-
Notifications
You must be signed in to change notification settings - Fork 5
135 lines (113 loc) · 4.69 KB
/
transform.yml
File metadata and controls
135 lines (113 loc) · 4.69 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
name: Transform OpenAPI Specs
on:
push:
branches:
- main
paths:
- 'source_specs/**'
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
permissions:
contents: write
jobs:
transform:
runs-on: ubuntu-latest
steps:
- name: Generate App Token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Set up mise
uses: jdx/mise-action@v2
with:
cache: true
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Transform OpenAPI spec paths
run: pnpm run transform:source_specs
env:
GITHUB_SHA: ${{ github.sha }}
- name: Generate OpenAPI specs
run: speakeasy run -s glean-api-specs
env:
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}
# We intentionally skip uploading the spec to the Speakeasy registry since
# we're only using them for code sample generation.
- name: Generate Client API specs for code sample generation
run: speakeasy run -s glean-client-api-specs --skip-upload-spec
env:
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}
# We intentionally skip uploading the spec to the Speakeasy registry since
# we're only using them for code sample generation.
- name: Generate Indexing API specs for code sample generation
run: speakeasy run -s glean-indexing-api-specs --skip-upload-spec
env:
SPEAKEASY_API_KEY: ${{ secrets.SPEAKEASY_API_KEY }}
- name: Run post-transformation smoke tests
run: pnpm exec vitest run tests/post_transform_smoke.test.js
- name: Check if changes are only SHA updates
id: check_changes
run: |
# Check if there are any changes at all
STATUS=$(git status --porcelain generated_specs/ overlayed_specs/ 2>/dev/null)
if [ -z "$STATUS" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes to commit"
exit 0
fi
echo "::group::Changed files"
echo "$STATUS"
echo "::endgroup::"
# Check for new/untracked files (lines starting with ??)
NEW_FILES=$(echo "$STATUS" | grep "^??" | wc -l)
if [ "$NEW_FILES" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "New files detected, will commit"
exit 0
fi
# Get the diff and check if only SHA lines changed (for modified files)
DIFF=$(git diff --unified=0 generated_specs/ overlayed_specs/)
echo "::group::Git diff"
echo "$DIFF"
echo "::endgroup::"
# Extract only the actual content changes (lines starting with + or -)
# Exclude file markers (+++/---), hunk headers (@@), and get only content
CHANGED_LINES=$(echo "$DIFF" | grep -E "^[\+\-]" | grep -v "^[\+\-][\+\-][\+\-]" | grep -v "^@@" || true)
if [ -z "$CHANGED_LINES" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No actual content changes detected"
exit 0
fi
# Check if all changes are SHA-related
NON_SHA_CHANGES=$(echo "$CHANGED_LINES" | grep -v "x-source-commit-sha" | grep -v "x-open-api-commit-sha" || true)
echo "::group::Non-SHA changes"
echo "$NON_SHA_CHANGES"
echo "::endgroup::"
if [ -z "$NON_SHA_CHANGES" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "Only SHA fields changed, skipping commit"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Non-SHA changes detected, will commit"
fi
# NOTE: The commit body contains "Generated-by: .github/workflows/transform.yml" which is used by
# trigger-client-generation.yml to detect whether meaningful changes were committed.
# If you change this identifier, update trigger-client-generation.yml accordingly.
- name: Commit changes
if: steps.check_changes.outputs.has_changes == 'true'
uses: ./.github/actions/git-commit
with:
commit_message: |
Update \`generated_specs\` and \`overlayed_specs\`
Generated-by: .github/workflows/transform.yml
file_patterns: 'generated_specs/* .speakeasy/* overlayed_specs/*'
github_token: ${{ steps.app-token.outputs.token }}