Skip to content

Feature/show advisories on site #23

Feature/show advisories on site

Feature/show advisories on site #23

Workflow file for this run

name: API Specification
on:
pull_request:
paths:
- "src/**/*.php"
- "config/**"
- "composer.json"
- "composer.lock"
- "public/api-spec-v1.yaml"
- "public/api-spec-v1.json"
- "docker-compose.yml"
env:
COMPOSE_USER: runner
jobs:
api-spec-export:
name: Ensure API specification is up to date
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Create docker network
run: docker network create frontend
# https://taskfile.dev/installation/#github-actions
- uses: go-task/setup-task@v1
- name: Export API specification
run: |
task site:update
task api:spec:export
- name: Check for uncommitted changes
id: git-diff-spec
continue-on-error: true
run: |
git diff --diff-filter=ACMRT --exit-code public/api-spec-v1.yaml public/api-spec-v1.json
- name: Comment PR if spec is outdated
if: steps.git-diff-spec.outcome == 'failure'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr comment ${{ github.event.pull_request.number }} \
--body "$(cat <<'EOF'
## API specification not up to date
The committed API specification files do not match the exported output.
Please run the following command, then commit and push the changes:
```shell
docker compose exec phpfpm composer update-api-spec
```
EOF
)" \
--create-if-none --edit-last
- name: Fail if spec is outdated
if: steps.git-diff-spec.outcome == 'failure'
run: exit 1
api-spec-breaking-changes:
name: Detect breaking changes in API specification
runs-on: ubuntu-latest
needs: [api-spec-export]
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Fetch base branch for comparison
run: git fetch --depth=1 origin ${{ github.base_ref }}
- name: Detect breaking changes
id: breaking
continue-on-error: true
uses: oasdiff/oasdiff-action/breaking@main
with:
base: "origin/${{ github.base_ref }}:public/api-spec-v1.yaml"
revision: "public/api-spec-v1.yaml"
fail-on: ERR
- name: Generate changelog
id: changelog
continue-on-error: true
uses: oasdiff/oasdiff-action/changelog@main
with:
base: "origin/${{ github.base_ref }}:public/api-spec-v1.yaml"
revision: "public/api-spec-v1.yaml"
format: markdown
output-to-file: changelog.md
- name: Comment PR - no changes
if: steps.breaking.outcome == 'success' && hashFiles('changelog.md') == ''
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr comment ${{ github.event.pull_request.number }} \
--body "## API Specification
No changes detected in API specification." \
--create-if-none --edit-last
- name: Comment PR - non-breaking changes
if: steps.breaking.outcome == 'success' && hashFiles('changelog.md') != ''
env:
GH_TOKEN: ${{ github.token }}
run: |
{
echo "## API Specification - Non-breaking changes"
echo ""
cat changelog.md
} > comment.md
gh pr comment ${{ github.event.pull_request.number }} \
--body-file comment.md \
--create-if-none --edit-last
- name: Comment PR - breaking changes
if: steps.breaking.outcome == 'failure'
env:
GH_TOKEN: ${{ github.token }}
run: |
{
echo "## API Specification - Breaking changes detected"
echo ""
if [ -s changelog.md ]; then
cat changelog.md
else
echo "The breaking changes action detected incompatible changes. Review the action logs for details."
fi
} > comment.md
gh pr comment ${{ github.event.pull_request.number }} \
--body-file comment.md \
--create-if-none --edit-last
- name: Fail if breaking changes detected
if: steps.breaking.outcome == 'failure'
run: exit 1