-
Notifications
You must be signed in to change notification settings - Fork 3
143 lines (122 loc) · 5.01 KB
/
api-spec.yaml
File metadata and controls
143 lines (122 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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