Repository navigation
49 lines (44 loc) · 1.81 KB
/
Copy pathapi-spec-sync.yml
File metadata and controls
49 lines (44 loc) · 1.81 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
# Keeps openapi/v1/openapi.yaml in step with the Platform API.
# Runs daily, on demand, or when the API repository sends an "openapi-updated" dispatch.
# If the spec changed it opens a pull request; CI on that PR runs the API coverage check, so a
# removed or renamed endpoint the app uses blocks the merge until the app follows.
name: API spec sync
on:
schedule:
- cron: "17 6 * * *"
workflow_dispatch:
repository_dispatch:
types: [openapi-updated]
permissions:
contents: write
pull-requests: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Fetch the API's openapi.yaml
id: fetch
run: |
api_repo=CompositeCode/substratalapps.com
commit=$(gh api "repos/$api_repo/commits/main" --jq .sha)
gh api "repos/$api_repo/contents/docs/openapi.yaml?ref=$commit" -H "Accept: application/vnd.github.raw" > /tmp/openapi.yaml
if cmp -s /tmp/openapi.yaml openapi/v1/openapi.yaml; then
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
python3 scripts/sync_openapi.py /tmp/openapi.yaml "$commit" > /tmp/summary.md
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "spec_version=$(grep -m1 '^spec_version' openapi/v1/SOURCE.yaml | cut -d'"' -f2)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ github.token }}
- name: Open a pull request
if: steps.fetch.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v8
with:
branch: api-spec-sync
delete-branch: true
commit-message: "Sync openapi.yaml ${{ steps.fetch.outputs.spec_version }} from the Platform API"
title: "Sync API spec ${{ steps.fetch.outputs.spec_version }}"
body-path: /tmp/summary.md
labels: api-spec