-
Notifications
You must be signed in to change notification settings - Fork 38
ci: Set up OIDC NPM publishing (initial attempt) #768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,14 +20,54 @@ on: | |
| required: false | ||
| type: string | ||
| default: '' | ||
| # Push to master will deploy a beta version | ||
| push: | ||
| branches: | ||
| - master | ||
| tags-ignore: | ||
| - '**' # Ignore all tags to prevent duplicate builds when tags are pushed. | ||
|
|
||
| permissions: | ||
| id-token: write # Required for OIDC | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: release | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| release_metadata: | ||
| name: Prepare release metadata | ||
| # ============================================================================ | ||
| # ROUTE DECISION | ||
| # ============================================================================ | ||
|
|
||
| determine_path: | ||
| name: Determine release path | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| path: ${{ steps.decide.outputs.path }} | ||
| steps: | ||
| - name: Decide path | ||
| id: decide | ||
| run: | | ||
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | ||
| echo "path=stable" >> $GITHUB_OUTPUT | ||
| elif [[ "${{ github.event_name }}" == "push" ]] && \ | ||
| [[ ! "${{ github.event.head_commit.message }}" =~ ^docs ]] && \ | ||
| [[ ! "${{ github.event.head_commit.message }}" =~ ^ci ]] && \ | ||
| [[ "${{ github.repository }}" =~ ^apify/ ]]; then | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move the checks for repository out into each job instead |
||
| echo "path=prerelease" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "path=skip" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| # ============================================================================ | ||
| # STABLE RELEASE PATH (workflow_dispatch) | ||
| # ============================================================================ | ||
|
|
||
| stable_release_metadata: | ||
| needs: determine_path | ||
| if: needs.determine_path.outputs.path == 'stable' | ||
| name: '[Stable] Prepare release metadata' | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| version_number: ${{ steps.release_metadata.outputs.version_number }} | ||
|
|
@@ -43,12 +83,14 @@ jobs: | |
| custom_version: ${{ inputs.custom_version }} | ||
| existing_changelog_path: CHANGELOG.md | ||
|
|
||
| run_code_checks: | ||
| stable_run_code_checks: | ||
| needs: determine_path | ||
| if: needs.determine_path.outputs.path == 'stable' | ||
| uses: ./.github/workflows/check.yaml | ||
|
|
||
| update_changelog: | ||
| needs: [release_metadata, run_code_checks] | ||
| name: Update changelog | ||
| stable_update_changelog: | ||
| needs: [stable_release_metadata, stable_run_code_checks] | ||
| name: '[Stable] Update changelog' | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| changelog_commitish: ${{ steps.commit.outputs.commit_long_sha || github.sha }} | ||
|
|
@@ -65,14 +107,14 @@ jobs: | |
| node-version: 22 | ||
|
|
||
| - name: Update package version in package.json | ||
| run: npm version --no-git-tag-version --allow-same-version ${{ needs.release_metadata.outputs.version_number }} | ||
| run: npm version --no-git-tag-version --allow-same-version ${{ needs.stable_release_metadata.outputs.version_number }} | ||
|
|
||
| - name: Update CHANGELOG.md | ||
| uses: DamianReeves/write-file-action@master | ||
| with: | ||
| path: CHANGELOG.md | ||
| write-mode: overwrite | ||
| contents: ${{ needs.release_metadata.outputs.changelog }} | ||
| contents: ${{ needs.stable_release_metadata.outputs.changelog }} | ||
|
|
||
| - name: Commit changes | ||
| id: commit | ||
|
|
@@ -82,29 +124,29 @@ jobs: | |
| author_email: [email protected] | ||
| message: 'chore(release): Update changelog and package version [skip ci]' | ||
|
|
||
| create_github_release: | ||
| name: Create github release | ||
| needs: [release_metadata, update_changelog] | ||
| stable_create_github_release: | ||
| needs: [stable_release_metadata, stable_update_changelog] | ||
| name: '[Stable] Create github release' | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| steps: | ||
| - name: Create release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| tag_name: ${{ needs.release_metadata.outputs.tag_name }} | ||
| name: ${{ needs.release_metadata.outputs.version_number }} | ||
| target_commitish: ${{ needs.update_changelog.outputs.changelog_commitish }} | ||
| body: ${{ needs.release_metadata.outputs.release_notes }} | ||
| tag_name: ${{ needs.stable_release_metadata.outputs.tag_name }} | ||
| name: ${{ needs.stable_release_metadata.outputs.version_number }} | ||
| target_commitish: ${{ needs.stable_update_changelog.outputs.changelog_commitish }} | ||
| body: ${{ needs.stable_release_metadata.outputs.release_notes }} | ||
|
|
||
| publish_to_npm: | ||
| name: Publish to NPM | ||
| needs: [update_changelog] | ||
| stable_publish_to_npm: | ||
| needs: [stable_update_changelog] | ||
| name: '[Stable] Publish to NPM' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| with: | ||
| ref: ${{ needs.update_changelog.outputs.changelog_commitish }} | ||
| ref: ${{ needs.stable_update_changelog.outputs.changelog_commitish }} | ||
| - name: Use Node.js 22 | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
|
|
@@ -113,16 +155,15 @@ jobs: | |
| 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: Build module | ||
| run: npm run build | ||
| - name: Publish to NPM | ||
| run: npm publish --tag latest | ||
|
|
||
| version-docs: | ||
| needs: publish_to_npm | ||
| stable_version_docs: | ||
| needs: [stable_publish_to_npm] | ||
| name: '[Stable] Version docs' | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
|
|
@@ -168,6 +209,96 @@ jobs: | |
| author_email: [email protected] | ||
| message: 'docs: update docs for ${{ inputs.version }} version' | ||
|
|
||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }} | ||
| NPM_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }} | ||
| # ============================================================================ | ||
| # PRE-RELEASE PATH (push to master) | ||
| # ============================================================================ | ||
|
|
||
| prerelease_release_metadata: | ||
| needs: determine_path | ||
| if: needs.determine_path.outputs.path == 'prerelease' | ||
| name: '[Pre-release] 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 | ||
|
|
||
| prerelease_wait_for_checks: | ||
| needs: determine_path | ||
| if: needs.determine_path.outputs.path == 'prerelease' | ||
| name: '[Pre-release] 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: (Build & Test .*|Lint|Docs build) | ||
| wait-interval: 5 | ||
|
|
||
| prerelease_update_changelog: | ||
| needs: [prerelease_release_metadata, prerelease_wait_for_checks] | ||
| name: '[Pre-release] Update changelog' | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| changelog_commitish: ${{ steps.commit.outputs.commit_long_sha || github.sha }} | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} | ||
|
|
||
| - name: Use Node.js 22 | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: 22 | ||
|
|
||
| - name: Update package version in package.json | ||
| run: npm version --no-git-tag-version --allow-same-version ${{ needs.prerelease_release_metadata.outputs.version_number }} | ||
|
|
||
| - name: Update CHANGELOG.md | ||
| uses: DamianReeves/write-file-action@master | ||
| with: | ||
| path: CHANGELOG.md | ||
| write-mode: overwrite | ||
| contents: ${{ needs.prerelease_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 changelog and package version [skip ci]' | ||
|
|
||
| prerelease_publish_to_npm: | ||
| needs: [prerelease_update_changelog, prerelease_wait_for_checks] | ||
| name: '[Pre-release] Publish to NPM' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| with: | ||
| ref: ${{ needs.prerelease_update_changelog.outputs.changelog_commitish }} | ||
| - name: Use Node.js 22 | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: 22 | ||
| cache: 'npm' | ||
| cache-dependency-path: 'package-lock.json' | ||
| - name: Install dependencies | ||
| run: | | ||
| npm ci | ||
| - # Check version consistency and increment pre-release version number for beta only. | ||
| name: Bump pre-release version | ||
| run: node ./.github/scripts/before-beta-release.js | ||
| - name: Build module | ||
| run: npm run build | ||
| - name: Publish to NPM | ||
| run: npm publish --tag beta | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe
(determine|pick)_release_typewould fit this job better. At first, I thought "release path" would be a filesystem path with the build.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, and i also like
pickbetter thandetermine