1
+ name : Fetch OpenAPI spec
2
+ on :
3
+ workflow_dispatch :
4
+ schedule :
5
+ - cron : ' 0 0 * * *'
6
+ jobs :
7
+ fetch :
8
+ name : Fetch pi OpenAPI spec
9
+ runs-on : ubuntu-latest
10
+ permissions :
11
+ contents : write
12
+ pull-requests : write
13
+ steps :
14
+ - name : Checkout this repo
15
+ uses : actions/checkout@v4
16
+ with :
17
+ ref : main
18
+ fetch-depth : 0
19
+
20
+ - name : fetch mediator OpenAPI spec
21
+ shell : bash
22
+ run : |
23
+ set -euo pipefail
24
+ gh api -H "Accept: application/vnd.github+json" \
25
+ -H "X-GitHub-Api-Version: 2022-11-28" \
26
+ /repos/stacklok/mediator/contents/pkg/api/openapi/mediator/v1/mediator.swagger.json | jq -r '.content' | base64 -d > src/openapi.json
27
+ env :
28
+ GH_TOKEN : ${{ secrets.REPO_READER_TOKEN }}
29
+
30
+ - name : Check if OpenAPI changed
31
+ id : check-openapi
32
+ run : |
33
+ if ! git diff --quiet src/openapi.json; then
34
+ echo "changed=true" >> "$GITHUB_OUTPUT"
35
+ else
36
+ echo "changed=false" >> "$GITHUB_OUTPUT"
37
+ fi
38
+
39
+ - name : Set Git config
40
+ run : |
41
+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
42
+ git config --global user.name "github-actions[bot]"
43
+
44
+ - name : Generate PR if needed
45
+ if : steps.check-openapi.outputs.changed == 'true'
46
+ run : |
47
+ git checkout -b update-openapi-$GITHUB_SHA
48
+
49
+ git add src/openapi.json
50
+ git commit -m "Update mediator OpenAPI to version generated from ref $GITHUB_SHA"
51
+
52
+ echo "Pushing branch so we can create a PR..."
53
+ git push --set-upstream origin update-openapi-$GITHUB_SHA
54
+
55
+ gh pr create --title "Update OpenAPI" \
56
+ --body "This PR updates the OpenAPI definition to the version generated from ref $GITHUB_SHA" \
57
+ --repo "$GITHUB_REPOSITORY" \
58
+ --base main \
59
+ --head update-openapi-$GITHUB_SHA
60
+ env :
61
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments