From 24a96ac7ad1e5417b9cece94fc02a6a7462c55c0 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 24 Jan 2025 15:26:56 +0000 Subject: [PATCH] chore(ci): use prebuilds to speed up ci runs --- .github/workflows/build-and-test.yml | 17 ++++++++++++----- script/ci/check-release-libs.sh | 2 +- script/ci/unpack-and-test.sh | 12 +++++++----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 9cb8feb8..f6e61cb1 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -64,30 +64,32 @@ jobs: steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + if: github.ref == 'refs/heads/master' with: fetch-depth: 0 - name: Use Node.js ${{ env.NODE_VERSION }} uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4 + if: github.ref == 'refs/heads/master' with: node-version: ${{ env.NODE_VERSION }} - - if: runner.os == 'Windows' + - if: ${{ runner.os == 'Windows' && github.ref == 'refs/heads/master'}} run: echo "ONLY_DOWNLOAD_PACT_FOR_WINDOWS=true" >> $GITHUB_ENV - - if: ${{ matrix.docker == true && matrix.alpine == true }} + - if: ${{ matrix.docker == true && matrix.alpine == true && github.ref == 'refs/heads/master'}} name: prebuild linux ${{ matrix.arch }} musl run: docker run -v $PWD:/home --platform linux/${{ matrix.arch }} --rm node:20-alpine bin/sh -c 'apk add bash && cd /home && bash -c "/home/script/ci/prebuild-alpine.sh" && rm -rf ffi node_modules' - - if: ${{ matrix.docker == true && matrix.alpine != true }} + - if: ${{ matrix.docker == true && matrix.alpine != true && github.ref == 'refs/heads/master' }} name: prebuild linux ${{ matrix.arch }} run: docker run -v $PWD:/home --platform linux/${{ matrix.arch }} --rm node:20 bin/bash -c 'cd /home && /home/script/ci/prebuild.sh && rm -rf ffi node_modules' - run: sudo chown -R $(id -u):$(id -g) prebuilds - if: ${{ matrix.docker == true }} + if: ${{ matrix.docker == true && github.ref == 'refs/heads/master' }} - run: ./script/ci/prebuild.sh - if: ${{ matrix.docker != true }} + if: ${{ matrix.docker != true && github.ref == 'refs/heads/master'}} - name: Upload prebuild for ${{ runner.os }}-${{ runner.arch }} uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4 @@ -156,7 +158,12 @@ jobs: fetch-depth: 0 - name: Download prebuilds + if: github.ref == 'refs/heads/master' uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + - run: FETCH_ASSETS=true REPO=you54f/pact-js-core ./script/ci/check-release-libs.sh --fetch-assets -t + if: github.ref != 'refs/heads/master' + env: + GITHUB_TOKEN: ${{ github.token }} - name: Use Node.js ${{ env.NODE_VERSION }} uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4 diff --git a/script/ci/check-release-libs.sh b/script/ci/check-release-libs.sh index 479ab174..22b60fce 100755 --- a/script/ci/check-release-libs.sh +++ b/script/ci/check-release-libs.sh @@ -69,7 +69,7 @@ if [[ "$TAG" == "" ]]; then else GH_TAG_OPTION="$TAG" if [[ "$TAG" == "latest" ]]; then - GH_TAG_OPTION='' + GH_TAG_OPTION=$(gh release list --limit 1 --repo you54f/pact-js-core --json tagName --jq '.[].tagName') fi if [[ "${LIST_ASSETS:-}" = true || "${FETCH_ASSETS:-}" = true ]]; then diff --git a/script/ci/unpack-and-test.sh b/script/ci/unpack-and-test.sh index ab136d88..7002ef6b 100755 --- a/script/ci/unpack-and-test.sh +++ b/script/ci/unpack-and-test.sh @@ -5,11 +5,13 @@ set -u SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" # Figure out where the script is running . "$SCRIPT_DIR"/../lib/robust-bash.sh -ls -1 -ls -1 artifact* -mkdir -p prebuilds -mv artifact*/*.tar.gz . -ls *.gz |xargs -n1 tar -xzf +if [ ! -d "prebuilds" ]; then + ls -1 + ls -1 artifact* + mkdir -p prebuilds + mv artifact*/*.tar.gz . + ls *.gz | xargs -n1 tar -xzf +fi "$SCRIPT_DIR"/../download-plugins.sh # Use the determined platform