fix: improve beta release cicd #157
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: | |
| - uses: lewagon/[email protected] | |
| with: | |
| ref: ${{ github.ref }} | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| check-regexp: (Code checks) | |
| wait-interval: 5 | |
| 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 }} | |
| - 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 and set beta version | |
| id: beta_version | |
| run: | | |
| # Use the improved beta script | |
| node ./.github/scripts/before-beta-release.cjs | |
| # Output the version for later jobs | |
| BETA_VERSION=$(node -p "require('./package.json').version") | |
| echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT | |
| echo "Beta version: $BETA_VERSION" | |
| - name: Update CHANGELOG.md | |
| uses: DamianReeves/write-file-action@master | |
| with: | |
| path: CHANGELOG.md | |
| write-mode: overwrite | |
| contents: ${{ needs.release_metadata.outputs.changelog }} | |
| - name: Commit changes | |
| id: commit | |
| uses: EndBug/add-and-commit@v9 | |
| with: | |
| author_name: Apify Release Bot | |
| author_email: [email protected] | |
| message: "chore(release): Update to ${{ steps.beta_version.outputs.version }} [skip ci]" | |
| - 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: Verify version consistency | |
| 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 }} |