-
Notifications
You must be signed in to change notification settings - Fork 61
121 lines (104 loc) · 4.09 KB
/
workflow-check-openapi-changes.yaml
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
# ℹ️
# This workflow runs for pull_requests that are based on main
# if there is a change in the file `openapi.yaml`
# but only when opening a PR containing changes to the file
# of if a commit is added to a PR containing changes to the file
#
# - 1. it runs the coral setup
# - 2. auto generates the file `coral/types/api.t.ds` from the `openapi.yaml`
# - 3. checks if the file file `coral/types/api.t.ds` was changed
# - if not: ends the workflow ✅
# - if yes:
# - 3.1 runs the typescript compiler in 'coral/'
# - if 3.1. is successful
# -> adds the file `coral/types/api.t.ds` as new commit ✅
# - if 3.1. fails
# -> fails the workflow ⛔️
# This workflow ensures that our type definition for APIs are always in
# sync and that API changes don't break things in coral.
name: Auto-generate TypeScript api file
on:
pull_request:
paths:
- 'openapi.yaml'
types:
- opened
- synchronize
jobs:
check-for-changes-openapi:
runs-on: ubuntu-latest
outputs:
change_detected: ${{ steps.detect-openapi-changes.outputs.change_detected }}
steps:
- name: Checkout code
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
persist-credentials: true
- id: detect-openapi-changes
name: Check for changes to "openapi.yaml"
run: |
if git diff --name-only HEAD^ HEAD | grep -q 'openapi.yaml'; then
echo "OpenAPI changes detected. Will generate new TypeScript types now 🤖"
echo "change_detected=true" >> $GITHUB_OUTPUT
else
echo "No new changes to OpenAPI detected, will end workflow."
fi
detect-ts-changes:
runs-on: ubuntu-latest
needs: check-for-changes-openapi
if: needs.check-for-changes-openapi.outputs.change_detected == 'true'
outputs:
types_changed: ${{ steps.detect-ts-changes.outputs.types_changed }}
steps:
- name: Checkout code
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
persist-credentials: true
- name: Setup coral
uses: ./.github/actions/setup-coral
- name: Generate files
working-directory: ./coral
run: pnpm extract-api-types
- id: detect-ts-changes
name: Check for changes to "coral/types/api.d.ts"
run: |
git add .
if git diff --name-only --cached | grep -q 'coral/types/api.d.ts'; then
echo "TS changes detected. Will run checks and if successful commit changes 🤖"
echo "types_changed=true" >> $GITHUB_OUTPUT
else
echo "No new changes to TS types detected, will end workflow."
fi
check-and-commit-typescript-changes:
runs-on: ubuntu-latest
needs: detect-ts-changes
if: needs.detect-ts-changes.outputs.types_changed == 'true'
steps:
- name: Checkout code
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
persist-credentials: true
- name: Setup coral
uses: ./.github/actions/setup-coral
- name: Generate files
working-directory: ./coral
run: pnpm extract-api-types
- name: Run TypeScript compiler
working-directory: ./coral
run: pnpm tsc
- name: Add changed file
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add .
git commit -m "🤖 Auto-update API types for TypeScript usage"
git push