diff --git a/.github/workflows/check-version-update-on-release.yaml b/.github/workflows/check-version-update-on-release.yaml new file mode 100644 index 0000000..05baf09 --- /dev/null +++ b/.github/workflows/check-version-update-on-release.yaml @@ -0,0 +1,27 @@ +name: Check Version update on release + +on: + pull_request: + branches: + - 'release/*' + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - run: | + CHANGED_FILES=$(git diff --name-only "origin/${{ github.base_ref }}...HEAD") + + if ! echo "${CHANGED_FILES}" | grep -qx "package.json"; then + echo "::error::Release PRs must include an update to package.json." + exit 1 + fi + + if ! echo "${CHANGED_FILES}" | grep -qx "package-lock.json"; then + echo "::error::Release PRs must include an update to package-lock.json." + exit 1 + fi diff --git a/.github/workflows/test-publish.yaml b/.github/workflows/test-publish.yaml index 0a27ee1..f229a76 100644 --- a/.github/workflows/test-publish.yaml +++ b/.github/workflows/test-publish.yaml @@ -4,8 +4,6 @@ on: push: branches: - main - tags: - - 'v*' pull_request: branches: - main @@ -77,14 +75,14 @@ jobs: path: coverage publish: - name: Publish + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + name: Publish on version update needs: - test permissions: contents: read id-token: write runs-on: ubuntu-latest - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 @@ -92,10 +90,24 @@ jobs: node-version-file: '/.nvmrc' registry-url: 'https://registry.npmjs.org' - - run: npm ci - - run: npm run build + - name: Check for version update + id: check_version + 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 + fi + + - if: steps.check_version.outputs.version_updated + run: npm ci + + - if: steps.check_version.outputs.version_updated + run: npm run build - - name: Publish + - if: steps.check_version.outputs.version_updated + name: Publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: |