From c17e9eed1585198e6bd50090bbd30711e64280e8 Mon Sep 17 00:00:00 2001 From: Dmytro Parzhytskyi Date: Wed, 15 Oct 2025 16:23:23 +0300 Subject: [PATCH 1/2] Make `bash` exit early --- .github/workflows/check-version-update-on-release.yaml | 4 ++++ .github/workflows/test-publish.yaml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/check-version-update-on-release.yaml b/.github/workflows/check-version-update-on-release.yaml index 05baf09..9c65be5 100644 --- a/.github/workflows/check-version-update-on-release.yaml +++ b/.github/workflows/check-version-update-on-release.yaml @@ -5,6 +5,10 @@ on: branches: - 'release/*' +defaults: + run: + shell: bash -o pipefail {0} + jobs: check: runs-on: ubuntu-latest diff --git a/.github/workflows/test-publish.yaml b/.github/workflows/test-publish.yaml index f229a76..a2b255c 100644 --- a/.github/workflows/test-publish.yaml +++ b/.github/workflows/test-publish.yaml @@ -8,6 +8,10 @@ on: branches: - main +defaults: + run: + shell: bash -o pipefail {0} + jobs: audit: name: Audit From 4659e815df24cad0a353569004cbf1ceb3710942 Mon Sep 17 00:00:00 2001 From: Dmytro Parzhytskyi Date: Wed, 15 Oct 2025 16:23:46 +0300 Subject: [PATCH 2/2] Separate version update detection and publishing into different jobs --- .github/workflows/test-publish.yaml | 49 ++++++++++++++++++----------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test-publish.yaml b/.github/workflows/test-publish.yaml index a2b255c..b360d09 100644 --- a/.github/workflows/test-publish.yaml +++ b/.github/workflows/test-publish.yaml @@ -78,40 +78,51 @@ jobs: name: coverage path: coverage - publish: + detect_version_update: if: github.event_name == 'push' && github.ref == 'refs/heads/main' - name: Publish on version update - needs: - - test - permissions: - contents: read - id-token: write + name: Detect version update runs-on: ubuntu-latest + outputs: + detected: ${{ steps.detect.outputs.detected }} steps: - uses: actions/checkout@v5 - - uses: actions/setup-node@v5 with: - node-version-file: '/.nvmrc' - registry-url: 'https://registry.npmjs.org' + fetch-depth: 2 - - name: Check for version update - id: check_version + - id: detect run: | CURRENT_VERSION=$(jq -r .version package.json) PREVIOUS_VERSION=$(git show HEAD~1:package.json | jq -r .version) if [[ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]]; then - echo "version_updated=true" >> $GITHUB_OUTPUT + echo "Version has been updated. Proceeding to publish." + echo "detected=true" >> $GITHUB_OUTPUT + else + echo "Version has not changed. Skipping publish." + echo "detected=false" >> $GITHUB_OUTPUT fi - - if: steps.check_version.outputs.version_updated - run: npm ci + publish: + name: Publish + needs: + - test + - detect_version_update + if: needs.detect_version_update.outputs.detected == 'true' + permissions: + contents: read + id-token: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version-file: '/.nvmrc' + registry-url: 'https://registry.npmjs.org' - - if: steps.check_version.outputs.version_updated - run: npm run build + - run: npm ci + - run: npm run build - - if: steps.check_version.outputs.version_updated - name: Publish + - name: Publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: |