From afd76aec7c79518229545e887bb035365d9d5781 Mon Sep 17 00:00:00 2001 From: Sjoerd Dijkstra Date: Wed, 15 Feb 2023 18:56:15 +0100 Subject: [PATCH 1/6] Add github actions for brew package --- .github/scripts/prepare-release.sh | 66 ++++++++++++++ .github/workflows/brew.yml | 137 +++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100755 .github/scripts/prepare-release.sh create mode 100644 .github/workflows/brew.yml diff --git a/.github/scripts/prepare-release.sh b/.github/scripts/prepare-release.sh new file mode 100755 index 0000000..06ff73c --- /dev/null +++ b/.github/scripts/prepare-release.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +# exit upon failure +set -e + +# setup +[[ -n "${DEBUG_SCRIPT}" ]] && set -xv + +# shell swag +RED="\033[1;91m" +CYAN="\033[1;36m" +GREEN="\033[1;32m" +WHITE="\033[1;38;5;231m" +RESET="\n\033[0m" + +# logging +log_std() { echo -e "${CYAN}==> ${WHITE}${1}${RESET}"; } +log_err() { echo -e "${RED}==> ${WHITE}${1}${RESET}"; } + +# vars +version=${TAG_REF/refs\/tags\//} +log_std "Preparing release ${GREEN}${version}" + +# create release directory +mkdir release + +# artifacts files +cd artifacts +for file in */* +do + cp "${file}" "../release/$(dirname "${file}")-${version}" +done + +# release files +cd ../release +for file in * +do + sha256sum "${file}" > "${file}.sha256sum" +done + +tar czf "all-files-${version}.tar.gz" * +sha256sum "all-files-${version}.tar.gz" > "all-files-${version}.tar.gz.sha256sum" +all_files_sha="$( cat "all-files-${version}.tar.gz.sha256sum" | cut -f 1 -d ' ' )" + +# release body +cat < "../${RELEASE_BODY_FILE}" +## SHA 256 +EOF + +echo "## SHA 256" > "../${RELEASE_BODY_FILE}" +for file in *.sha256sum +do + echo "- \`$( cat "${file}" | cut -f 1 -d ' ' )\` ${file}" >> "../${RELEASE_BODY_FILE}" +done + +cat <> "../${RELEASE_BODY_FILE}" + +## Change log +EOF +echo "${CHANGE_LOG}" >> "../${RELEASE_BODY_FILE}" + +# github output +for output in "new_version=${version}" "all_files_sha=${all_files_sha}" +do + echo "${output}" >> "$GITHUB_OUTPUT" +done diff --git a/.github/workflows/brew.yml b/.github/workflows/brew.yml new file mode 100644 index 0000000..a3b952a --- /dev/null +++ b/.github/workflows/brew.yml @@ -0,0 +1,137 @@ +name: Build and release Nosana Node packages + +on: + push: + tags: + - v* + +permissions: + contents: write + +jobs: + build: + name: Build package + runs-on: ubuntu-latest + + steps: + # repo + - name: Checkout sources + uses: actions/checkout@v3 + with: + submodules: 'true' + + # java + - name: Prepare java + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 19 + + # clojure + - name: Install clojure tools + uses: DeLaGuardo/setup-clojure@10.1 + with: + cli: latest + + # build + - name: Clojure Uber Build + run: clojure -X:compile uberjar + + # artifact + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: nosana-node + path: target/*.jar + if-no-files-found: error + + release: + name: Release package + needs: build + runs-on: ubuntu-latest + env: + RELEASE_BODY_FILE: body.txt + outputs: + new_version: ${{ steps.release-files.outputs.new_version }} + all_files_sha: ${{ steps.release-files.outputs.all_files_sha }} + steps: + # repo + - name: Checkout sources + uses: actions/checkout@v3 + with: + submodules: 'true' + + # artifact + - name: Download all workflow run artifacts + uses: actions/download-artifact@v2 + with: + path: artifacts + + # build + - name: Check files + run: ls artifacts/**/* + + # change log + - name: Generate changelog + id: changelog + uses: metcalfc/changelog-generator@v4.0.1 + with: + myToken: ${{ secrets.GITHUB_TOKEN }} + + # prepare release + - name: Prepare release files + id: release-files + run: .github/scripts/prepare-release.sh + env: + TAG_REF: ${{ github.ref }} + CHANGE_LOG: ${{ steps.changelog.outputs.changelog }} + + # build + - name: Check files + run: ls release/* + + # release + - name: Release package + uses: softprops/action-gh-release@v1 + with: + body_path: ${{ env.RELEASE_BODY_FILE }} + files: release/* + draft: false + prerelease: false + + update: + name: Update Brew + needs: release + runs-on: ubuntu-latest + env: + NEW_VERSION: ${{ needs.release.outputs.new_version }} + ALL_FILES_SHA: ${{ needs.release.outputs.all_files_sha }} + steps: + # remote repo + - name: Checkout sources + uses: actions/checkout@v2 + with: + repository: nosana-ci/homebrew-tools + + # changes formula + - name: Update formula native image + id: update-formula + run: scripts/update-formula.sh nosana-node.rb ${{ env.NEW_VERSION }} ${{ env.ALL_FILES_SHA }} + + # create PR + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.BOT_GITHUB_PAT_PUBLIC_REPO }} + commit-message: Update nosana-node formula to version ${{ env.NEW_VERSION }} + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + base: main + branch: update-nosana-node-cli-formula + delete-branch: true + title: Nosana Node brew update ${{ env.NEW_VERSION }} + body: | + This PR + - Updates `nosana-node` formula to version `${{ env.NEW_VERSION }}` + - All files package sha is `${{ env.ALL_FILES_SHA }}` + - Auto-generated from [nosana-ci Continuous Delivery workflow][1] + [1]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} From aa8db61b11c6561a48ce6ecd9a59457dc2245a01 Mon Sep 17 00:00:00 2001 From: Sjoerd Dijkstra Date: Wed, 15 Feb 2023 20:22:15 +0100 Subject: [PATCH 2/6] Update workflow --- .github/scripts/prepare-release.sh | 35 +++++++++++++++--------------- .github/workflows/brew.yml | 29 ++++++++++--------------- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/.github/scripts/prepare-release.sh b/.github/scripts/prepare-release.sh index 06ff73c..6aa035e 100755 --- a/.github/scripts/prepare-release.sh +++ b/.github/scripts/prepare-release.sh @@ -19,6 +19,7 @@ log_err() { echo -e "${RED}==> ${WHITE}${1}${RESET}"; } # vars version=${TAG_REF/refs\/tags\//} +tarball="all-files-${version}.tar.gz" log_std "Preparing release ${GREEN}${version}" # create release directory @@ -26,41 +27,39 @@ mkdir release # artifacts files cd artifacts -for file in */* -do +for file in */*; do cp "${file}" "../release/$(dirname "${file}")-${version}" done # release files cd ../release -for file in * -do - sha256sum "${file}" > "${file}.sha256sum" +for file in *; do + sha256sum "${file}" >"${file}.sha256sum" done -tar czf "all-files-${version}.tar.gz" * -sha256sum "all-files-${version}.tar.gz" > "all-files-${version}.tar.gz.sha256sum" -all_files_sha="$( cat "all-files-${version}.tar.gz.sha256sum" | cut -f 1 -d ' ' )" +tar czf "${tarball}" ./* +sha256sum "${tarball}" >"${tarball}.sha256sum" # release body -cat < "../${RELEASE_BODY_FILE}" +cat <"../${RELEASE_BODY_FILE}" ## SHA 256 + EOF -echo "## SHA 256" > "../${RELEASE_BODY_FILE}" -for file in *.sha256sum -do - echo "- \`$( cat "${file}" | cut -f 1 -d ' ' )\` ${file}" >> "../${RELEASE_BODY_FILE}" +for file in *.sha256sum; do + echo "- \`$(cut -f 1 -d ' ' <"${file}")\` ${file}" >>"../${RELEASE_BODY_FILE}" done -cat <> "../${RELEASE_BODY_FILE}" +cat <>"../${RELEASE_BODY_FILE}" ## Change log + EOF -echo "${CHANGE_LOG}" >> "../${RELEASE_BODY_FILE}" +echo "${CHANGE_LOG}" >>"../${RELEASE_BODY_FILE}" # github output -for output in "new_version=${version}" "all_files_sha=${all_files_sha}" -do - echo "${output}" >> "$GITHUB_OUTPUT" +for output in \ + "version=${version}" \ + "sha256=$(cut -f 1 -d ' ' <"${tarball}")"; do + echo "${output}" >>"${GITHUB_OUTPUT}" done diff --git a/.github/workflows/brew.yml b/.github/workflows/brew.yml index a3b952a..011c4fd 100644 --- a/.github/workflows/brew.yml +++ b/.github/workflows/brew.yml @@ -9,6 +9,9 @@ permissions: contents: write jobs: + ############## + # BUILD + # build: name: Build package runs-on: ubuntu-latest @@ -18,7 +21,7 @@ jobs: - name: Checkout sources uses: actions/checkout@v3 with: - submodules: 'true' + submodules: true # java - name: Prepare java @@ -45,6 +48,9 @@ jobs: path: target/*.jar if-no-files-found: error + ############## + # RELEASE + # release: name: Release package needs: build @@ -52,25 +58,15 @@ jobs: env: RELEASE_BODY_FILE: body.txt outputs: - new_version: ${{ steps.release-files.outputs.new_version }} - all_files_sha: ${{ steps.release-files.outputs.all_files_sha }} + version: ${{ steps.release-files.outputs.version }} + sha256: ${{ steps.release-files.outputs.sha256 }} steps: - # repo - - name: Checkout sources - uses: actions/checkout@v3 - with: - submodules: 'true' - # artifact - name: Download all workflow run artifacts uses: actions/download-artifact@v2 with: path: artifacts - # build - - name: Check files - run: ls artifacts/**/* - # change log - name: Generate changelog id: changelog @@ -86,10 +82,6 @@ jobs: TAG_REF: ${{ github.ref }} CHANGE_LOG: ${{ steps.changelog.outputs.changelog }} - # build - - name: Check files - run: ls release/* - # release - name: Release package uses: softprops/action-gh-release@v1 @@ -99,6 +91,9 @@ jobs: draft: false prerelease: false + ############## + # UPDATE + # update: name: Update Brew needs: release From 218787dabb638744cbcf6b5c53307ea318a553db Mon Sep 17 00:00:00 2001 From: Sjoerd Dijkstra Date: Wed, 15 Feb 2023 20:28:01 +0100 Subject: [PATCH 3/6] Improve naming --- .github/workflows/brew.yml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/brew.yml b/.github/workflows/brew.yml index 011c4fd..c9aa475 100644 --- a/.github/workflows/brew.yml +++ b/.github/workflows/brew.yml @@ -18,26 +18,26 @@ jobs: steps: # repo - - name: Checkout sources + - name: Checkout repository uses: actions/checkout@v3 with: submodules: true # java - - name: Prepare java + - name: Setup java uses: actions/setup-java@v3 with: distribution: temurin java-version: 19 # clojure - - name: Install clojure tools + - name: Setup clojure uses: DeLaGuardo/setup-clojure@10.1 with: cli: latest # build - - name: Clojure Uber Build + - name: Compile uberjar run: clojure -X:compile uberjar # artifact @@ -61,8 +61,12 @@ jobs: version: ${{ steps.release-files.outputs.version }} sha256: ${{ steps.release-files.outputs.sha256 }} steps: + # repo + - name: Checkout repository + uses: actions/checkout@v3 + # artifact - - name: Download all workflow run artifacts + - name: Download artifacts uses: actions/download-artifact@v2 with: path: artifacts @@ -103,18 +107,18 @@ jobs: ALL_FILES_SHA: ${{ needs.release.outputs.all_files_sha }} steps: # remote repo - - name: Checkout sources + - name: Checkout brew sources uses: actions/checkout@v2 with: repository: nosana-ci/homebrew-tools - # changes formula - - name: Update formula native image + # update formula + - name: Update formula id: update-formula run: scripts/update-formula.sh nosana-node.rb ${{ env.NEW_VERSION }} ${{ env.ALL_FILES_SHA }} # create PR - - name: Create Pull Request + - name: Create PR uses: peter-evans/create-pull-request@v3 with: token: ${{ secrets.BOT_GITHUB_PAT_PUBLIC_REPO }} From 8b293ae85f3378348f65a50b7b92d7a786c92452 Mon Sep 17 00:00:00 2001 From: Sjoerd Dijkstra Date: Wed, 15 Feb 2023 20:33:42 +0100 Subject: [PATCH 4/6] Fix workflow --- .github/workflows/brew.yml | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/.github/workflows/brew.yml b/.github/workflows/brew.yml index c9aa475..d544172 100644 --- a/.github/workflows/brew.yml +++ b/.github/workflows/brew.yml @@ -11,7 +11,6 @@ permissions: jobs: ############## # BUILD - # build: name: Build package runs-on: ubuntu-latest @@ -50,7 +49,6 @@ jobs: ############## # RELEASE - # release: name: Release package needs: build @@ -58,8 +56,8 @@ jobs: env: RELEASE_BODY_FILE: body.txt outputs: - version: ${{ steps.release-files.outputs.version }} - sha256: ${{ steps.release-files.outputs.sha256 }} + version: ${{ steps.prepare.outputs.version }} + sha256: ${{ steps.prepare.outputs.sha256 }} steps: # repo - name: Checkout repository @@ -71,16 +69,16 @@ jobs: with: path: artifacts - # change log + # changelog - name: Generate changelog id: changelog uses: metcalfc/changelog-generator@v4.0.1 with: myToken: ${{ secrets.GITHUB_TOKEN }} - # prepare release + # prepare - name: Prepare release files - id: release-files + id: prepare run: .github/scripts/prepare-release.sh env: TAG_REF: ${{ github.ref }} @@ -97,14 +95,13 @@ jobs: ############## # UPDATE - # update: name: Update Brew needs: release runs-on: ubuntu-latest env: - NEW_VERSION: ${{ needs.release.outputs.new_version }} - ALL_FILES_SHA: ${{ needs.release.outputs.all_files_sha }} + VERSION: ${{ needs.release.outputs.version }} + SHA256: ${{ needs.release.outputs.sha256 }} steps: # remote repo - name: Checkout brew sources @@ -115,22 +112,21 @@ jobs: # update formula - name: Update formula id: update-formula - run: scripts/update-formula.sh nosana-node.rb ${{ env.NEW_VERSION }} ${{ env.ALL_FILES_SHA }} + run: scripts/update-formula.sh nosana-node.rb ${{ env.VERSION }} ${{ env.SHA256 }} # create PR - name: Create PR uses: peter-evans/create-pull-request@v3 with: token: ${{ secrets.BOT_GITHUB_PAT_PUBLIC_REPO }} - commit-message: Update nosana-node formula to version ${{ env.NEW_VERSION }} + commit-message: Update nosana-node formula to version ${{ env.VERSION }} author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> base: main branch: update-nosana-node-cli-formula delete-branch: true - title: Nosana Node brew update ${{ env.NEW_VERSION }} + title: Nosana Node brew update ${{ env.VERSION }} body: | This PR - - Updates `nosana-node` formula to version `${{ env.NEW_VERSION }}` - - All files package sha is `${{ env.ALL_FILES_SHA }}` - - Auto-generated from [nosana-ci Continuous Delivery workflow][1] - [1]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + - Updates `nosana-node` formula to version `${{ env.VERSION }}` + - Package sha256 is `${{ env.SHA256 }}` + - Auto-generated from [nosana-ci Continuous Delivery workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) From ab955c2c084d1e6f20f5938f6e0600481ffd5ee6 Mon Sep 17 00:00:00 2001 From: Sjoerd Dijkstra Date: Wed, 15 Feb 2023 20:37:07 +0100 Subject: [PATCH 5/6] Update actions --- .github/workflows/brew.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/brew.yml b/.github/workflows/brew.yml index d544172..6221f6c 100644 --- a/.github/workflows/brew.yml +++ b/.github/workflows/brew.yml @@ -65,7 +65,7 @@ jobs: # artifact - name: Download artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: path: artifacts @@ -105,7 +105,7 @@ jobs: steps: # remote repo - name: Checkout brew sources - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: nosana-ci/homebrew-tools @@ -116,7 +116,7 @@ jobs: # create PR - name: Create PR - uses: peter-evans/create-pull-request@v3 + uses: peter-evans/create-pull-request@v4 with: token: ${{ secrets.BOT_GITHUB_PAT_PUBLIC_REPO }} commit-message: Update nosana-node formula to version ${{ env.VERSION }} From 6212c292d6de703cdec974deebd1849d9f18f3e1 Mon Sep 17 00:00:00 2001 From: Sjoerd Dijkstra Date: Wed, 15 Feb 2023 20:43:36 +0100 Subject: [PATCH 6/6] Get sha256 from file --- .github/scripts/prepare-release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/prepare-release.sh b/.github/scripts/prepare-release.sh index 6aa035e..3d68ba2 100755 --- a/.github/scripts/prepare-release.sh +++ b/.github/scripts/prepare-release.sh @@ -60,6 +60,6 @@ echo "${CHANGE_LOG}" >>"../${RELEASE_BODY_FILE}" # github output for output in \ "version=${version}" \ - "sha256=$(cut -f 1 -d ' ' <"${tarball}")"; do + "sha256=$(cut -f 1 -d ' ' <"${tarball}.sha256sum")"; do echo "${output}" >>"${GITHUB_OUTPUT}" done