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..b360d09 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 @@ -74,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: |