-
Notifications
You must be signed in to change notification settings - Fork 53
85 lines (73 loc) · 2.62 KB
/
Copy pathcodex-update.yml
File metadata and controls
85 lines (73 loc) · 2.62 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
name: Codex Update
on:
schedule:
- cron: '0 9 * * *'
workflow_dispatch:
push:
branches:
- ish/codex-autoupdate
env:
CODEX_PACKAGE: '@openai/codex'
jobs:
check:
runs-on: ubuntu-latest
outputs:
should_update: ${{ steps.check.outputs.should_update }}
version: ${{ steps.check.outputs.version }}
branch: ${{ steps.check.outputs.branch }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if update is required
id: check
run: |
if ! npm outdated ${{ env.CODEX_PACKAGE }}; then
echo "Package is up to date"
exit 0
fi
LATEST=$(npm view ${{ env.CODEX_PACKAGE }} version)
BRANCH="codex-update/$LATEST"
if git ls-remote --exit-code --heads origin "refs/heads/$BRANCH" >/dev/null 2>&1; then
echo "Branch $BRANCH already exists"
exit 0
fi
echo "version=$LATEST" >> $GITHUB_OUTPUT
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
echo "should_update=true" >> $GITHUB_OUTPUT
update:
needs: check
if: needs.check.outputs.should_update == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure git user and prepare branch
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "${{ needs.check.outputs.branch }}"
- name: Install new version of package and commit
run: |
npm install ${{ env.CODEX_PACKAGE }}@${{ needs.check.outputs.version }}
npm run generate-types
git add package.json package-lock.json src/app-server
git commit -m "Update codex to ${{ needs.check.outputs.version }}"
git push origin "${{ needs.check.outputs.branch }}"
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- name: Create PR
run: |
curl --fail-with-body -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ steps.app-token.outputs.token }}" \
https://api.github.com/repos/${{ github.repository }}/pulls \
-d '{
"title": "Update codex to ${{ needs.check.outputs.version }}",
"body": "Automated codex update",
"head": "${{ needs.check.outputs.branch }}",
"base": "main"
}'