Workflow file for this run
This file contains 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: Publish release-candidate npm package | |
on: | |
push: | |
branches: | |
- '**' | |
- '!main' | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18.18.0' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Get package name and current version from package.json | |
id: get_package_info | |
run: | | |
PACKAGE_NAME=$(jq -r .name < package.json) | |
echo "::set-output name=package_name::$PACKAGE_NAME" | |
# - name: Install dependencies | |
# run: npm install | |
# - name: Run tests | |
# run: npm test | |
# - name: Build package | |
# run: npm run build | |
# - name: Ensure no untracked changes after build | |
# run: | | |
# if [ -n "$(git status --porcelain)" ]; then | |
# echo "Untracked changes found after build" | |
# exit 1 | |
# else | |
# echo "No untracked changes" | |
# fi | |
- name: Set Git config | |
run: | | |
git config --local user.email "actions@github.com" | |
git config --local user.name "Github Actions" | |
- name: Iterate rc version | |
run: npm version prerelease --preid=rc | |
- name: Check and update package.json version | |
run: | | |
# Get the current version from package.json | |
PACKAGE_BASE_VERSION=$(node -p "require('./package.json').version") | cut -d "-" -f 1 | |
echo "::set-output name=base_version::$PACKAGE_BASE_VERSION" | |
# Check for matching npm versions | |
matching_versions=$(npm view ${{ steps.get_package_info.outputs.package_name }} versions --json | grep "$PACKAGE_BASE_VERSION") | |
if [ -n "$matching_versions" ]; then | |
# Overwrite package.json version with the latest rc version | |
latest_rc_version=${matching_versions[-1]} | |
npm version $latest_rc_version | |
echo "Updated package.json to version $latest_rc_version" | |
# Run npm version prerelease again | |
npm version prerelease --preid=rc | |
fi | |
# - name: Publish to npm | |
# run: npm publish --tag rc | |
# env: | |
# NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} |