Merge pull request #76 from miloshb/cm #71
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: Production Pipeline | |
| on: | |
| push: | |
| branches: [ main, stage ] | |
| pull_request: | |
| branches: [ main, stage ] | |
| jobs: | |
| # JOB 1: Test and validate everything first | |
| validate: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22.14.0' | |
| cache: 'npm' | |
| - name: Install Dependencies | |
| run: npm ci | |
| - name: Compile Production Astro Build | |
| run: npm run build | |
| env: | |
| ASTRO_SITE: https://studiosunandsea.com | |
| - name: Assert Sitemap & Robots.txt Alignment | |
| run: | | |
| if [ ! -f ./dist/sitemap-index.xml ]; then | |
| echo "❌ ERROR: sitemap-index.xml missing!" | |
| exit 1 | |
| fi | |
| if ! grep -q "Sitemap: https://studiosunandsea.com" ./dist/robots.txt; then | |
| echo "❌ ERROR: robots.txt missing sitemap reference!" | |
| exit 1 | |
| fi | |
| - name: Run Dynamic Sitemap URL Validation | |
| run: npm run test:sitemap | |
| - name: Scan Entire Site for Broken Internal Links | |
| # start-server-and-test securely spins up the http-server, runs linkinator, catches real errors, and terminates gracefully on runner crash or test completion | |
| run: npm run test:links | |
| # LIVE EDGE REDIRECT RUNNER: Executes exclusively on production merge environments | |
| - name: Install Playwright Browsers (Production Only) | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| run: npx playwright install --with-deps chromium | |
| - name: Execute Live Edge Domain Redirect Checks (Production Only) | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| run: npm run test:redirects | |
| # JOB 2: Only run version bumping if the validation job passes AND it's the stage branch | |
| bump-version: | |
| runs-on: ubuntu-latest | |
| needs: validate | |
| # Only bump version when code lands on stage | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/stage' | |
| permissions: | |
| contents: write # Crucial for the bot to push commits/tags | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Required to see commit history cleanly | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22.14.0' | |
| cache: 'npm' | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| # This reads the commit message. If it contains [major] or [minor], it bumps accordingly. | |
| # Otherwise, it defaults to a standard patch bump (e.g. 0.0.2 -> 0.0.3). | |
| - name: Evaluate Commits & Bump Version | |
| run: | | |
| # Grabs the latest commit message from the incoming branch | |
| COMMIT_MSG=$(git log -1 --pretty=%B) | |
| # Prevent infinite loop if the last commit was already a version bump | |
| if [[ "$COMMIT_MSG" == *"chore: bump version"* ]]; then | |
| echo "Already a version bump commit. Exiting gracefully." | |
| exit 0 | |
| fi | |
| if [[ "$COMMIT_MSG" == *"[major]"* ]]; then | |
| npm version major -m "chore: bump version to %s [skip ci]" | |
| elif [[ "$COMMIT_MSG" == *"[minor]"* ]]; then | |
| npm version minor -m "chore: bump version to %s [skip ci]" | |
| else | |
| npm version patch -m "chore: bump version to %s [skip ci]" | |
| fi | |
| - name: Push Version Update and Tags to Stage | |
| run: | | |
| # The '-o ci.skip' option tells GitHub's server to completely ignore branch rules regarding PR requirements for this specific automated push | |
| git push origin stage --follow-tags -o ci.skip |