diff --git a/.github/workflows/generic.yml b/.github/workflows/generic.yml index 048dfeb..b171712 100644 --- a/.github/workflows/generic.yml +++ b/.github/workflows/generic.yml @@ -3,7 +3,7 @@ name: Generic github actions on: push: branches-ignore: - - 'master' + - "master" permissions: contents: write @@ -12,34 +12,34 @@ jobs: build-devel: runs-on: ubuntu-latest steps: - - name: Get current date - run: echo "irgsh_build_date=$(TZ='Asia/Jakarta' date +'%Y%m%d%H%M')" >> $GITHUB_ENV - - uses: actions/checkout@v3 - - name: Install needed apt packages - uses: awalsh128/cache-apt-pkgs-action@v1.2.3 - with: - packages: gpg pbuilder debootstrap devscripts python3-apt reprepro make - version: 1.0 - - uses: actions/setup-go@v3 - with: - go-version: '1.13.14' - - uses: actions/cache@v3 - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - name: Build development release - run: | - echo ${{ env.irgsh_build_date }}-development-build > VERSION - make release - mv target/{release,pre-release}.tar.gz - - uses: actions/upload-artifact@v3 - with: - name: pre-release.tar.gz - path: target/ + - name: Get current date + run: echo "irgsh_build_date=$(TZ='Asia/Jakarta' date +'%Y%m%d%H%M')" >> $GITHUB_ENV + - uses: actions/checkout@v3 + - name: Install needed apt packages + uses: awalsh128/cache-apt-pkgs-action@v1.2.3 + with: + packages: gpg pbuilder debootstrap devscripts python3-apt reprepro make + version: 1.0 + - uses: actions/setup-go@v3 + with: + go-version: "1.13.14" + - uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Build development release + run: | + echo ${{ env.irgsh_build_date }}-development-build > VERSION + make release + mv target/{release,pre-release}.tar.gz + - uses: actions/upload-artifact@v3 + with: + name: pre-release.tar.gz + path: target/ outputs: irgsh_build_date: ${{ env.irgsh_build_date }} @@ -47,32 +47,32 @@ jobs: runs-on: ubuntu-latest needs: [build-devel] steps: - - uses: actions/download-artifact@v3 - with: - name: pre-release.tar.gz - - name: Extract pre-release - run: | - tar xvzf pre-release.tar.gz - cp $(find . -type f -name "irgsh-cli") . - - name: Create github pre-release - uses: softprops/action-gh-release@v0.1.15 - with: - name: ${{ needs.build-devel.outputs.irgsh_build_date }} Development Release - body: Development release ${{ needs.build-devel.outputs.irgsh_build_date }} - draft: false - prerelease: true - tag_name: ${{ needs.build-devel.outputs.irgsh_build_date }}-development-build - files: | - pre-release.tar.gz - irgsh-cli + - uses: actions/download-artifact@v3 + with: + name: pre-release.tar.gz + - name: Extract pre-release + run: | + tar xvzf pre-release.tar.gz + cp $(find . -type f -name "irgsh-cli") . + - name: Create github pre-release + uses: softprops/action-gh-release@v0.1.15 + with: + name: ${{ needs.build-devel.outputs.irgsh_build_date }} Development Release + body: Development release ${{ needs.build-devel.outputs.irgsh_build_date }} + draft: false + prerelease: true + tag_name: ${{ needs.build-devel.outputs.irgsh_build_date }}-development-build + files: | + pre-release.tar.gz + irgsh-cli deploy: runs-on: ubuntu-latest needs: [release] steps: - - name: Deploy to irgsh development server - uses: kudaliar032/tendang-action@v1 - with: - url: ${{ secrets.RAFI_TENDANG_URL }} - token: ${{ secrets.RAFI_DEPLOYMENT_KEY }} - name: ${{ secrets.RAFI_DEPLOYMENT_NAME }} + - name: Deploy to irgsh development server + uses: kudaliar032/tendang-action@v1 + with: + url: ${{ secrets.RAFI_TENDANG_URL }} + token: ${{ secrets.RAFI_DEPLOYMENT_KEY }} + name: ${{ secrets.RAFI_DEPLOYMENT_NAME }} diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index a468bd8..bb60490 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -3,7 +3,7 @@ name: Master github actions on: push: branches: - - 'master' + - "master" permissions: contents: write @@ -12,33 +12,33 @@ jobs: build-release: runs-on: ubuntu-latest steps: - - name: Get current date - run: echo "irgsh_build_date=$(TZ='Asia/Jakarta' date +'%Y%m%d%H%M')" >> $GITHUB_ENV - - uses: actions/checkout@v3 - - name: Install needed apt packages - uses: awalsh128/cache-apt-pkgs-action@v1.2.3 - with: - packages: gpg pbuilder debootstrap devscripts python3-apt reprepro make - version: 1.0 - - uses: actions/setup-go@v3 - with: - go-version: '1.13.14' - - uses: actions/cache@v3 - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - name: Build nightly release - run: | - echo ${{ steps.date.outputs.date }}-nightly-build > VERSION - make release - - uses: actions/upload-artifact@v3 - with: - name: release.tar.gz - path: target/ + - name: Get current date + run: echo "irgsh_build_date=$(TZ='Asia/Jakarta' date +'%Y%m%d%H%M')" >> $GITHUB_ENV + - uses: actions/checkout@v3 + - name: Install needed apt packages + uses: awalsh128/cache-apt-pkgs-action@v1.2.3 + with: + packages: gpg pbuilder debootstrap devscripts python3-apt reprepro make + version: 1.0 + - uses: actions/setup-go@v3 + with: + go-version: "1.13.14" + - uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Build nightly release + run: | + echo ${{ steps.date.outputs.date }}-nightly-build > VERSION + make release + - uses: actions/upload-artifact@v3 + with: + name: release.tar.gz + path: target/ outputs: irgsh_build_date: ${{ env.irgsh_build_date }} @@ -46,32 +46,32 @@ jobs: runs-on: ubuntu-latest needs: [build-release] steps: - - uses: actions/download-artifact@v3 - with: - name: release.tar.gz - - name: Extract release - run: | - tar xvzf release.tar.gz - cp $(find . -type f -name "irgsh-cli") . - - name: Create github release - uses: softprops/action-gh-release@v0.1.15 - with: - name: ${{ needs.build-release.outputs.irgsh_build_date }} Nightly Release - body: Nightly release - draft: false - prerelease: false - tag_name: ${{ needs.build-release.outputs.irgsh_build_date }}-nightly-build - files: | - release.tar.gz - irgsh-cli + - uses: actions/download-artifact@v3 + with: + name: release.tar.gz + - name: Extract release + run: | + tar xvzf release.tar.gz + cp $(find . -type f -name "irgsh-cli") . + - name: Create github release + uses: softprops/action-gh-release@v0.1.15 + with: + name: ${{ needs.build-release.outputs.irgsh_build_date }} Nightly Release + body: Nightly release + draft: false + prerelease: false + tag_name: ${{ needs.build-release.outputs.irgsh_build_date }}-nightly-build + files: | + release.tar.gz + irgsh-cli deploy: runs-on: ubuntu-latest needs: [release] steps: - - name: Deploy to irgsh server - uses: kudaliar032/tendang-action@v1 - with: - url: ${{ secrets.RANI_TENDANG_URL }} - token: ${{ secrets.RANI_DEPLOYMENT_KEY }} - name: ${{ secrets.RANI_DEPLOYMENT_NAME }} + - name: Deploy to irgsh server + uses: kudaliar032/tendang-action@v1 + with: + url: ${{ secrets.RANI_TENDANG_URL }} + token: ${{ secrets.RANI_DEPLOYMENT_KEY }} + name: ${{ secrets.RANI_DEPLOYMENT_NAME }} diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index 64d47fd..873e256 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -1,5 +1,5 @@ FROM debian:buster-slim -RUN apt update && apt install -y gpg pbuilder debootstrap devscripts python-apt reprepro make && \ +RUN apt update && apt install -y gpg pbuilder debootstrap devscripts python3-apt reprepro make && \ curl -O https://storage.googleapis.com/golang/go1.13.14.linux-amd64.tar.gz && \ tar -xf go1.13.14.linux-amd64.tar.gz && \ mv go /usr/local && \ diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 121f526..55dec35 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -42,6 +42,14 @@ type Submission struct { SourceBranch string `json:"sourceBranch"` } +type GithubReleaseResponse struct { + Url string `json:"url"` + Assets []struct { + Name string `json:"name"` + BrowserDownloadUrl string `json:"browser_download_url"` + } +} + var ( app *cli.App homeDir string @@ -815,36 +823,72 @@ func main() { Name: "update", Usage: "Update the irgsh-cli tool", Action: func(c *cli.Context) (err error) { - cmdStr := "curl -ksL 'https://api.github.com/repos/BlankOn/irgsh-go/releases/latest' | jq -r '.assets | .[] | select(.name == \"irgsh-cli\")| .browser_download_url'" - output, err := exec.Command("bash", "-c", cmdStr).Output() + var ( + cmdStr = "ln -sf /usr/bin/irgsh-cli /usr/bin/irgsh && /usr/bin/irgsh-cli --version" + downloadURL string + githubResponse GithubReleaseResponse + githubAssetName = "irgsh-cli" + url = "https://api.github.com/repos/BlankOn/irgsh-go/releases/latest" + ) + + response, err := http.Get(url) if err != nil { - log.Println("error: %v\n", err) + log.Printf("error: %v\n", err) log.Println("Failed to get package name.") + return } - downloadURL := strings.TrimSuffix(string(output), "\n") + defer response.Body.Close() + + body, err := ioutil.ReadAll(response.Body) + if err != nil { + log.Printf("error: %v\n", err) + + return + } + + if err := json.Unmarshal(body, &githubResponse); err != nil { + log.Printf("error: %v\n", err) + + return err + } + + for _, asset := range githubResponse.Assets { + if asset.Name == githubAssetName { + downloadURL = strings.TrimSuffix(string(asset.BrowserDownloadUrl), "\n") + break + } + } + log.Println(downloadURL) log.Println("Self-updating...") + resp, err := http.Get(downloadURL) if err != nil { - log.Println(err) + log.Printf("error: %v\n", err) + return err } + defer resp.Body.Close() + err = update.Apply(resp.Body, update.Options{}) if err != nil { - log.Println(err) + log.Printf("error: %v\n", err) + return err } - cmdStr = "ln -sf /usr/bin/irgsh-cli /usr/bin/irgsh && /usr/bin/irgsh-cli --version" + log.Println(cmdStr) - output, err = exec.Command("bash", "-c", cmdStr).Output() + + output, err := exec.Command("bash", "-c", cmdStr).Output() if err != nil { log.Println(output) - log.Println("error: %v\n", err) + log.Printf("error: %v\n", err) log.Println("Failed to get package name.") } log.Println("Updated to " + strings.TrimSuffix(string(output), "\n")) + return }, }, diff --git a/install.sh b/install.sh index 55920ea..f8f36ef 100755 --- a/install.sh +++ b/install.sh @@ -24,7 +24,7 @@ else apt install -y docker.io fi -apt install -y gnupg pbuilder debootstrap devscripts debhelper python-apt reprepro jq +apt install -y gnupg pbuilder debootstrap devscripts debhelper python3-apt reprepro jq if [ -f ./target/release.tar.gz ]; then # For development/testing purpose