diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8c86d8e..75d5a61 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,43 +1,52 @@ name: Release -# Trigger on version tags (v*.*.*) +# Every merge to main that passes the Tests workflow is released โ no tag to +# push by hand. The release reuses that run as its gate rather than repeating +# it: the same hygiene, lint, typecheck, unit, build, bundle-floor, Playwright +# and WebKit checks, on the same commit (R9-05). The version is decided by +# scripts/release-version.js from the merged PRs' labels and titles; see +# docs/Release-Process.md for the rules. on: - push: - tags: - - 'v*.*.*' + workflow_run: + workflows: [Tests] + types: [completed] + branches: [main] + # A manual release from main's tip, optionally forcing the bump. + workflow_dispatch: + inputs: + bump: + description: 'Version bump (auto reads the merged PRs)' + type: choice + options: [auto, patch, minor, major] + default: auto -# Permissions required for creating releases permissions: contents: write + pull-requests: read + +# One release at a time, never cancelled midway. GitHub keeps only the newest +# pending run, which is the one that should release. +concurrency: + group: release + cancel-in-progress: false jobs: release: + if: >- + github.event_name == 'workflow_dispatch' || + (github.event.workflow_run.conclusion == 'success' && + github.event.workflow_run.event == 'push') runs-on: ubuntu-latest - + env: + SHA: ${{ github.event.workflow_run.head_sha || github.sha }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: - - name: Checkout code + - name: Checkout the tested commit uses: actions/checkout@v4 with: - fetch-depth: 0 # Fetch all history for changelog generation - - - name: Validate tag format - id: validate-tag - run: | - TAG=${GITHUB_REF#refs/tags/} - echo "Tag: $TAG" - - # Validate semantic versioning format (v*.*.*) - if [[ ! $TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "โ Invalid tag format. Expected format: v*.*.* (e.g., v1.0.0)" - echo "Received: $TAG" - exit 1 - fi - - # Extract version without 'v' prefix - VERSION=${TAG#v} - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "tag=$TAG" >> $GITHUB_OUTPUT - echo "โ Tag format validated: $TAG (version: $VERSION)" + ref: ${{ env.SHA }} + fetch-depth: 0 # every tag and commit since the last release - name: Setup Node.js uses: actions/setup-node@v4 @@ -45,139 +54,122 @@ jobs: node-version: '24' cache: 'yarn' - - name: Install dependencies - run: | - echo "๐ฆ Installing dependencies..." - yarn install --frozen-lockfile - - - name: Install Playwright browsers - run: | - echo "๐ญ Installing Playwright browsers..." - yarn playwright install - - # The release gate must be at least as strict as the PR gate (R9-05). - # It used to run typecheck, build and Playwright but neither `yarn lint` - # nor `yarn hygiene`, so a release cut from a branch that never went - # through a PR could ship a lint or ratchet regression. These are the - # same five checks `test.yml` runs, in the same order. - - name: Hygiene ratchet (cycles, unused exports, waitForTimeout) - run: | - echo "๐ Running hygiene ratchet..." - yarn hygiene - - - name: Lint - run: | - echo "๐งน Running lint..." - yarn lint - - - name: Run type checking + # If main has moved on, a newer Tests run will release this commit along + # with what followed it; releasing here would tag a commit that is no + # longer main's tip. + - name: Check this commit is still main's tip + id: tip run: | - echo "๐ Running type checking..." - yarn typecheck - - - name: Unit tests - run: | - echo "๐ฌ Running unit tests..." - yarn test:unit + git fetch origin main + TIP=$(git rev-parse origin/main) + if [ "$TIP" != "$SHA" ]; then + echo "superseded=true" >> "$GITHUB_OUTPUT" + echo "โญ๏ธ main has moved on to $TIP; that commit's run will release." + elif git tag --points-at "$SHA" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then + echo "superseded=true" >> "$GITHUB_OUTPUT" + echo "โญ๏ธ $SHA is already released." + else + echo "superseded=false" >> "$GITHUB_OUTPUT" + fi - - name: Check the tag matches package.json + - name: Decide the version + id: decide + if: steps.tip.outputs.superseded == 'false' run: | - PACKAGE_VERSION=$(node -p "require('./package.json').version") - TAG_VERSION="${{ steps.validate-tag.outputs.version }}" - - if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then - echo "โ Version mismatch: package.json has '$PACKAGE_VERSION', tag expects '$TAG_VERSION'" + node scripts/release-evidence.js "$SHA" "${{ inputs.bump || 'auto' }}" > evidence.json + node scripts/release-version.js evidence.json > decision.json + cat decision.json + RELEASE=$(node -p "require('./decision.json').release") + VERSION=$(node -p "require('./decision.json').version") + REASON=$(node -p "require('./decision.json').reason") + echo "release=$RELEASE" >> "$GITHUB_OUTPUT" + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "tag=v$VERSION" >> "$GITHUB_OUTPUT" + { + echo "### Release decision" + if [ "$RELEASE" = "true" ]; then echo "**v$VERSION** โ $REASON"; else echo "No release โ $REASON"; fi + } >> "$GITHUB_STEP_SUMMARY" + if [ "$RELEASE" = "true" ] && git rev-parse -q --verify "refs/tags/v$VERSION" >/dev/null; then + echo "โ Tag v$VERSION already exists" exit 1 fi - echo "โ package.json version matches the tag: $PACKAGE_VERSION" + - name: Set the version in package.json + if: steps.decide.outputs.release == 'true' + run: npm version "${{ steps.decide.outputs.version }}" --no-git-tag-version --allow-same-version + + - name: Install dependencies + if: steps.decide.outputs.release == 'true' + run: yarn install --frozen-lockfile - name: Build standalone version + if: steps.decide.outputs.release == 'true' run: | - echo "๐๏ธ Building standalone version for file:// protocol compatibility..." yarn build:standalone - - # Verify standalone bundle exists + if [ ! -f "dist/gramframe.bundle.js" ]; then echo "โ Standalone build failed: gramframe.bundle.js not found" exit 1 fi - - # Check bundle size (should be substantial due to inlined CSS/assets) - BUNDLE_SIZE=$(stat -c%s "dist/gramframe.bundle.js" 2>/dev/null || stat -f%z "dist/gramframe.bundle.js") + + BUNDLE_SIZE=$(stat -c%s "dist/gramframe.bundle.js") if [ "$BUNDLE_SIZE" -lt 100000 ]; then echo "โ Standalone bundle too small ($BUNDLE_SIZE bytes), likely incomplete" exit 1 fi - - # The version is injected into the bundle at build time (no tracked - # file is rewritten), so verify it landed in the shipped artifact. - PACKAGE_VERSION=$(node -p "require('./package.json').version") - if ! grep -q "\"$PACKAGE_VERSION\"" dist/gramframe.bundle.js; then - echo "โ Bundle does not carry version $PACKAGE_VERSION" + + # The version is injected at build time; check it reached the artifact. + if ! grep -q "\"${{ steps.decide.outputs.version }}\"" dist/gramframe.bundle.js; then + echo "โ Bundle does not carry version ${{ steps.decide.outputs.version }}" exit 1 fi + echo "โ Bundle: $BUNDLE_SIZE bytes" - echo "โ Standalone build successful" - echo "๐ Bundle size: $BUNDLE_SIZE bytes" - echo "๐ Standalone build contents:" - ls -la dist/ - - # The shipped artifact must parse on the floor the runtime guard - # advertises; a parse error kills the IIFE before the guard runs (R9-06). + # Tests checked this already; repeated because the bundle was rebuilt + # with the new version, and it costs a second. - name: Assert the bundle stays within the advertised browser floor - run: | - echo "๐ Checking the bundle's syntax floor..." - yarn check:bundle-floor - - - name: Run tests - run: | - echo "๐งช Running tests..." - yarn test + if: steps.decide.outputs.release == 'true' + run: yarn check:bundle-floor - name: Prepare release assets id: assets + if: steps.decide.outputs.release == 'true' + env: + VERSION: ${{ steps.decide.outputs.version }} + TAG: ${{ steps.decide.outputs.tag }} run: | - echo "๐ฆ Preparing release assets..." - - # Create release directory mkdir -p release-assets - - # Copy standalone bundle (the only build users need) cp dist/gramframe.bundle.js release-assets/ - - # Copy test HTML file and required assets. The demo gram is a - # small synthetic spectrogram committed at sample/demo-gram.png, - # not one of the large photographic sample images. + # The demo gram is a small synthetic spectrogram committed at + # sample/demo-gram.png, not one of the large photographic samples. cp test-release.html release-assets/index.html cp sample/demo-gram.png release-assets/ - - # Create simple verification file - cat > release-assets/README.md << 'EOF' + + cat > release-assets/README.md << EOF # GramFrame Release - + ## Quick Start - - 1. **Double-click `index.html`** from your file explorer + + 1. **Double-click \`index.html\`** from your file explorer 2. The component will load automatically - no web server required! 3. Test all interactions with the spectrogram - + ## Files Included - - - **`gramframe.bundle.js`** - Complete GramFrame component (file:// compatible) - - **`index.html`** - Sample HTML page demonstrating usage - - **`demo-gram.png`** - Synthetic demo spectrogram (harmonic stack, sidebands, Doppler curve) - - **`README.md`** - This guide - + + - **\`gramframe.bundle.js\`** - Complete GramFrame component (file:// compatible) + - **\`index.html\`** - Sample HTML page demonstrating usage + - **\`demo-gram.png\`** - Synthetic demo spectrogram (harmonic stack, sidebands, Doppler curve) + - **\`README.md\`** - This guide + ## How to Use in Your Training Materials - - 1. Include `gramframe.bundle.js` in your HTML training materials - 2. Add spectrogram configuration tables with class `gram-config` + + 1. Include \`gramframe.bundle.js\` in your HTML training materials + 2. Add spectrogram configuration tables with class \`gram-config\` 3. Component auto-initializes when the page loads - + ### Example HTML Structure - - ```html + + \`\`\`html
@@ -185,8 +177,7 @@ jobs:![]() |
@@ -196,156 +187,108 @@ jobs:
|
| freq-start | 0 |
| freq-end | 100 |