-
-
Notifications
You must be signed in to change notification settings - Fork 230
107 lines (88 loc) · 2.81 KB
/
api-schema.yml
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
name: API schema
on:
workflow_dispatch:
push:
branches: [main]
paths:
- .github/workflows/api-schema.yml
- api/**
pull_request:
branches: [main]
paths:
- .github/workflows/api-schema.yml
- api/**
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-api-${{ hashFiles('api/**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-api
- name: Install
run: make install
working-directory: api
- name: Get pull request commit range
if: github.event_name == 'pull_request'
run: echo "COMMIT_RANGE=origin/${{ github.base_ref }}..${{ github.sha }}" >> $GITHUB_ENV
- name: Get push commit range
if: github.event_name == 'push'
run: echo "COMMIT_RANGE=${{ github.event.before }}..${{ github.sha }}" >> $GITHUB_ENV
- name: Check if schema is outdated
run: |
for commit in $(git rev-list --reverse --no-merges ${{ env.COMMIT_RANGE }}); do
git checkout $commit
make --quiet schema
git diff -- schema.yml
git add schema.yml
git diff-index --quiet HEAD -- || {
echo "ERROR: Schema is outdated for commit $commit"
git show --quiet
exit 1
}
done
working-directory: api
dispatch:
if: >
github.repository_owner == 'libretime'
&& github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/checkout@v4
with:
repository: libretime/client
path: client
ssh-key: "${{ secrets.API_CLIENT_DEPLOY_KEY }}"
- name: Dispatch schema update commits
run: |
git config --global user.name "libretime-bot"
git config --global user.email "[email protected]"
for commit in $(git rev-list --reverse --no-merges ${{ github.event.before }}..${{ github.sha }} -- api/schema.yml); do
cp api/schema.yml client/
git show \
--quiet \
--format="%B%n${{ github.repository }}@%H" \
"$commit" \
> commit-message
pushd client/
git add schema.yml
git diff-index --quiet HEAD -- || {
git commit --file=../commit-message
git push
}
popd
rm commit-message
done