Automate version bump validation, changelog enforcement, and NPM publ… #86
Workflow file for this run
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: PR Build and Check | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| build: | |
| name: Build and Check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repo | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| - name: Enable Corepack | |
| run: corepack enable | |
| - name: Install Dependencies | |
| run: yarn install --immutable | |
| - name: Run Checks | |
| run: yarn check | |
| - name: Build | |
| run: yarn build | |
| - name: Run Tests | |
| run: yarn test | |
| version-check: | |
| name: Version Bump Check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repo | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check for source changes requiring version bump | |
| id: changes | |
| run: | | |
| CHANGED_FILES=$(git diff --name-only origin/main...HEAD) | |
| echo "Changed files:" | |
| echo "$CHANGED_FILES" | |
| NEEDS_BUMP=false | |
| while IFS= read -r file; do | |
| case "$file" in | |
| src/*|tsconfig.build.json|tsconfig.base.json) | |
| NEEDS_BUMP=true | |
| break | |
| ;; | |
| package.json) | |
| # Check if anything other than "version" changed | |
| OTHER_CHANGES=$(git diff origin/main...HEAD -- package.json | grep -E '^[+-]\s' | grep -v -E '^\+\+\+|^---' | grep -v '"version"' || true) | |
| if [ -n "$OTHER_CHANGES" ]; then | |
| NEEDS_BUMP=true | |
| break | |
| fi | |
| ;; | |
| esac | |
| done <<< "$CHANGED_FILES" | |
| echo "needs_bump=$NEEDS_BUMP" >> "$GITHUB_OUTPUT" | |
| - name: Verify version bump and changelog | |
| if: steps.changes.outputs.needs_bump == 'true' | |
| run: | | |
| PR_VERSION=$(node -p "require('./package.json').version") | |
| MAIN_VERSION=$(git show origin/main:package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).version") | |
| echo "Main version: $MAIN_VERSION" | |
| echo "PR version: $PR_VERSION" | |
| if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then | |
| echo "::error::Source files or dependencies changed but package version was not bumped. Please update the version in package.json." | |
| exit 1 | |
| fi | |
| HIGHER=$(node -e " | |
| const [a, b] = ['$PR_VERSION', '$MAIN_VERSION'].map(v => v.split('.').map(Number)); | |
| const isHigher = a[0] > b[0] || (a[0] === b[0] && a[1] > b[1]) || (a[0] === b[0] && a[1] === b[1] && a[2] > b[2]); | |
| process.exit(isHigher ? 0 : 1); | |
| " && echo "true" || echo "false") | |
| if [ "$HIGHER" != "true" ]; then | |
| echo "::error::PR version ($PR_VERSION) must be higher than main version ($MAIN_VERSION)." | |
| exit 1 | |
| fi | |
| echo "Version bumped from $MAIN_VERSION to $PR_VERSION" | |
| CHANGELOG_CHANGED=$(git diff --name-only origin/main...HEAD -- docs/changelog.md) | |
| if [ -z "$CHANGELOG_CHANGED" ]; then | |
| echo "::error::Version was bumped but docs/changelog.md was not updated. Please add a changelog entry for version $PR_VERSION." | |
| exit 1 | |
| fi | |
| echo "Changelog updated for version bump" |