-
Notifications
You must be signed in to change notification settings - Fork 15
150 lines (145 loc) · 5.29 KB
/
openai-api-check.yml
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
name: Check OpenAI API
on:
workflow_dispatch:
jobs:
checkAPIVersion:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Install Octokit Action
run: npm install @octokit/action
- name: Get latest API commit
id: get-latest-commit
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
result-encoding: string
script: '
const { Octokit } = require("@octokit/action");
const octokit = new Octokit();
const owner = ''openai'';
const repo = ''openai-openapi'';
const filePath = ''openapi.yaml'';
const branch = ''master'';
const commits = await octokit.repos.listCommits({
owner,
repo,
path: filePath,
ref: branch
});
return commits.data[0].sha.trim();
'
- name: Get result latest API commit
run: |
LATEST_API_COMMIT="${{steps.get-latest-commit.outputs.result}}"
echo "LATEST_API_COMMIT=$LATEST_API_COMMIT" >> $GITHUB_ENV
- name: Get current API commit
id: get-current-commit
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
result-encoding: string
script: '
const { Octokit } = require("@octokit/action");
const octokit = new Octokit();
const owner = ''xebia-functional'';
const repo = ''xef'';
const filePath = ''openai-client/generator/config/openai-api-commit'';
const branch = ''main'';
const response = await octokit.repos.getContent({
owner,
repo,
path: filePath,
ref: branch,
});
const content = Buffer.from(response.data.content, ''base64'').toString(''utf-8'');
return content.trim();
'
- name: Get result current API commit
run: |
CURRENT_API_COMMIT="${{steps.get-current-commit.outputs.result}}"
echo "CURRENT_API_COMMIT=$CURRENT_API_COMMIT" >> $GITHUB_ENV
- name: Check existing PR
if: env.CURRENT_API_COMMIT != env.LATEST_API_COMMIT
id: get-pr-commit
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
result-encoding: string
script: '
const { Octokit } = require("@octokit/action");
const octokit = new Octokit();
const owner = ''xebia-functional'';
const repo = ''xef'';
const filePath = ''openai-client/generator/config/openai-api-commit'';
const existing = await octokit.pulls.list({
owner,
repo,
head: ''xebia-functional:update/openai-client''
});
if (existing.data.length > 0) {
const prCommit = existing.data[0].head.sha;
const response = await octokit.repos.getContent({
owner,
repo,
path: filePath,
ref: prCommit
});
const prApiCommit = Buffer.from(response.data.content, ''base64'').toString(''utf-8'').trim();
if (prApiCommit === ''${{ env.LATEST_API_COMMIT }}'') {
return prApiCommit;
} else {
return '''';
}
} else {
return '''';
}
'
- name: Update current commit with PR
if: env.CURRENT_API_COMMIT != env.LATEST_API_COMMIT
run: |
PR_API_COMMIT="${{steps.get-pr-commit.outputs.result}}"
if [[ ! -z "$PR_API_COMMIT" ]]
then
echo "CURRENT_API_COMMIT=$PR_API_COMMIT" >> $GITHUB_ENV
else
echo "Previous PR outdated or nonexistent"
fi
- name: Checkout
if: env.CURRENT_API_COMMIT != env.LATEST_API_COMMIT
uses: actions/checkout@v4
- name: Update commit
if: env.CURRENT_API_COMMIT != env.LATEST_API_COMMIT
run: |
echo $LATEST_API_COMMIT > $GITHUB_WORKSPACE/openai-client/generator/config/openai-api-commit
- name: Set up Java
if: env.CURRENT_API_COMMIT != env.LATEST_API_COMMIT
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 20
- name: Download new API spec
if: env.CURRENT_API_COMMIT != env.LATEST_API_COMMIT
uses: gradle/gradle-build-action@v2
with:
arguments: downloadOpenAIAPI
- name: Generate new OpenAI client
if: env.CURRENT_API_COMMIT != env.LATEST_API_COMMIT
uses: gradle/gradle-build-action@v2
with:
arguments: openaiClientGenerate
- name: Create PR
if: env.CURRENT_API_COMMIT != env.LATEST_API_COMMIT
uses: peter-evans/create-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
commit-message: 'Update OpenAI Client'
branch: update/openai-client
title: 'Update OpenAI client'
body: 'Updates the OpenAI client based on the latest changes.'