Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download Directory features added #644

Merged
merged 20 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build, Distribute and Test zbox
name: Distribute zbox using apt

on:
workflow_dispatch:
Expand Down
175 changes: 175 additions & 0 deletions .github/workflows/distribute-zboxcli-choco.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
name: Distribute zbox using choco

on:
workflow_dispatch:
inputs:
version:
description: 'Version of zbox to release'
required: true
default: '1.0.0'

env:
APP_NAME: zbox
PACKAGE_ID: zbox
APP_VERSION: ${{ github.event.inputs.version }}
GO_VERSION: '1.21'

jobs:
build:
runs-on: windows-latest
env:
SRC_DIR: ${{ github.workspace }}\src
OUTPUT_DIR: ${{ github.workspace }}\output
PACKAGE_DIR: ${{ github.workspace }}\package

steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
path: ${{ env.SRC_DIR }}

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Install MinGW for CGo
run: |
choco install mingw

- name: Setup
run : |
New-Item -ItemType Directory -Force -Path "${{ env.OUTPUT_DIR }}\amd64"
New-Item -ItemType Directory -Force -Path "${{ env.PACKAGE_DIR }}"
Copy-Item -Force -Path "${{ env.SRC_DIR }}\cmd\config.yaml" -Destination "${{ env.OUTPUT_DIR }}\amd64\"

- name: Build ${{ env.APP_NAME }} for amd64
run: |
Set-Location -Path "${{ env.SRC_DIR }}"
$env:CGO_ENABLED="1"
$env:CC="x86_64-w64-mingw32-gcc"
$env:CXX="x86_64-w64-mingw32-g++"
$env:GOOS="windows"
$env:GOARCH="amd64"
where x86_64-w64-mingw32-gcc
where x86_64-w64-mingw32-g++
go build -x -v -tags bn256 -ldflags "-X main.VersionStr=v${{ env.APP_VERSION }}" -o ${{ env.OUTPUT_DIR }}\amd64\${{ env.APP_NAME }}.exe .
shell: pwsh

- name: Generate SHA256 Checksum
id: checksum
shell: pwsh
run: |
$checksum = Get-FileHash "${{ env.OUTPUT_DIR }}\amd64\${{ env.APP_NAME }}.exe" -Algorithm SHA256
Write-Output "::set-output name=checksum::$($checksum.Hash)"

- name: Create VERIFICATION.txt
shell: pwsh
run: |
Set-Location -Path "${{ env.PACKAGE_DIR }}"
$location = Get-Location
Write-Host "Current Directory: $location"
$files = Get-ChildItem "${{ env.PACKAGE_DIR }}"
Write-Host "Files in Directory: $files"

$verificationContent = @"
The binaries in this package were sourced from the official https://github.com/0chain/zboxcli repository.

Verification Steps:
1. The SHA256 checksum of the binary was calculated.
2. Users can verify the binary themselves by running the following command:
`Get-FileHash -Algorithm SHA256 ${{ env.APP_NAME }}.exe`

Expected checksum:
${{ steps.checksum.outputs.checksum }}
"@

$verificationContent | Out-File -FilePath "VERIFICATION.txt" -Encoding utf8
Write-Host "Created VERIFICATION.txt file"
Get-ChildItem "${{ env.PACKAGE_DIR }}"

$fileContent = Get-Content -Path "VERIFICATION.txt"
Write-Host "File Content: $fileContent"

- name: Create Chocolatey Install Script
run: |
Set-Location -Path "${{ env.PACKAGE_DIR }}"
$location = Get-Location
Write-Host "Current Directory: $location"
$files = Get-ChildItem "${{ env.PACKAGE_DIR }}"
Write-Host "Files in Directory: $files"

$content = @'
$installDir = "$(Get-ToolsLocation)\zbox"
$envPath = [System.Environment]::GetEnvironmentVariable('Path', 'Machine')

if ($envPath -notlike "*$installDir*") {
Write-Host "Adding $installDir to PATH"
[System.Environment]::SetEnvironmentVariable('Path', "$envPath;$installDir", 'Machine')
}
'@

$content | Out-File -FilePath "chocolateyInstall.ps1" -Encoding utf8
Write-Host "Created chocolateyInstall.ps1 file"
Get-ChildItem "${{ env.PACKAGE_DIR }}"

