workflows: replace softprops/action-gh-release with gh CLI (main) #113
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Node | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - v20.18.3 | |
| - workflows-for-v20.18.3 | |
| pull_request: | |
| paths: .github/workflows/build-node.yml | |
| jobs: | |
| build-node: | |
| name: Build ${{ matrix.platform }}-${{ matrix.arch }} | |
| strategy: | |
| matrix: | |
| include: | |
| - platform: linux | |
| arch: x64 | |
| runs_on: ubuntu-22.04 | |
| - platform: linux | |
| arch: arm64 | |
| runs_on: ubuntu-22.04-arm | |
| runs-on: ${{ matrix.runs_on }} | |
| env: | |
| S3_BUCKET: your-bucket-name | |
| AWS_REGION: us-east-1 | |
| REPO: ${{ github.repository }} | |
| steps: | |
| - name: Checkout Node fork | |
| uses: actions/checkout@v3 | |
| with: | |
| repository: Asana/node | |
| path: node | |
| ref: ${{ github.event_name == 'pull_request' && format('refs/pull/{0}/merge', github.event.pull_request.number) || github.ref_name }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Node Version | |
| id: extract-node-version | |
| run: | | |
| NODE_MAJOR_VERSION=$(grep '#define NODE_MAJOR_VERSION' node/src/node_version.h | awk '{print $3}') | |
| NODE_MINOR_VERSION=$(grep '#define NODE_MINOR_VERSION' node/src/node_version.h | awk '{print $3}') | |
| NODE_PATCH_VERSION=$(grep '#define NODE_PATCH_VERSION' node/src/node_version.h | awk '{print $3}') | |
| NODE_VERSION="v${NODE_MAJOR_VERSION}.${NODE_MINOR_VERSION}.${NODE_PATCH_VERSION}" | |
| echo "NODE_VERSION=${NODE_VERSION}" >> $GITHUB_ENV | |
| - name: Set build metadata | |
| id: meta | |
| working-directory: node | |
| run: | | |
| TIMESTAMP=$(date -u +%Y-%m-%dT%H-%M) | |
| SHORT_SHA=$(git rev-parse --short HEAD) | |
| echo "BUILD_ID=${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_ENV | |
| echo "build_id=${TIMESTAMP}-${SHORT_SHA}" >> $GITHUB_OUTPUT | |
| - name: Install dependencies (Linux) | |
| if: matrix.platform == 'linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y python3 g++ make curl tar xz-utils | |
| - name: Build Node (linux) | |
| working-directory: node | |
| if: matrix.platform == 'linux' | |
| run: | | |
| ./configure --experimental-enable-pointer-compression | |
| make -j4 install DESTDIR=$GITHUB_WORKSPACE/node-install | |
| - name: Build Node (darwin) | |
| working-directory: node | |
| if: matrix.platform == 'darwin' | |
| run: | | |
| ./configure --experimental-enable-pointer-compression --without-snapshot | |
| make -j2 install DESTDIR=$GITHUB_WORKSPACE/node-install | |
| - name: Archive Node | |
| run: | | |
| mkdir -p artifacts | |
| FILENAME=node-${NODE_VERSION}-${{ matrix.platform }}-${{ matrix.arch }}-${{ steps.meta.outputs.build_id }}.tar.xz | |
| FILENAME_LATEST=node-${NODE_VERSION}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST.tar.xz | |
| tar -C node-install -cJf artifacts/$FILENAME . | |
| cp artifacts/$FILENAME artifacts/$FILENAME_LATEST | |
| echo "NODE_ARCHIVE=$FILENAME" >> $GITHUB_ENV | |
| echo "NODE_ARCHIVE_LATEST=$FILENAME_LATEST" >> $GITHUB_ENV | |
| - name: Upload Node archive | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-${{ steps.meta.outputs.build_id }} | |
| path: artifacts/${{ env.NODE_ARCHIVE }} | |
| - name: Upload Node archive latest | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: node-${{ env.NODE_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-LATEST | |
| path: artifacts/${{ env.NODE_ARCHIVE_LATEST }} | |
| - name: Upload Node archive to release | |
| # Publish the built Node archive to the node-${NODE_VERSION}-release release. | |
| # This is the first uploader in the pipeline; build-node-packages and | |
| # build-node-fibers attach additional artifacts to the same release later. | |
| # | |
| # Matrix concurrency: both matrix arms (linux-x64, linux-arm64) hit this step | |
| # in parallel. On the first run for a new NODE_VERSION the release does not | |
| # yet exist, so both arms race to create it. The view-or-create guard with | |
| # the trailing `|| gh release view` tolerates "already exists" from the | |
| # losing arm (as long as the release now exists); any other create failure | |
| # propagates through that second view. | |
| # | |
| # `--clobber` makes re-uploads idempotent on asset name collisions: an | |
| # existing asset with the same name is deleted before the new one uploads. | |
| # Acceptable here because the -LATEST assets are always reproducible from | |
| # the build inputs; if the upload fails after the delete, just re-run the | |
| # job. | |
| # | |
| # `gh release edit --title` after upload keeps the release title | |
| # deterministically derived from NODE_VERSION even if someone renames the | |
| # release in the GitHub UI. | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| TAG="node-$NODE_VERSION-release" | |
| RELEASE_NAME="node-$NODE_VERSION-LATEST" | |
| FILE="./artifacts/$NODE_ARCHIVE_LATEST" | |
| if ! gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then | |
| gh release create "$TAG" --title "$RELEASE_NAME" --notes "" --repo "$REPO" \ | |
| || gh release view "$TAG" --repo "$REPO" >/dev/null | |
| fi | |
| gh release upload "$TAG" "$FILE" --clobber --repo "$REPO" | |
| gh release edit "$TAG" --title "$RELEASE_NAME" --repo "$REPO" |