Skip to content

Publish New Package Version #17

Publish New Package Version

Publish New Package Version #17

---
name: Publish New Package Version
on:
workflow_dispatch:
inputs:
version:
type: string
description: "version"
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: Validate version format and uniqueness
id: validate-version
working-directory: packages/${{ inputs.package }}
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
echo "Validating version: $INPUT_VERSION"
# Extract semver portion (strip suffix like -offchain-manager)
SEMVER=$(echo "$INPUT_VERSION" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+')
if [[ -z "$SEMVER" ]]; then
echo "❌ Invalid version format. Must follow semantic versioning (e.g., 1.0.0)"
exit 1
fi
# Extract current version from package.json
CURRENT_VERSION=$(jq -r '.version' package.json)
echo "Current version in package.json: $CURRENT_VERSION"
echo "Proposed version: $SEMVER"
# Compare versions using node + semver module
RESULT=$(node -p "
const semver = require('semver');
const current = '$CURRENT_VERSION';
const next = '$SEMVER';
if (!semver.valid(next)) {
console.error('❌ Invalid semver:', next);
process.exit(1);
}
if (semver.lte(next, current)) {
console.error('❌ Provided version must be greater than current version.');
process.exit(1);
}
'✅ Version is valid and greater.';
")
echo "$RESULT"
- name: Install dependencies
run: npm install
- name: Build selected package
working-directory: packages/${{ inputs.package }}
run: npm run build
- name: Update package version in package.json
working-directory: packages/${{ inputs.package }}
run: |
npm version ${{ inputs.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"