$fileContent = Get-Content -Path "chocolateyInstall.ps1"
Write-Host "File Content: $fileContent"

- name: Create .nuspec file
run: |
Set-Location -Path "${{ env.PACKAGE_DIR }}"
$location = Get-Location
Write-Host "Current Directory: $location"
$files = Get-ChildItem "${{ env.PACKAGE_DIR }}"
Write-Host "Files in Directory: $files"
$content = @"
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>${{ env.PACKAGE_ID }}</id>
<version>${{ env.APP_VERSION }}</version>
<authors>Saswata Basu</authors>
<owners>Saswata Basu</owners>
<tags>zbox cloud storage cli windows golang</tags>
<licenseUrl>https://github.com/0chain/zboxcli/blob/staging/LICENSE</licenseUrl>
<projectUrl>https://github.com/0chain/zboxcli</projectUrl>
<packageSourceUrl>https://github.com/0chain/zboxcli</packageSourceUrl>
<releaseNotes>https://github.com/0chain/zboxcli/releases/latest</releaseNotes>
<summary>zbox is a command line interface (CLI) tool to understand the capabilities of Züs dStorage and prototype your app.</summary>
<description>zbox is a command line interface (CLI) tool to understand the capabilities of Züs dStorage and prototype your app.</description>
<title>zbox CLI</title>
</metadata>
<files>
<file src="${{ env.OUTPUT_DIR }}\amd64\${{ env.APP_NAME }}.exe" target="tools\${{ env.APP_NAME }}.exe" />
<file src="${{ env.SRC_DIR }}\LICENSE" target="tools\LICENSE" />
<file src="${{ env.PACKAGE_DIR }}\VERIFICATION.txt" target="tools\VERIFICATION.txt" />
<file src="${{ env.PACKAGE_DIR }}\chocolateyInstall.ps1" target="tools\chocolateyInstall.ps1" />
</files>
</package>
"@

$content | Out-File -FilePath "zbox.nuspec" -Encoding utf8
Write-Host "Created .nuspec file:"
Get-ChildItem "${{ env.PACKAGE_DIR }}"

$fileContent = Get-Content -Path "zbox.nuspec"
Write-Host "File Content: $fileContent"

- name: Pack Chocolatey Package
run: |
Set-Location -Path "${{ env.PACKAGE_DIR }}"
$location = Get-Location
Write-Host "Current Directory: $location"
$files = Get-ChildItem "${{ env.PACKAGE_DIR }}"
Write-Host "Files in Directory: $files"
choco pack ${{ env.PACKAGE_ID }}.nuspec

- name: Push Chocolatey Package
run: |
Set-Location -Path "${{ env.PACKAGE_DIR }}"
$location = Get-Location
Write-Host "Current Directory: $location"
$files = Get-ChildItem "${{ env.PACKAGE_DIR }}"
Write-Host "Files in Directory: $files"
choco push ${{ env.PACKAGE_ID }}.${{ env.APP_VERSION }}.nupkg --source https://push.chocolatey.org/ -k ${{ secrets.CHOCOLATEY_API_KEY }}
68 changes: 65 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
cd ${{ env.OUTPUT_DIR }}
zip -qq -r ${{ env.APP_NAME }}-linux-amd64.zip ${{ env.APP_NAME }} config.yaml

- name: Upload Zip for Darwin/amd64
- name: Upload Zip for linux/amd64
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-linux-amd64
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
cd ${{ env.OUTPUT_DIR }}
zip -qq -r ${{ env.APP_NAME }}-linux-arm64.zip ${{ env.APP_NAME }} config.yaml

- name: Upload Zip for Darwin/arm64
- name: Upload Zip for linux/arm64
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-linux-arm64
Expand Down Expand Up @@ -161,7 +161,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: ${{ env.GO_VERSION }}

- name: Setup
run : |
Expand Down Expand Up @@ -221,3 +221,65 @@ jobs:
asset_path: ${{ env.OUTPUT_DIR }}/arm64/${{ env.APP_NAME }}-darwin-arm64.zip
asset_name: ${{ env.APP_NAME }}-darwin-arm64.zip
asset_content_type: application/zip

windows:
runs-on: windows-latest
needs: create_release
env:
SRC_DIR: ${{ github.workspace }}\src
OUTPUT_DIR: ${{ github.workspace }}\output
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
path: ${{ env.SRC_DIR }}

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Install MinGW for CGo
run: |
choco install mingw

