diff --git a/.github/scripts/prepare-release.sh b/.github/scripts/prepare-release.sh new file mode 100755 index 0000000..3d68ba2 --- /dev/null +++ b/.github/scripts/prepare-release.sh @@ -0,0 +1,65 @@ +#!/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\//} +tarball="all-files-${version}.tar.gz" +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 "${tarball}" ./* +sha256sum "${tarball}" >"${tarball}.sha256sum" + +# release body +cat <"../${RELEASE_BODY_FILE}" +## SHA 256 + +EOF + +for file in *.sha256sum; do + echo "- \`$(cut -f 1 -d ' ' <"${file}")\` ${file}" >>"../${RELEASE_BODY_FILE}" +done + +cat <>"../${RELEASE_BODY_FILE}" + +## Change log + +EOF +echo "${CHANGE_LOG}" >>"../${RELEASE_BODY_FILE}" + +# github output +for output in \ + "version=${version}" \ + "sha256=$(cut -f 1 -d ' ' <"${tarball}.sha256sum")"; do + echo "${output}" >>"${GITHUB_OUTPUT}" +done diff --git a/.github/workflows/brew.yml b/.github/workflows/brew.yml new file mode 100644 index 0000000..6221f6c --- /dev/null +++ b/.github/workflows/brew.yml @@ -0,0 +1,132 @@ +name: Build and release Nosana Node packages + +on: + push: + tags: + - v* + +permissions: + contents: write + +jobs: + ############## + # BUILD + build: + name: Build package + runs-on: ubuntu-latest + + steps: + # repo + - name: Checkout repository + uses: actions/checkout@v3 + with: + submodules: true + + # java + - name: Setup java + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 19 + + # clojure + - name: Setup clojure + uses: DeLaGuardo/setup-clojure@10.1 + with: + cli: latest + + # build + - name: Compile uberjar + 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 + release: + name: Release package + needs: build + runs-on: ubuntu-latest + env: + RELEASE_BODY_FILE: body.txt + outputs: + version: ${{ steps.prepare.outputs.version }} + sha256: ${{ steps.prepare.outputs.sha256 }} + steps: + # repo + - name: Checkout repository + uses: actions/checkout@v3 + + # artifact + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + path: artifacts + + # changelog + - name: Generate changelog + id: changelog + uses: metcalfc/changelog-generator@v4.0.1 + with: + myToken: ${{ secrets.GITHUB_TOKEN }} + + # prepare + - name: Prepare release files + id: prepare + run: .github/scripts/prepare-release.sh + env: + TAG_REF: ${{ github.ref }} + CHANGE_LOG: ${{ steps.changelog.outputs.changelog }} + + # release + - name: Release package + uses: softprops/action-gh-release@v1 + with: + body_path: ${{ env.RELEASE_BODY_FILE }} + files: release/* + draft: false + prerelease: false + + ############## + # UPDATE + update: + name: Update Brew + needs: release + runs-on: ubuntu-latest + env: + VERSION: ${{ needs.release.outputs.version }} + SHA256: ${{ needs.release.outputs.sha256 }} + steps: + # remote repo + - name: Checkout brew sources + uses: actions/checkout@v3 + with: + repository: nosana-ci/homebrew-tools + + # update formula + - name: Update formula + id: update-formula + run: scripts/update-formula.sh nosana-node.rb ${{ env.VERSION }} ${{ env.SHA256 }} + + # create PR + - name: Create PR + 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 }} + 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.VERSION }} + body: | + This PR + - 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 }})