ci: auto-increment beta versions on dev branch

- Workflow now auto-detects highest existing beta (from tags + npm)
- Increments to next beta: X.Y.Z-beta.N -> X.Y.Z-beta.(N+1)
- Updates package.json automatically with [skip ci]
- No manual version bumping needed for dev releases
- Bump base version to 1.2.6 for next release cycle
This commit is contained in:
tctinh
2025-12-26 11:51:12 +07:00
parent 4cfac758fe
commit 1f23cc18c2
2 changed files with 79 additions and 61 deletions

View File

@@ -24,6 +24,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Use Node.js
uses: actions/setup-node@v4
@@ -32,53 +33,75 @@ jobs:
registry-url: https://registry.npmjs.org
always-auth: true
- name: Determine release state
- name: Determine and bump beta version
id: determine
run: |
set -euo pipefail
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "current_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
# Check if this is already a beta version
if [[ "$CURRENT_VERSION" == *"-beta"* ]] || [[ "$CURRENT_VERSION" == *"-alpha"* ]] || [[ "$CURRENT_VERSION" == *"-rc"* ]]; then
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
fi
# Get base version from package.json (strip any existing prerelease suffix)
RAW_VERSION=$(node -p "require('./package.json').version")
BASE_VERSION=$(echo "$RAW_VERSION" | sed 's/-.*$//')
echo "base_version=$BASE_VERSION" >> "$GITHUB_OUTPUT"
# Check if tag already exists
# Fetch all tags
git fetch --tags --force
if git tag -l "v$CURRENT_VERSION" | grep -q "v$CURRENT_VERSION"; then
echo "tag_exists=true" >> "$GITHUB_OUTPUT"
else
echo "tag_exists=false" >> "$GITHUB_OUTPUT"
fi
# Check npm for existing version
NPM_VERSION=$(npm view opencode-antigravity-auth@"$CURRENT_VERSION" version 2>/dev/null || echo "")
if [ -n "$NPM_VERSION" ]; then
echo "npm_exists=true" >> "$GITHUB_OUTPUT"
else
echo "npm_exists=false" >> "$GITHUB_OUTPUT"
fi
# Find the highest beta number for this base version
HIGHEST_BETA=-1
for tag in $(git tag -l "v${BASE_VERSION}-beta.*"); do
# Extract beta number from tag like v1.2.5-beta.3
BETA_NUM=$(echo "$tag" | sed "s/v${BASE_VERSION}-beta\\.//")
if [[ "$BETA_NUM" =~ ^[0-9]+$ ]] && [ "$BETA_NUM" -gt "$HIGHEST_BETA" ]; then
HIGHEST_BETA=$BETA_NUM
fi
done
# Also check npm for published beta versions
NPM_BETAS=$(npm view opencode-antigravity-auth versions --json 2>/dev/null | grep -oP "\"${BASE_VERSION}-beta\\.\\K[0-9]+" || echo "")
for BETA_NUM in $NPM_BETAS; do
if [ "$BETA_NUM" -gt "$HIGHEST_BETA" ]; then
HIGHEST_BETA=$BETA_NUM
fi
done
# Increment to next beta
NEXT_BETA=$((HIGHEST_BETA + 1))
NEXT_VERSION="${BASE_VERSION}-beta.${NEXT_BETA}"
echo "next_version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
echo "next_beta=$NEXT_BETA" >> "$GITHUB_OUTPUT"
echo "Base version: $BASE_VERSION"
echo "Highest existing beta: $HIGHEST_BETA"
echo "Next beta version: $NEXT_VERSION"
- name: Update package.json version
id: update_version
run: |
NEXT_VERSION="${{ steps.determine.outputs.next_version }}"
# Update package.json with new beta version
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.version = '$NEXT_VERSION';
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 4) + '\n');
"
echo "Updated package.json to version $NEXT_VERSION"
# Commit the version bump
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json
git commit -m "chore: bump version to $NEXT_VERSION [skip ci]" || echo "No changes to commit"
git push origin dev || echo "Push failed or no changes"
- name: Check if should publish
id: should_publish
run: |
FORCE="${{ github.event.inputs.force }}"
TAG_EXISTS="${{ steps.determine.outputs.tag_exists }}"
NPM_EXISTS="${{ steps.determine.outputs.npm_exists }}"
if [ "$FORCE" = "true" ]; then
echo "should_publish=true" >> "$GITHUB_OUTPUT"
echo "Forcing publish due to manual trigger"
elif [ "$TAG_EXISTS" = "true" ] || [ "$NPM_EXISTS" = "true" ]; then
echo "should_publish=false" >> "$GITHUB_OUTPUT"
echo "Version already exists (tag=$TAG_EXISTS, npm=$NPM_EXISTS)"
else
echo "should_publish=true" >> "$GITHUB_OUTPUT"
echo "New version detected, will publish"
fi
# Always publish since we auto-increment
echo "should_publish=true" >> "$GITHUB_OUTPUT"
echo "Will publish version ${{ steps.determine.outputs.next_version }}"
- name: Verify NPM token
if: steps.should_publish.outputs.should_publish == 'true'
@@ -115,41 +138,44 @@ jobs:
[ -d dist/src ] || { echo "dist/src/ missing" >&2; exit 1; }
- name: Create git tag
if: steps.should_publish.outputs.should_publish == 'true' && steps.determine.outputs.tag_exists == 'false'
if: steps.should_publish.outputs.should_publish == 'true'
run: |
CURRENT_VERSION="${{ steps.determine.outputs.current_version }}"
NEXT_VERSION="${{ steps.determine.outputs.next_version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "v$CURRENT_VERSION"
git push origin "v$CURRENT_VERSION"
git tag "v$NEXT_VERSION"
git push origin "v$NEXT_VERSION"
- name: Generate release notes
if: steps.should_publish.outputs.should_publish == 'true'
id: release_notes
run: |
set -euo pipefail
CURRENT_VERSION="${{ steps.determine.outputs.current_version }}"
NEXT_VERSION="${{ steps.determine.outputs.next_version }}"
BASE_VERSION="${{ steps.determine.outputs.base_version }}"
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
CHANGELOG=$(git log --no-merges --pretty=format:'- %s (%h)' "${LAST_TAG}..HEAD")
COMPARE_URL="https://github.com/${GITHUB_REPOSITORY}/compare/${LAST_TAG}...v${CURRENT_VERSION}"
CHANGELOG=$(git log --no-merges --pretty=format:'- %s (%h)' "${LAST_TAG}..HEAD" | grep -v "\[skip ci\]" || echo "")
COMPARE_URL="https://github.com/${GITHUB_REPOSITORY}/compare/${LAST_TAG}...v${NEXT_VERSION}"
else
CHANGELOG=$(git log --no-merges --pretty=format:'- %s (%h)' -20)
CHANGELOG=$(git log --no-merges --pretty=format:'- %s (%h)' -20 | grep -v "\[skip ci\]" || echo "")
COMPARE_URL=""
fi
if [ -z "$CHANGELOG" ]; then
CHANGELOG="- Beta release"
CHANGELOG="- Beta release ${NEXT_VERSION}"
fi
BODY_FILE=$(mktemp)
{
echo "## Beta Release v${CURRENT_VERSION}"
echo "## Beta Release v${NEXT_VERSION}"
echo ""
echo "⚠️ **This is a beta release for testing. Use at your own risk.**"
echo ""
echo "Base version: \`${BASE_VERSION}\`"
echo ""
if [ -n "$COMPARE_URL" ]; then
echo "Compare changes: $COMPARE_URL"
echo ""
@@ -162,11 +188,11 @@ jobs:
echo ""
printf '%s\n' '```json'
printf '%s\n' '{'
printf '%s\n' " \"plugin\": [\"opencode-antigravity-auth@${CURRENT_VERSION}\"]"
printf '%s\n' " \"plugin\": [\"opencode-antigravity-auth@${NEXT_VERSION}\"]"
printf '%s\n' '}'
printf '%s\n' '```'
echo ""
echo "Or use the beta tag:"
echo "Or use the beta tag (always latest beta):"
echo ""
printf '%s\n' '```json'
printf '%s\n' '{'
@@ -193,8 +219,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.determine.outputs.current_version }}
release_name: v${{ steps.determine.outputs.current_version }} (Beta)
tag_name: v${{ steps.determine.outputs.next_version }}
release_name: v${{ steps.determine.outputs.next_version }} (Beta)
body: ${{ steps.release_notes.outputs.body }}
prerelease: true
draft: false
@@ -210,18 +236,10 @@ jobs:
run: |
echo "## Beta Release Published! 🚀" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ steps.determine.outputs.current_version }}" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ steps.determine.outputs.next_version }}" >> $GITHUB_STEP_SUMMARY
echo "**Base:** ${{ steps.determine.outputs.base_version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Install:**" >> $GITHUB_STEP_SUMMARY
echo '```json' >> $GITHUB_STEP_SUMMARY
echo '{ "plugin": ["opencode-antigravity-auth@beta"] }' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Skip summary
if: steps.should_publish.outputs.should_publish == 'false'
run: |
echo "## Skipped Beta Release" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Version ${{ steps.determine.outputs.current_version }} already exists." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "To publish, bump the version in package.json or use manual trigger with force option." >> $GITHUB_STEP_SUMMARY

View File

@@ -1,6 +1,6 @@
{
"name": "opencode-antigravity-auth",
"version": "1.2.5",
"version": "1.2.6",
"description": "Google Antigravity IDE OAuth auth plugin for Opencode - access Gemini 3 Pro and Claude 4.5 using Google credentials",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",