fix: report page version not updating after releases #273
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: Pre-release from develop | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| workflow_dispatch: | |
| jobs: | |
| prerelease: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Determine pre-release version | |
| id: version | |
| run: | | |
| # Get the version from package.json (strip any existing pre-release suffix) | |
| PKG_VERSION=$(node -p "require('./package.json').version.replace(/-.*/, '')") | |
| # Get the latest stable release tag and increment its patch | |
| LATEST_TAG=$(gh release list --exclude-drafts --exclude-pre-releases --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null || echo "") | |
| if [ -n "$LATEST_TAG" ]; then | |
| TAG_BASE="${LATEST_TAG#v}" | |
| MAJOR=$(echo "$TAG_BASE" | cut -d. -f1) | |
| MINOR=$(echo "$TAG_BASE" | cut -d. -f2) | |
| PATCH=$(echo "$TAG_BASE" | cut -d. -f3) | |
| TAG_NEXT="${MAJOR}.${MINOR}.$((PATCH + 1))" | |
| else | |
| TAG_NEXT="0.0.0" | |
| fi | |
| # Use whichever is higher: package.json version or tag+1 | |
| # This respects manual version bumps (e.g., 1.2.0) over auto-incremented patch (1.1.5) | |
| BASE_VERSION=$(node -e " | |
| const a = '${PKG_VERSION}'.split('.').map(Number); | |
| const b = '${TAG_NEXT}'.split('.').map(Number); | |
| const cmp = a[0]-b[0] || a[1]-b[1] || a[2]-b[2]; | |
| console.log(cmp >= 0 ? '${PKG_VERSION}' : '${TAG_NEXT}'); | |
| ") | |
| SHORT_SHA=$(git rev-parse --short HEAD) | |
| TIMESTAMP=$(date -u +%Y%m%d%H%M%S) | |
| PRE_VERSION="${BASE_VERSION}-dev.${TIMESTAMP}.${SHORT_SHA}" | |
| echo "version=$PRE_VERSION" >> $GITHUB_OUTPUT | |
| echo "Pre-release version: $PRE_VERSION (pkg=${PKG_VERSION}, tag+1=${TAG_NEXT})" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Write version to package.json | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| npm version "$VERSION" --no-git-tag-version | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add package.json package-lock.json | |
| git commit -m "chore: bump version to $VERSION [skip ci]" | |
| git push origin develop | |
| - name: Build project | |
| run: npm run build | |
| - name: Generate changelog from AI commit comments | |
| id: changelog | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GITHUB_REPOSITORY: ${{ github.repository }} | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| npm install --no-save @octokit/rest | |
| # Use the last stable release tag (not pre-release) for the commit range | |
| LAST_TAG=$(gh release list --exclude-drafts --exclude-pre-releases --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null || echo "") | |
| export LAST_TAG | |
| node scripts/ai-generate-changelog.mjs || true | |
| if [ ! -f CHANGELOG.txt ]; then | |
| echo "## Pre-release ${{ steps.version.outputs.version }}" > CHANGELOG.txt | |
| echo "" >> CHANGELOG.txt | |
| git log --oneline --no-merges "${LAST_TAG}..HEAD" 2>/dev/null >> CHANGELOG.txt || \ | |
| git log --oneline --no-merges -10 >> CHANGELOG.txt | |
| fi | |
| - name: Create Git tag | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git tag -a "v$VERSION" -m "Pre-release v$VERSION" | |
| git push origin "v$VERSION" | |
| - name: Create GitHub Pre-release | |
| uses: softprops/action-gh-release@v2.4.1 | |
| with: | |
| tag_name: v${{ steps.version.outputs.version }} | |
| name: Pre-release v${{ steps.version.outputs.version }} | |
| body_path: CHANGELOG.txt | |
| draft: false | |
| prerelease: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Cleanup old pre-release tags (keep latest 3) | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "Fetching pre-release tags..." | |
| PRE_TAGS=$(git tag -l 'v*-dev.*' --sort=-version:refname) | |
| COUNT=0 | |
| for TAG in $PRE_TAGS; do | |
| COUNT=$((COUNT + 1)) | |
| if [ $COUNT -gt 3 ]; then | |
| echo "Deleting old pre-release: $TAG" | |
| gh release delete "$TAG" --yes --cleanup-tag 2>/dev/null || true | |
| git push origin --delete "$TAG" 2>/dev/null || true | |
| fi | |
| done | |
| echo "Kept latest 3 pre-releases, deleted $((COUNT > 3 ? COUNT - 3 : 0)) old ones" |