-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathsdks_generate_openapi_spec_and_fern_code.yml
More file actions
204 lines (178 loc) · 6.96 KB
/
sdks_generate_openapi_spec_and_fern_code.yml
File metadata and controls
204 lines (178 loc) · 6.96 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
201
202
203
204
name: SDKs Generate OpenAPI spec and Fern code
on:
push:
branches: ['main']
paths:
- 'apps/opik-backend/src/main/java/**/*.java'
- 'apps/opik-backend/src/main/resources/openapi_template.yml'
- 'apps/opik-backend/pom.xml'
workflow_dispatch: # Allows manual trigger
concurrency:
group: fern-auto-update
cancel-in-progress: true
jobs:
resolve-trigger-context:
runs-on: ubuntu-latest
if: github.event_name == 'push'
permissions:
contents: read
outputs:
trigger_author: ${{ steps.get-author.outputs.author }}
originating_pr_url: ${{ steps.find-pr.outputs.pr_url }}
steps:
- name: Get merge author
id: get-author
run: |
AUTHOR="${{ github.event.head_commit.author.username }}"
if [ -z "$AUTHOR" ]; then
AUTHOR="${{ github.actor }}"
fi
echo "author=$AUTHOR" >> $GITHUB_OUTPUT
- name: Find originating PR
id: find-pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_URL=$(gh api "repos/${{ github.repository }}/commits/${{ github.sha }}/pulls" --jq '.[0].html_url' 2>/dev/null || echo "")
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
update-open-api-spec-and-fern-code:
needs: resolve-trigger-context
if: ${{ !failure() }}
runs-on: ubuntu-latest
permissions:
contents: write
timeout-minutes: 15
outputs:
pr_url: ${{ steps.create-pr.outputs.pull-request-url }}
pr_number: ${{ steps.create-pr.outputs.pull-request-number }}
steps:
- name: Checkout Repository
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'
cache: maven
- name: Install Fern
run: npm install -g fern-api
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install Opik Optimizer SDK (for Fern docs)
run: |
python -m pip install --upgrade pip
pip install -e sdks/opik_optimizer
- name: Set branch name
run: |
echo "BRANCH_NAME=github-actions/NA-automatically-update-openapi-spec-and-fern-code-$(date +%Y-%m-%d-%H-%M-%S)" >> $GITHUB_ENV
- name: Run Generate OpenAPI spec and Fern code
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
run: |
set -e
cd apps/opik-backend
mvn clean
cd -
./scripts/generate_openapi.sh
- name: Generate Opik Optimizer Fern docs
run: |
python sdks/opik_optimizer/scripts/generate_fern_docs.py --write
- name: Prepare PR context
id: pr-context
run: |
if [ "${{ github.event_name }}" == "push" ]; then
ORIGINATING_PR="${{ needs.resolve-trigger-context.outputs.originating_pr_url }}"
if [ -n "$ORIGINATING_PR" ]; then
echo "trigger_info=**Triggered by BE merge:** $ORIGINATING_PR" >> $GITHUB_OUTPUT
else
echo "trigger_info=**Triggered by commit:** https://github.com/${{ github.repository }}/commit/${{ github.sha }}" >> $GITHUB_OUTPUT
fi
else
echo "trigger_info=" >> $GITHUB_OUTPUT
fi
- name: Check for changes
id: check_changes
run: |
if git diff --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Commit files
if: steps.check_changes.outputs.has_changes == 'true'
run: |
set -ex
git config --local user.email "github-actions@comet.com"
git config --local user.name "Github Actions (${{ github.actor }})"
git add sdks/python/src/opik/rest_api/
git add sdks/typescript/src/opik/rest_api/
git add sdks/code_generation/fern/openapi/openapi.yaml
git add apps/opik-documentation/documentation/fern/openapi/opik.yaml
git add apps/opik-documentation/documentation/fern/docs/agent_optimization/opik_optimizer/reference.mdx
git commit -m "[NA] [SDK] [DOCS] Update automatically OpenAPI spec and Fern code"
- name: Create Pull Request
if: steps.check_changes.outputs.has_changes == 'true'
id: create-pr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.COMET_ACTION_CREATE_PR }}
branch: ${{ env.BRANCH_NAME }}
title: "[NA] [SDK] [DOCS] Update automatically OpenAPI spec and Fern code"
body: |
## Details
Automated update of OpenAPI spec and Fern code after running `./scripts/generate_openapi.sh` and `./sdks/opik_optimizer/scripts/generate_fern_docs.py`.
${{ steps.pr-context.outputs.trigger_info }}
## Change checklist
- [ ] User facing changes
- [X] Documentation updated
## Issues
N/A
## Testing
- Passed CI
## Documentation
- https://buildwithfern.com/learn/cli-api-reference/cli-reference/commands#fern-generate
base: main
notify-slack:
name: Notify #code-review
runs-on: ubuntu-latest
permissions: {}
needs: [update-open-api-spec-and-fern-code, resolve-trigger-context]
if: >-
!failure() &&
github.event_name == 'push' &&
needs.update-open-api-spec-and-fern-code.outputs.pr_url != ''
steps:
- name: Checkout
uses: actions/checkout@v6
with:
sparse-checkout: .github/scripts
sparse-checkout-cone-mode: false
- name: Resolve Slack mention
id: resolve-mention
env:
SLACK_USER_MAPPING: ${{ secrets.SLACK_USER_MAPPING }}
run: |
AUTHOR="${{ needs.resolve-trigger-context.outputs.trigger_author }}"
AUTHOR_MENTION=""
if [ -n "$SLACK_USER_MAPPING" ] && [ -n "$AUTHOR" ]; then
AUTHOR_SLACK_ID=$(echo "$SLACK_USER_MAPPING" | jq -r --arg user "$AUTHOR" '.[$user] // empty' 2>/dev/null || echo "")
if [ -n "$AUTHOR_SLACK_ID" ]; then
AUTHOR_MENTION="<@$AUTHOR_SLACK_ID>"
fi
fi
echo "mention=$AUTHOR_MENTION" >> $GITHUB_OUTPUT
echo "author_display=$AUTHOR" >> $GITHUB_OUTPUT
- name: Send Slack notification
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_CODE_REVIEW }}
PR_URL: ${{ needs.update-open-api-spec-and-fern-code.outputs.pr_url }}
PR_NUMBER: ${{ needs.update-open-api-spec-and-fern-code.outputs.pr_number }}
ORIGINATING_PR: ${{ needs.resolve-trigger-context.outputs.originating_pr_url }}
AUTHOR_DISPLAY: ${{ steps.resolve-mention.outputs.author_display }}
MENTION: ${{ steps.resolve-mention.outputs.mention }}
run: .github/scripts/notify-slack-fern-update.sh