Skip to content

ops: revert files back ahead of merge #19

ops: revert files back ahead of merge

ops: revert files back ahead of merge #19

name: Publish beta version of notehub-js to npm
on:
push:
branches:
- "test-release-*"
paths:
- "openapi.yaml"
jobs:
publish-beta:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get current version from config.json
id: get_version
run: |
CURRENT_VERSION=$(jq -r .projectVersion config.json)
echo "Current project version: $CURRENT_VERSION"
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
- name: Get existing beta versions from npm
id: get_existing_versions
run: |
# Query npm for existing versions of the package
EXISTING_VERSIONS=$(npm show @blues-inc/notehub-js versions --json)
echo "Existing versions on npm: $EXISTING_VERSIONS"
# Extract current version without any existing beta suffix
BASE_VERSION=$(echo "$CURRENT_VERSION" | sed -E 's/-beta\.[0-9]+$//')
# Extract only the beta versions for the current base version (e.g., 1.0.23-beta.X)
CURRENT_BETA_VERSIONS=$(echo "$EXISTING_VERSIONS" | jq -r '.[]' | grep -E "^${BASE_VERSION}-beta\.[0-9]+$" || true)
echo "Current beta versions: $CURRENT_BETA_VERSIONS"
# Determine the next beta version number
if [ -z "$CURRENT_BETA_VERSIONS" ]; then
NEXT_BETA_VERSION=1
else
# Extract numeric suffixes of all beta versions, sort, and get the highest
HIGHEST_BETA_VERSION=$(echo "$CURRENT_BETA_VERSIONS" | sed -E 's/.*-beta\.([0-9]+)$/\1/' | sort -n | tail -n 1)
NEXT_BETA_VERSION=$((HIGHEST_BETA_VERSION + 1))
fi
# Set the new version as `MAJOR.MINOR.PATCH-beta.N`
NEW_VERSION="${BASE_VERSION}-beta.$NEXT_BETA_VERSION"
echo "Next beta version: $NEW_VERSION"
# Save to GitHub environment variables
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
- name: Update version to beta
run: |
# Update config.json with the new beta version
jq --arg new_version "$new_version" '.projectVersion = $new_version' config.json > config.tmp.json && mv config.tmp.json config.json
echo "Updated project version to: $new_version"
- name: Install Dependencies
run: npm install
- name: Remove Outdated SDK Folder
run: rm -rf src
- name: Generate New SDK
run: npm run generateDocs
- name: Setup .npmrc file to publish to npm
uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: |
cd src
npm install
- name: Publish Beta Version to npm
run: |
echo "Publishing beta version to npm... $new_version"
cd src
npm publish --tag beta --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Commit Updated config.json
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add config.json
git commit -m "Update project version to ${{ steps.update_version.outputs.new_version }} [skip ci]"
git push