Repository navigation
chore(release): publish to npm with trusted publishing #93
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
Open
cs-raj
wants to merge
5
commits into
development
Choose a base branch
from
feat/DX-27614
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5acdf9c
chore(release): publish to npm with trusted publishing
cs-raj debf795
chore(release): verify the tag matches package.json, pass it via env
cs-raj 2bfd306
fix: bump lodash to ^4.18.1 to resolve Snyk findings
cs-raj 5596cde
Merge remote-tracking branch 'origin/development' into feat/DX-27614
cs-raj 99a92d7
fix: regenerate lock file to clear npm audit findings
cs-raj 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 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 |
|---|---|---|
| @@ -1,55 +1,58 @@ | ||
| name: Release | ||
|
|
||
| name: Publish package to npmjs registry | ||
| on: | ||
| release: | ||
| types: [created] | ||
| types: [published] | ||
|
|
||
| jobs: | ||
| build: | ||
| publish-npm: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| steps: | ||
| # Checkout the repository | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| # Setup Node.js environment | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| node-version: "22.x" | ||
|
|
||
| # Install dependencies | ||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| # Fetch package details (name and version) | ||
| - name: Get package details | ||
| id: package | ||
| uses: codex-team/[email protected] | ||
|
|
||
| # Install npm-pack-all to create a package archive | ||
| - name: Install npm pack | ||
| run: npm install npm-pack | ||
|
|
||
| # Pack the package into a .tgz archive | ||
| - name: Pack the npm package | ||
| run: npm pack | ||
|
|
||
| # Publish the package to npm | ||
| - name: Publish to npm | ||
| id: publish_npm | ||
| uses: JS-DevTools/npm-publish@v3 | ||
| ref: ${{ github.event.release.tag_name }} | ||
| persist-credentials: false | ||
| - uses: actions/setup-node@v7 | ||
| with: | ||
| token: ${{ secrets.NPM_TOKEN }} | ||
| # access: public # Uncomment this line if you want to publish the package as public for first time | ||
|
|
||
| # Upload the packaged .tgz to the release that triggered this workflow | ||
| - name: Upload Release Asset | ||
| uses: actions/upload-release-asset@v1 | ||
| node-version: 24 | ||
| registry-url: https://registry.npmjs.org/ | ||
| cache: 'npm' | ||
| - name: Check the release tag matches package.json | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| RELEASE_TAG: ${{ github.event.release.tag_name }} | ||
| run: | | ||
| PKG_VERSION="v$(node -p "require('./package.json').version")" | ||
| if [ "$RELEASE_TAG" != "$PKG_VERSION" ]; then | ||
| echo "::error::release tag $RELEASE_TAG does not match package.json version $PKG_VERSION" | ||
| exit 1 | ||
| fi | ||
| - run: npm ci | ||
| - name: Update npm | ||
| run: npm install -g npm@latest | ||
| - name: Release | ||
| run: npm publish --access public --tag ${{ github.event.release.prerelease && 'beta' || 'latest' }} | ||
|
|
||
| upload-release-asset: | ||
| runs-on: ubuntu-latest | ||
| needs: publish-npm | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| upload_url: ${{ github.event.release.upload_url }} | ||
| asset_path: "./contentstack-datasync-mongodb-sdk-${{ steps.package.outputs.version }}.tgz" | ||
| asset_name: "contentstack-datasync-mongodb-sdk-${{ steps.package.outputs.version }}.tgz" | ||
| asset_content_type: application/tgz | ||
| ref: ${{ github.event.release.tag_name }} | ||
| persist-credentials: false | ||
| - uses: actions/setup-node@v7 | ||
| with: | ||
| node-version: 24 | ||
| cache: 'npm' | ||
| - run: npm ci | ||
| - name: Pack | ||
| run: npm pack | ||
| - name: Attach the tarball to the release | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| RELEASE_TAG: ${{ github.event.release.tag_name }} | ||
| run: gh release upload "$RELEASE_TAG" ./*.tgz --clobber | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.