forked from open-metadata/OpenMetadata
-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (178 loc) · 8.58 KB
/
Copy pathtypescript-type-generation.yml
File metadata and controls
200 lines (178 loc) · 8.58 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: TypeScript Type Generation
on:
merge_group:
pull_request_target:
types: [opened, synchronize, reopened, labeled, ready_for_review]
paths:
- 'openmetadata-spec/src/main/resources/json/schema/**'
- 'openmetadata-ui/src/main/resources/ui/src/generated/**'
workflow_dispatch:
inputs:
branch:
description: 'Branch to run the workflow on (ignored if pr_number is provided)'
required: false
default: 'main'
type: string
pr_number:
description: 'PR number to run the workflow for (works for both forked and non-forked PRs)'
required: false
type: string
concurrency:
group: typescript-generation-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name != 'pull_request_target' || github.event.action != 'labeled' || github.event.label.name == 'safe to test' }}
jobs:
generate-types:
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.draft && (github.event_name != 'pull_request_target' || github.event.action != 'labeled' || github.event.label.name == 'safe to test') }}
permissions:
contents: write
pull-requests: write
steps:
- name: Get PR details for workflow_dispatch
if: github.event_name == 'workflow_dispatch' && github.event.inputs.pr_number != ''
id: pr-details
env:
PR_NUMBER: ${{ github.event.inputs.pr_number }}
BASE_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_DATA=$(gh pr view "$PR_NUMBER" --json headRepository,headRefName,headRepositoryOwner,headRefOid --repo "$BASE_REPO")
echo "head_repo=$(echo "$PR_DATA" | jq -r '.headRepository.name')" >> $GITHUB_OUTPUT
echo "head_owner=$(echo "$PR_DATA" | jq -r '.headRepositoryOwner.login')" >> $GITHUB_OUTPUT
echo "head_ref=$(echo "$PR_DATA" | jq -r '.headRefName')" >> $GITHUB_OUTPUT
echo "head_sha=$(echo "$PR_DATA" | jq -r '.headRefOid')" >> $GITHUB_OUTPUT
echo "full_repo=$(echo "$PR_DATA" | jq -r '.headRepositoryOwner.login + "/" + .headRepository.name')" >> $GITHUB_OUTPUT
- name: Wait for the labeler
uses: lewagon/wait-on-check-action@v1.7.0
if: ${{ github.event_name == 'pull_request_target' && github.actor != 'github-actions[bot]' }}
with:
ref: ${{ github.event.pull_request.head.sha }}
check-name: Team Label
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 90
- name: Verify PR labels
uses: jesusvasquez333/verify-pr-label-action@v1.4.0
if: ${{ github.event_name == 'pull_request_target' && github.actor != 'github-actions[bot]' }}
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
valid-labels: 'safe to test'
pull-request-number: '${{ github.event.pull_request.number }}'
disable-reviews: true
- name: Check if repository is a fork
id: check-fork
env:
EVENT_NAME: ${{ github.event_name }}
FULL_REPO: ${{ steps.pr-details.outputs.full_repo }}
HEAD_REPO_FULL_NAME: ${{ github.event.pull_request.head.repo.full_name }}
BASE_REPO: ${{ github.repository }}
run: |
if [ "$EVENT_NAME" == "workflow_dispatch" ] && [ -n "$FULL_REPO" ]; then
# For workflow_dispatch with PR number
if [ "$FULL_REPO" != "$BASE_REPO" ]; then
echo "is_fork=true" >> $GITHUB_OUTPUT
else
echo "is_fork=false" >> $GITHUB_OUTPUT
fi
elif [ "$EVENT_NAME" == "pull_request_target" ]; then
# For pull_request_target events
if [ "$HEAD_REPO_FULL_NAME" != "$BASE_REPO" ]; then
echo "is_fork=true" >> $GITHUB_OUTPUT
else
echo "is_fork=false" >> $GITHUB_OUTPUT
fi
else
# Default to non-fork for direct branch runs
echo "is_fork=false" >> $GITHUB_OUTPUT
fi
- name: Determine checkout ref
id: checkout-ref
env:
IS_FORK: ${{ steps.check-fork.outputs.is_fork }}
EVENT_NAME: ${{ github.event_name }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
PR_DETAILS_HEAD_SHA: ${{ steps.pr-details.outputs.head_sha }}
PR_DETAILS_HEAD_REF: ${{ steps.pr-details.outputs.head_ref }}
INPUT_BRANCH: ${{ github.event.inputs.branch }}
GITHUB_REF: ${{ github.ref }}
GITHUB_SHA_VAL: ${{ github.sha }}
run: |
if [ "$EVENT_NAME" == "merge_group" ]; then
echo "ref=$GITHUB_SHA_VAL" >> $GITHUB_OUTPUT
elif [ "$IS_FORK" == "true" ] && [ "$EVENT_NAME" == "pull_request_target" ]; then
echo "ref=$PR_HEAD_SHA" >> $GITHUB_OUTPUT
elif [ "$EVENT_NAME" == "pull_request_target" ]; then
echo "ref=$PR_HEAD_REF" >> $GITHUB_OUTPUT
elif [ "$IS_FORK" == "true" ] && [ -n "$PR_DETAILS_HEAD_SHA" ]; then
echo "ref=$PR_DETAILS_HEAD_SHA" >> $GITHUB_OUTPUT
elif [ -n "$PR_DETAILS_HEAD_REF" ]; then
echo "ref=$PR_DETAILS_HEAD_REF" >> $GITHUB_OUTPUT
elif [ -n "$INPUT_BRANCH" ]; then
echo "ref=$INPUT_BRANCH" >> $GITHUB_OUTPUT
else
echo "ref=$GITHUB_REF" >> $GITHUB_OUTPUT
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ steps.pr-details.outputs.full_repo || github.repository }}
ref: ${{ steps.checkout-ref.outputs.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: 'openmetadata-ui/src/main/resources/ui/.nvmrc'
- name: Install dependencies
run: |
yarn install --frozen-lockfile
- name: Generate TypeScript types
run: |
cd openmetadata-ui/src/main/resources/ui
# Create a symlink to the root node_modules
ln -sf ../../../../../node_modules .
./json2ts-generate-all.sh -l true
- name: Check for changes
id: git-check
continue-on-error: true
run: |
git add openmetadata-ui/src/main/resources/ui/src/generated/
git diff --cached --quiet
- name: Configure Git
if: steps.git-check.outcome != 'success'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Commit and push changes
if: steps.git-check.outcome != 'success' && steps.check-fork.outputs.is_fork == 'false'
run: |
git commit -m "Update generated TypeScript types"
git push --force-with-lease
- name: Create PR comment about auto-update
if: steps.git-check.outcome != 'success' && steps.check-fork.outputs.is_fork == 'false' && (github.event_name == 'pull_request_target' || github.event.inputs.pr_number != '')
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number || github.event.inputs.pr_number }}
body: |
## ✅ TypeScript Types Auto-Updated
The generated TypeScript types have been automatically updated based on JSON schema changes in this PR.
- name: Create PR comment for fork repository
if: steps.git-check.outcome != 'success' && steps.check-fork.outputs.is_fork == 'true' && (github.event_name == 'pull_request_target' || github.event.inputs.pr_number != '')
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number || github.event.inputs.pr_number }}
body: |
## ⚠️ TypeScript Types Need Update
**The generated TypeScript types are out of sync with the JSON schema changes.**
Since this is a pull request from a forked repository, the types cannot be automatically committed.
Please generate and commit the types manually:
```bash
cd openmetadata-ui/src/main/resources/ui
./json2ts-generate-all.sh -l true
git add src/generated/
git commit -m "Update generated TypeScript types"
git push
```
After pushing the changes, this check will pass automatically.
- name: Fail workflow for fork PRs with type changes
if: steps.git-check.outcome != 'success' && steps.check-fork.outputs.is_fork == 'true'
run: exit 1