-
Notifications
You must be signed in to change notification settings - Fork 179
142 lines (138 loc) · 6.07 KB
/
Copy pathupdate-api-schema.yml
File metadata and controls
142 lines (138 loc) · 6.07 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
name: update-api-schema
on:
pull_request:
paths:
- 'src/ai/backend/manager/models/**'
- 'src/ai/backend/manager/api/**'
- 'VERSION'
jobs:
api-updated:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Calculate the fetch depth
run: |
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
echo "GIT_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
else
echo "GIT_FETCH_DEPTH=2" >> "${GITHUB_ENV}"
fi
- name: Checkout the revision with minimal required history
uses: actions/checkout@v6
with:
fetch-depth: ${{ env.GIT_FETCH_DEPTH }}
ref: ${{ github.head_ref }}
token: ${{ secrets.OCTODOG }}
lfs: false
- name: Extract Python version from pants.toml
run: |
PYTHON_VERSION=$(grep -m 1 -oP '(?<=CPython==)([^"]+)' pants.toml)
echo "PANTS_CONFIG_FILES=pants.ci.toml" >> $GITHUB_ENV
echo "PROJECT_PYTHON_VERSION=$PYTHON_VERSION" >> $GITHUB_ENV
- name: Set up Python as Runtime
uses: actions/setup-python@v6
with:
python-version: ${{ env.PROJECT_PYTHON_VERSION }}
- name: Set up remote cache backend (if applicable)
run: |
echo "PANTS_REMOTE_STORE_ADDRESS=${REMOTE_CACHE_BACKEND_ENDPOINT}" >> $GITHUB_ENV
echo "PANTS_REMOTE_CACHE_READ=true" >> $GITHUB_ENV
echo "PANTS_REMOTE_CACHE_WRITE=true" >> $GITHUB_ENV
echo "PANTS_REMOTE_INSTANCE_NAME=main" >> $GITHUB_ENV
env:
REMOTE_CACHE_BACKEND_ENDPOINT: ${{ secrets.PANTS_REMOTE_CACHE_ENDPOINT_ARC }}
if: ${{ env.REMOTE_CACHE_BACKEND_ENDPOINT != '' }}
- name: Bootstrap Pants
uses: pantsbuild/actions/init-pants@v11
# See: github.com/pantsbuild/actions/tree/main/init-pants/
# ref) https://github.com/pantsbuild/example-python/blob/main/.github/workflows/pants.yaml#L30-L49
with:
gha-cache-key: v1
named-caches-hash: ${{ hashFiles('python*.lock', 'tools/*.lock') }}
# ``pants export`` fails when a stale PEX from the pex->uv lockfile
# migration is restored from the lmdb_store cache; disable it here
# (the build-* export jobs already do).
cache-lmdb-store: 'false'
- name: Pants export
run: pants export --resolve=python-default
- name: Install Rover CLI for generating supergraph
run: |
curl -sSL https://rover.apollo.dev/nix/latest | sh
echo "$HOME/.rover/bin" >> $GITHUB_PATH
- name: Create api schema dump
env:
APOLLO_ELV2_LICENSE: accept
run: |
./backend.ai mgr api dump-gql-schema --output docs/manager/graphql-reference/schema.graphql
./backend.ai mgr api dump-gql-schema --v2 --output docs/manager/graphql-reference/v2-schema.graphql
./backend.ai mgr api dump-gql-schema --public --output docs/manager/graphql-reference/v2-public-schema.graphql
./backend.ai mgr api generate-supergraph --config configs/graphql/supergraph.yaml -o docs/manager/graphql-reference
./backend.ai mgr api dump-openapi --output docs/manager/rest-reference/openapi.json
- name: Make commit message for changing change log file
run: |
git add docs/manager/graphql-reference/schema.graphql
git add docs/manager/graphql-reference/v2-schema.graphql
git add docs/manager/graphql-reference/v2-public-schema.graphql
git add docs/manager/graphql-reference/supergraph.graphql
git add docs/manager/rest-reference/openapi.json
author_name=$(git show -q --pretty='format:%an')
author_email=$(git show -q --pretty='format:%ae')
git config user.email "$author_email"
git config user.name "$author_name"
if [ -n "$(git diff --staged)" ]; then
git commit \
-m "chore: update api schema dump" \
--author="$author_name <$author_email>" \
--trailer "Co-authored-by: octodog <mu001@lablup.com>"
git push
fi
graphql-inspector:
needs: api-updated
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
checks: write
steps:
- uses: actions/checkout@v6
- uses: graphql-hive/graphql-inspector@v4.0.0
with:
schema: '${{ github.base_ref }}:docs/manager/graphql-reference/supergraph.graphql'
rules: |
gql-inspector-checker.js
# A version branch inherits NEXT_RELEASE_VERSION from the cut PR, where it already
# points at the *next* version -- one this branch never releases. New references
# added here must therefore spell out the version this branch will actually ship.
version-branch-added-version:
if: ${{ github.base_ref != 'main' }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- name: Reject NEXT_RELEASE_VERSION added on a version branch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_REF: ${{ github.base_ref }}
PR_FILES_API: repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files
run: |
if [[ ! "$BASE_REF" =~ ^[0-9]{2}\.[0-9]{1,2}$ ]]; then
echo "'$BASE_REF' is not a version branch (YY.S); nothing to check."
exit 0
fi
added=$(gh api --paginate "$PR_FILES_API" --jq '
.[] | select(.patch != null) | .filename as $file
| .patch | split("\n")[]
| select(startswith("+") and (startswith("+++") | not))
| select(test("NEXT_RELEASE_VERSION"))
| "\($file): \(.[1:])"
')
if [ -z "$added" ]; then
echo "No newly added NEXT_RELEASE_VERSION reference."
exit 0
fi
echo "Newly added NEXT_RELEASE_VERSION references:"
echo "$added"
echo "::error::NEXT_RELEASE_VERSION must not be added on version branch ${BASE_REF}: it resolves to a version this branch never releases. Write the version this branch will ship instead (e.g. added_version=\"${BASE_REF}.<patch>\"). Pre-existing references are left alone."
exit 1