2022-04-08 16:07:01 +02:00
|
|
|
name: API schema
|
2022-04-08 15:38:58 +02:00
|
|
|
|
|
|
|
on:
|
2023-02-27 12:34:17 +01:00
|
|
|
workflow_dispatch:
|
2022-04-08 15:38:58 +02:00
|
|
|
push:
|
|
|
|
branches: [main]
|
2022-06-17 17:07:44 +02:00
|
|
|
paths:
|
2022-09-14 13:45:26 +02:00
|
|
|
- .github/workflows/api-schema.yml
|
2022-06-17 17:07:44 +02:00
|
|
|
- api/**
|
|
|
|
|
|
|
|
pull_request:
|
|
|
|
branches: [main]
|
|
|
|
paths:
|
2022-09-14 13:45:26 +02:00
|
|
|
- .github/workflows/api-schema.yml
|
2022-06-17 17:07:44 +02:00
|
|
|
- api/**
|
2022-04-08 15:38:58 +02:00
|
|
|
|
|
|
|
concurrency:
|
|
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
|
|
|
|
|
|
jobs:
|
2022-06-17 17:07:44 +02:00
|
|
|
check:
|
2022-04-08 15:38:58 +02:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2023-10-21 21:30:18 +02:00
|
|
|
- uses: actions/checkout@v4
|
2022-06-17 17:07:44 +02:00
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
|
|
|
|
2023-12-20 05:08:55 +01:00
|
|
|
- uses: actions/setup-python@v5
|
2022-06-09 09:50:36 +02:00
|
|
|
with:
|
|
|
|
python-version: "3.x"
|
2022-04-08 15:54:00 +02:00
|
|
|
|
2022-06-17 17:07:44 +02:00
|
|
|
- uses: actions/cache@v3
|
2022-04-08 15:38:58 +02:00
|
|
|
with:
|
2022-06-17 17:07:44 +02:00
|
|
|
path: ~/.cache/pip
|
|
|
|
key: ${{ runner.os }}-pip-api-${{ hashFiles('api/**/setup.py') }}
|
|
|
|
restore-keys: |
|
|
|
|
${{ runner.os }}-pip-api
|
2022-04-08 15:54:00 +02:00
|
|
|
|
2022-06-17 17:07:44 +02:00
|
|
|
- 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
|
2022-04-08 15:38:58 +02:00
|
|
|
run: |
|
2022-06-17 17:07:44 +02:00
|
|
|
for commit in $(git rev-list --reverse --no-merges ${{ env.COMMIT_RANGE }}); do
|
|
|
|
git checkout $commit
|
|
|
|
|
|
|
|
make --quiet schema
|
2023-02-10 23:26:11 +01:00
|
|
|
git diff -- schema.yml
|
2022-06-17 17:07:44 +02:00
|
|
|
git add schema.yml
|
|
|
|
git diff-index --quiet HEAD -- || {
|
|
|
|
echo "ERROR: Schema is outdated for commit $commit"
|
|
|
|
git show --quiet
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
done
|
2022-04-08 15:38:58 +02:00
|
|
|
working-directory: api
|
2022-04-08 15:54:00 +02:00
|
|
|
|
2022-06-17 17:07:44 +02:00
|
|
|
dispatch:
|
|
|
|
if: >
|
|
|
|
github.repository_owner == 'libretime'
|
|
|
|
&& github.event_name == 'push'
|
|
|
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2023-10-21 21:30:18 +02:00
|
|
|
- uses: actions/checkout@v4
|
2022-06-17 17:07:44 +02:00
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
|
|
|
|
2023-10-21 21:30:18 +02:00
|
|
|
- uses: actions/checkout@v4
|
2022-04-08 15:38:58 +02:00
|
|
|
with:
|
2022-06-17 17:07:44 +02:00
|
|
|
repository: libretime/client
|
|
|
|
path: client
|
|
|
|
ssh-key: "${{ secrets.API_CLIENT_DEPLOY_KEY }}"
|
|
|
|
|
|
|
|
- name: Dispatch schema update commits
|
|
|
|
run: |
|
2022-06-22 19:33:53 +02:00
|
|
|
git config --global user.name "libretime-bot"
|
|
|
|
git config --global user.email "libretime-bot@users.noreply.github.com"
|
2022-06-17 17:07:44 +02:00
|
|
|
|
|
|
|
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
|