fix: improve beta release cicd #163
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: Create a pre-release | |
| on: | |
| # Only trigger on PRs with "beta" label | |
| pull_request: | |
| types: [labeled, synchronize, reopened] | |
| concurrency: | |
| group: release | |
| cancel-in-progress: false | |
| jobs: | |
| release_metadata: | |
| # Run ONLY when PR has the "beta" label | |
| if: contains(github.event.pull_request.labels.*.name, 'beta') | |
| name: Prepare release metadata | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version_number: ${{ steps.release_metadata.outputs.version_number }} | |
| changelog: ${{ steps.release_metadata.outputs.changelog }} | |
| steps: | |
| - uses: apify/workflows/git-cliff-release@main | |
| name: Prepare release metadata | |
| id: release_metadata | |
| with: | |
| release_type: prerelease | |
| existing_changelog_path: CHANGELOG.md | |
| wait_for_checks: | |
| name: Wait for code checks to pass | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Wait for existing checks or skip if none | |
| uses: lewagon/[email protected] | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| check-regexp: (Code checks) | |
| wait-interval: 10 | |
| running-workflow-name: 'Wait for code checks to pass' | |
| allowed-conclusions: success,neutral,skipped | |
| continue-on-error: true | |
| - name: Run checks if none were found | |
| if: failure() | |
| uses: actions/checkout@v4 | |
| - name: Use Node.js 22 | |
| if: failure() | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: 'npm' | |
| cache-dependency-path: 'package-lock.json' | |
| - name: Install Dependencies | |
| if: failure() | |
| run: npm ci | |
| - name: Lint | |
| if: failure() | |
| run: npm run lint | |
| - name: Build | |
| if: failure() | |
| run: npm run build | |
| - name: Test | |
| if: failure() | |
| run: npm run test | |
| - name: Type checks | |
| if: failure() | |
| run: npm run type-check | |
| update_changelog_and_version: | |
| needs: [ release_metadata, wait_for_checks ] | |
| name: Update changelog and prepare beta version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| changelog_commitish: ${{ steps.commit.outputs.commit_long_sha || github.sha }} | |
| beta_version: ${{ steps.beta_version.outputs.version }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| repository: ${{ github.event.pull_request.head.repo.full_name }} | |
| - name: Use Node.js 22 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: 'npm' | |
| cache-dependency-path: 'package-lock.json' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Update package version to base version | |
| run: npm version --no-git-tag-version --allow-same-version ${{ needs.release_metadata.outputs.version_number }} | |
| - name: Calculate beta version (without updating package.json) | |
| id: beta_version | |
| run: | | |
| # Use the improved beta script to calculate version only | |
| node ./.github/scripts/before-beta-release.cjs --calculate-only | |
| # The script will output the beta version without updating package.json | |
| BETA_VERSION=$(cat /tmp/beta_version.txt) | |
| echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT | |
| echo "Beta version calculated: $BETA_VERSION" | |
| - name: Update CHANGELOG.md only | |
| uses: DamianReeves/write-file-action@master | |
| with: | |
| path: CHANGELOG.md | |
| write-mode: overwrite | |
| contents: ${{ needs.release_metadata.outputs.changelog }} | |
| - name: Commit changelog only | |
| id: commit | |
| uses: EndBug/add-and-commit@v9 | |
| with: | |
| author_name: Apify Release Bot | |
| author_email: [email protected] | |
| message: "chore(release): Update changelog for ${{ steps.beta_version.outputs.version }} [skip ci]" | |
| add: 'CHANGELOG.md' | |
| push: true | |
| - name: Create and push beta tag | |
| run: | | |
| git tag "v${{ steps.beta_version.outputs.version }}" | |
| git push origin "v${{ steps.beta_version.outputs.version }}" | |
| publish_to_npm: | |
| name: Publish to NPM | |
| needs: [ update_changelog_and_version ] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.update_changelog_and_version.outputs.changelog_commitish }} | |
| - name: Use Node.js 22 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: 'npm' | |
| cache-dependency-path: 'package-lock.json' | |
| - name: Install dependencies | |
| run: | | |
| echo "access=public" >> .npmrc | |
| echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc | |
| npm ci | |
| - name: Set beta version in package.json | |
| run: | | |
| BETA_VERSION="${{ needs.update_changelog_and_version.outputs.beta_version }}" | |
| echo "Setting package.json version to: $BETA_VERSION" | |
| npm version --no-git-tag-version --allow-same-version "$BETA_VERSION" | |
| - name: Verify version is set correctly | |
| run: | | |
| PACKAGE_VERSION=$(node -p "require('./package.json').version") | |
| EXPECTED_VERSION="${{ needs.update_changelog_and_version.outputs.beta_version }}" | |
| if [ "$PACKAGE_VERSION" != "$EXPECTED_VERSION" ]; then | |
| echo "Version mismatch! Package: $PACKAGE_VERSION, Expected: $EXPECTED_VERSION" | |
| exit 1 | |
| fi | |
| echo "Version verified: $PACKAGE_VERSION" | |
| - name: Build module | |
| run: npm run build | |
| - name: Publish to NPM | |
| run: npm publish --tag beta | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }} | |
| NPM_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }} |