- name: Setup
run : |
New-Item -ItemType Directory -Force -Path "${{ env.OUTPUT_DIR }}\amd64"
Copy-Item -Force -Path "${{ env.SRC_DIR }}\cmd\config.yaml" -Destination "${{ env.OUTPUT_DIR }}\amd64\"

- name: Build ${{ env.APP_NAME }} for amd64
run: |
Set-Location -Path "${{ env.SRC_DIR }}"
$env:CGO_ENABLED="1"
$env:CC="x86_64-w64-mingw32-gcc"
$env:CXX="x86_64-w64-mingw32-g++"
$env:GOOS="windows"
$env:GOARCH="amd64"
where x86_64-w64-mingw32-gcc
where x86_64-w64-mingw32-g++
go build -x -v -tags bn256 -ldflags "-X main.VersionStr=v${{ env.VERSION }}" -o ${{ env.OUTPUT_DIR }}\amd64\${{ env.APP_NAME }}.exe .
shell: pwsh

- name: Create Zip File for windows/amd64
run: |
Set-Location -Path "${{ env.OUTPUT_DIR }}\amd64"
Compress-Archive -Path @("${{ env.APP_NAME }}.exe", "config.yaml") -DestinationPath ${{ env.APP_NAME }}-windows-amd64.zip

- name: Upload Zip for windows/amd64
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_NAME }}-windows-amd64
path: ${{ env.OUTPUT_DIR }}\amd64\${{ env.APP_NAME }}-windows-amd64.zip

- name: Upload Release Asset for windows/amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ${{ env.OUTPUT_DIR }}\amd64\${{ env.APP_NAME }}-windows-amd64.zip
asset_name: ${{ env.APP_NAME }}-windows-amd64.zip
asset_content_type: application/zip


41 changes: 24 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
MIT License
Non-compete BSD-3-Clause

Copyright (c) 2019 0Chain
Copyright © 2019 0Chain,LLC.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Redistribution and use in source and binary forms, with or without modification, are permitted provided
that the following conditions are met:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

4. It is not permitted to provide any offering that competes with the source code and binary form
or any other offering the licensor provides using the source code and binary form.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
66 changes: 66 additions & 0 deletions cmd/downloaddir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package cmd

import (
"context"
"os"
"sync"

"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/spf13/cobra"
)

// downloadCmd represents download directory command
var downdirCmd = &cobra.Command{
Use: "downloaddir",
Short: "download directory from blobbers",
Long: `download directory from blobbers`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
fflags := cmd.Flags() // fflags is a *flag.FlagSet
if !(fflags.Changed("remotepath") || fflags.Changed("authticket")) {
PrintError("Error: remotepath / authticket flag is missing")
os.Exit(1)
}

remotePath := cmd.Flag("remotepath").Value.String()
authTicket := cmd.Flag("authticket").Value.String()
localPath := cmd.Flag("localpath").Value.String()
allocationID := cmd.Flag("allocation").Value.String()

var allocationObj *sdk.Allocation
if !fflags.Changed("allocation") { // check if the flag "path" is set
PrintError("Error: allocation flag is missing") // If not, we'll let the user know
os.Exit(1) // and return
}
allocationObj, err := sdk.GetAllocation(allocationID)
if err != nil {
PrintError("Error fetching the allocation", err)
os.Exit(1)
}
wg := &sync.WaitGroup{}
statusBar := &StatusBar{wg: wg}
wg.Add(1)
errE := allocationObj.DownloadDirectory(context.Background(), remotePath, localPath, authTicket, statusBar)
if errE == nil {
wg.Wait()
} else {
PrintError("Download failed.", errE.Error())
os.Exit(1)
}
if !statusBar.success {
os.Exit(1)
}
},
}

func init() {
rootCmd.AddCommand(downdirCmd)
downdirCmd.PersistentFlags().String("allocation", "", "Allocation ID")
downdirCmd.PersistentFlags().String("remotepath", "", "Remote path of directory to download")
downdirCmd.PersistentFlags().String("localpath", "", "Local path of directory to download")
downdirCmd.PersistentFlags().String("authticket", "", "Auth ticket fot the file to download if you dont own it")

downdirCmd.MarkFlagRequired("allocation")
downdirCmd.MarkFlagRequired("localpath")
downdirCmd.MarkFlagRequired("remotepath")
}