name: Release on: # Trigger after CI passes on main branch (normal path) workflow_run: workflows: ["CI"] types: [completed] branches: [main] # Manual fallback for when CI's event routing is stuck. Still gated on the # main branch via the job-level `if:` so accidental dispatches from feature # branches don't publish. workflow_dispatch: jobs: release: name: Semantic Release runs-on: [self-hosted, linux, x64, llmist-release] environment: release # Run on (a) the normal workflow_run path after CI passes on main, or # (b) an explicit manual dispatch — but only when dispatched FROM main, # so an accidental "Run workflow" from a feature branch can't publish. if: | (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') permissions: contents: write issues: write pull-requests: write outputs: released: ${{ steps.semantic.outputs.released == 'true' }} version: ${{ steps.semantic.outputs.version }} steps: - name: Checkout repository uses: actions/checkout@v4 with: # Fetch full history for semantic-release to analyze all commits fetch-depth: 0 # Use PAT for authenticated pushes (allows triggering workflows and bypassing branch protection) token: ${{ secrets.GH_PAT }} # Always checkout main branch for releases (workflow only triggers on main CI) ref: main - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '22' registry-url: 'https://registry.npmjs.org' cache: 'npm' - name: Install npm 10.9.2 run: | npm install --global npm@10.9.2 node --version npm --version node -e "require('node:assert/strict').equal(process.versions.node.split('.')[0], '22')" test "$(npm --version)" = "10.9.2" - name: Install dependencies run: npm ci - name: Build package run: npm run build - name: Configure git run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git config core.hooksPath /dev/null - name: Run semantic-release id: semantic env: GITHUB_TOKEN: ${{ secrets.GH_PAT }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: | # Force GITHUB_REF to main for semantic-release branch detection # (workflow_run events incorrectly set GITHUB_REF from triggering workflow) export GITHUB_REF=refs/heads/main BEFORE_SHA=$(git rev-parse HEAD) # Run semantic-release (publishes llmist package to npm) # The @semantic-release/exec plugin runs sync-versions.js to sync all package versions npx semantic-release || RELEASE_EXIT_CODE=$? AFTER_SHA=$(git rev-parse HEAD) # Check if a release commit was made (HEAD changed) if [ "$BEFORE_SHA" != "$AFTER_SHA" ]; then echo "released=true" >> $GITHUB_OUTPUT # Extract version from the release commit VERSION=$(node -p "require('./packages/llmist/package.json').version") echo "version=$VERSION" >> $GITHUB_OUTPUT echo "✅ Release $VERSION created" else echo "released=false" >> $GITHUB_OUTPUT echo "ℹ️ No release commit - skipping publish" fi # Exit with the original exit code if semantic-release failed exit ${RELEASE_EXIT_CODE:-0} - name: Publish @llmist/cli to npm if: steps.semantic.outputs.released == 'true' env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: | echo "Publishing @llmist/cli@${{ steps.semantic.outputs.version }}..." # Rebuild CLI to include correct version (was built before version sync) cd packages/cli npm run build npm publish --access public - name: Publish @llmist/testing to npm if: steps.semantic.outputs.released == 'true' env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: | echo "Publishing @llmist/testing@${{ steps.semantic.outputs.version }}..." # Rebuild testing to include correct version (was built before version sync) cd packages/testing npm run build npm publish --access public # Sync dev branch after any successful CI on main sync-dev: name: Sync dev branch runs-on: [self-hosted, linux, x64, llmist-release] environment: release needs: release if: always() && needs.release.result == 'success' steps: - uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.GH_PAT }} - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "22" - name: Install npm 10.9.2 run: | npm install --global npm@10.9.2 node --version npm --version node -e "require('node:assert/strict').equal(process.versions.node.split('.')[0], '22')" test "$(npm --version)" = "10.9.2" - name: Sync dev with main run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git fetch origin git checkout dev # Fast-forward if possible, otherwise merge if git merge origin/main --ff-only; then echo "✅ Fast-forwarded dev to main" else echo "⚠️ Cannot fast-forward, creating merge commit..." git merge origin/main --no-edit -m "chore: sync dev with main [skip ci]" fi git push origin dev echo "✅ Sync complete"