Publish New Package Version #15
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: Build And Publish Package Update | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| package: | |
| type: choice | |
| description: Package name | |
| options: | |
| - offchain-manager | |
| - addresses | |
| - indexer | |
| - mint-manager | |
| jobs: | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| registry-url: 'https://registry.npmjs.org/' | |
| # - name: Authenticate with NmpJS | |
| # run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
| - name: Install dependencies (root) | |
| run: npm install | |
| - name: Build selected package | |
| working-directory: packages/${{ inputs.package }} | |
| run: npm run build | |
| - name: Determine new version | |
| id: versioning | |
| run: | | |
| PACKAGE="${{ inputs.package }}" | |
| LATEST_TAG=$(git tag --list "*-${PACKAGE}" --sort=-v:refname | head -n 1) | |
| if [ -z "$LATEST_TAG" ]; then | |
| echo "No version found" | |
| NEW_VERSION="1.0.0-$PACKAGE" | |
| else | |
| echo "Version found: $LATEST_TAG" | |
| BASE_VERSION=${LATEST_TAG%-${PACKAGE}} | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION" | |
| PATCH=$((PATCH + 1)) | |
| NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}-$PACKAGE" | |
| fi | |
| echo "New version: $NEW_VERSION" | |
| # Set the version as output | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| - name: Update package version in package.json | |
| working-directory: packages/${{ inputs.package }} | |
| env: | |
| version: ${{ steps.versioning.outputs.version }} | |
| run: | | |
| PURE_VERSION=${version%-${package}} | |
| # Show for debug | |
| echo "Original version: $version" | |
| echo "Pure version for npm: $PURE_VERSION" | |
| # Run npm version with the pure semver | |
| npm version $PURE_VERSION --no-git-tag-version | |
| - name: Publish package to npm registry | |
| working-directory: packages/${{ inputs.package }} | |
| run: npm publish --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Commit and push version bump and tag | |
| env: | |
| version: ${{ steps.versioning.outputs.version }} | |
| package: ${{ inputs.package }} | |
| GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Commit the updated package.json with new version | |
| git add packages/$package/package.json | |
| git commit -m "chore($package): bump version to $version" | |
| # Create a tag with the version | |
| git tag -a "$version" -m "Release $version" | |
| # Push commit and tag | |
| git push origin HEAD | |
| git push origin "$version" |