1
0
Fork 0
mirror of https://github.com/imjasonh/apidiff-action synced 2026-07-06 22:52:43 +00:00
apidiff-action/.github/workflows/ci.yml
Jason Hall 422a3478df
fix: improve dist update messaging and ensure proper CI flow
- Add clear message when dist is auto-updated
- Exit with code 1 to prevent auto-merge of out-of-date dist
- This ensures the PR must pass CI again after dist update
2025-07-30 11:01:34 -04:00

188 lines
6.4 KiB
YAML

name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: write
pull-requests: write
jobs:
check-dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Use a token that can push for PR events from same repo
token: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && secrets.GITHUB_TOKEN || github.token }}
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }}
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm
- run: npm ci
- run: npm run build
- id: check-changes
run: |
if [ -n "$(git status --porcelain dist/)" ]; then
echo "changes=true" >> "$GITHUB_OUTPUT"
else
echo "changes=false" >> "$GITHUB_OUTPUT"
fi
# For push events, just fail if out of date
- name: Fail if dist is out of date (push)
if: github.event_name == 'push' && steps.check-changes.outputs.changes == 'true'
run: |
echo "Detected uncommitted changes after build. See diff below:"
git diff --ignore-space-at-eol --text dist/
echo ""
echo "Please run 'npm run build' locally and commit the changes."
exit 1
# For PRs from same repo, update automatically
- name: Update dist (PR)
if: |
github.event_name == 'pull_request' &&
steps.check-changes.outputs.changes == 'true' &&
github.event.pull_request.head.repo.full_name == github.repository
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add dist/
git commit -m "chore: update dist" --no-verify
git push
echo ""
echo "✅ Updated dist/ directory. The check-dist job will pass on the next CI run."
echo ""
exit 1 # Fail to prevent auto-merge of out-of-date dist
# For PRs from forks, fail with instructions
- name: Fail if dist is out of date (fork PR)
if: |
github.event_name == 'pull_request' &&
steps.check-changes.outputs.changes == 'true' &&
github.event.pull_request.head.repo.full_name != github.repository
run: |
echo "Detected uncommitted changes after build. See diff below:"
git diff --ignore-space-at-eol --text dist/
echo ""
echo "This PR is from a fork. Please run 'npm run build' locally and commit the changes."
exit 1
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- uses: pre-commit/action@v3.0.1
# Test the action itself
test-action:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 'stable'
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: |
npm ci
npm run build
# Test with breaking changes (should detect them)
- name: Test with breaking changes
uses: ./
id: test-breaking
with:
working-directory: testdata/break
fail-on-breaking: false
comment-on-pr: false
env:
INPUT_OLD: old
INPUT_NEW: new
- name: Verify breaking changes detected
run: |
if [ "${{ steps.test-breaking.outputs.has-breaking-changes }}" != "true" ]; then
echo "Expected breaking changes to be detected"
exit 1
fi
echo "Breaking changes detected: ${{ steps.test-breaking.outputs.breaking-count }}"
echo "Compatible changes: ${{ steps.test-breaking.outputs.compatible-count }}"
# Verify counts match what we expect
if [ "${{ steps.test-breaking.outputs.breaking-count }}" != "3" ]; then
echo "Expected 3 breaking changes, got ${{ steps.test-breaking.outputs.breaking-count }}"
exit 1
fi
if [ "${{ steps.test-breaking.outputs.compatible-count }}" != "1" ]; then
echo "Expected 1 compatible change, got ${{ steps.test-breaking.outputs.compatible-count }}"
exit 1
fi
# Test with safe changes (should not detect breaking changes)
- name: Test with safe changes
uses: ./
id: test-safe
with:
working-directory: testdata/safe
fail-on-breaking: true
comment-on-pr: false
env:
INPUT_OLD: old
INPUT_NEW: new
- name: Verify no breaking changes in safe test
run: |
if [ "${{ steps.test-safe.outputs.has-breaking-changes }}" != "false" ]; then
echo "Expected no breaking changes in safe test"
exit 1
fi
echo "Compatible changes: ${{ steps.test-safe.outputs.compatible-count }}"
# Verify count matches what we expect
if [ "${{ steps.test-safe.outputs.compatible-count }}" != "3" ]; then
echo "Expected 3 compatible changes, got ${{ steps.test-safe.outputs.compatible-count }}"
exit 1
fi
# Test with clean changes (no API changes)
- name: Test with clean changes
uses: ./
id: test-clean
with:
working-directory: testdata/clean
fail-on-breaking: true
comment-on-pr: false
env:
INPUT_OLD: old
INPUT_NEW: new
- name: Verify no changes in clean test
run: |
if [ "${{ steps.test-clean.outputs.has-breaking-changes }}" != "false" ]; then
echo "Expected no breaking changes in clean test"
exit 1
fi
if [ "${{ steps.test-clean.outputs.breaking-count }}" != "0" ]; then
echo "Expected 0 breaking changes, got ${{ steps.test-clean.outputs.breaking-count }}"
exit 1
fi
if [ "${{ steps.test-clean.outputs.compatible-count }}" != "0" ]; then
echo "Expected 0 compatible changes, got ${{ steps.test-clean.outputs.compatible-count }}"
exit 1
fi