-
Notifications
You must be signed in to change notification settings - Fork 204
172 lines (143 loc) · 6.36 KB
/
Copy pathopenapi-ci.yaml
File metadata and controls
172 lines (143 loc) · 6.36 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: OpenAPI checks
on:
pull_request:
# The 'closed' type is needed to trigger cleanup of the corresponding apify-client-python PR.
types: [opened, synchronize, reopened, closed]
push:
branches:
- master
permissions:
contents: read
pull-requests: read
jobs:
lint:
name: Lint specification
# Skip lint/build/validate on PR close events - those only need the cleanup job.
if: github.event_name != 'pull_request' || github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24
- uses: apify/actions/pnpm-install@v1.1.2
- name: Lint with Redocly
run: pnpm openapi:lint:redocly --format=github-actions
- name: Lint with Spectral
run: pnpm openapi:lint:spectral --format=github-actions
build:
name: Build bundled specification
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24
- uses: apify/actions/pnpm-install@v1.1.2
- name: Build bundles
run: pnpm openapi:build
- name: Upload bundles
uses: actions/upload-artifact@v7
with:
name: openapi-bundles
path: |
static/api/openapi.json
static/api/openapi.yaml
retention-days: 1
validate:
name: Validate bundled specification
runs-on: ubuntu-latest
needs: [lint, build]
steps:
- uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24
- uses: apify/actions/pnpm-install@v1.1.2
- name: Download bundles
uses: actions/download-artifact@v8
with:
name: openapi-bundles
path: static/api/
- name: Validate YAML bundle
run: pnpm exec redocly lint static/api/openapi.yaml
- name: Validate JSON bundle
run: pnpm exec redocly lint static/api/openapi.json
- name: Check bundle sizes
run: |
JSON_SIZE=$(stat -f%z static/api/openapi.json 2>/dev/null || stat -c%s static/api/openapi.json)
YAML_SIZE=$(stat -f%z static/api/openapi.yaml 2>/dev/null || stat -c%s static/api/openapi.yaml)
echo "Bundle sizes:"
echo " JSON: $JSON_SIZE bytes"
echo " YAML: $YAML_SIZE bytes"
if [[ "$JSON_SIZE" -lt 1000 ]] || [[ "$YAML_SIZE" -lt 1000 ]]; then
echo "Error: Bundle files are suspiciously small"
exit 1
fi
echo "✓ Bundles have valid sizes"
# When a PR changes OpenAPI specs and passes validation, trigger model regeneration in apify-client-python
# so the Python client stays in sync with the API spec.
trigger-client-model-regeneration:
name: Trigger Python client model regeneration
runs-on: ubuntu-latest
needs: [validate]
if: >-
github.event_name == 'pull_request'
&& github.event.action != 'closed'
&& github.event.pull_request.head.repo.full_name == github.repository
steps:
- uses: actions/checkout@v6
- name: Check if OpenAPI files changed
id: changed-files
uses: tj-actions/changed-files@v47
with:
files: 'apify-api/openapi/**'
- name: Trigger apify-client-python model regeneration
if: steps.changed-files.outputs.any_changed == 'true'
env:
GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
run: |
gh workflow run manual_regenerate_models.yaml \
--repo apify/apify-client-python \
--field docs_pr_number="$PR_NUMBER" \
--field docs_workflow_run_id="${{ github.run_id }}" \
--field docs_pr_author="$PR_AUTHOR"
# When a docs PR is closed without being merged, clean up the corresponding auto-generated PR
# in apify-client-python to avoid stale PRs piling up.
# If the docs PR is merged, the client PR is left open for manual review and merge.
cleanup-client-model-pr:
name: Close Python client model PR on docs PR close
runs-on: ubuntu-latest
if: >-
github.event_name == 'pull_request'
&& github.event.action == 'closed'
&& github.event.pull_request.merged == false
&& github.event.pull_request.head.repo.full_name == github.repository
steps:
- name: Close corresponding apify-client-python PR
env:
GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
# Branch name convention must match what manual_regenerate_models.yaml creates.
run: |
BRANCH="update-models-docs-pr-${PR_NUMBER}"
EXISTING_PR=$(gh pr list \
--repo apify/apify-client-python \
--head "$BRANCH" \
--json number \
--jq '.[0].number // empty' 2>/dev/null || true)
if [[ -n "$EXISTING_PR" ]]; then
gh pr close "$EXISTING_PR" \
--repo apify/apify-client-python \
--delete-branch \
--comment "Closing this PR because the source apify-docs PR #${PR_NUMBER} was closed without merging."
echo "Closed apify-client-python PR #$EXISTING_PR"
else
echo "No corresponding apify-client-python PR found for branch $BRANCH"
fi