Skip to content

Commit 67e528a

Browse files
committed
Codex auto-update
Automatically check for new version of codex and create MR with update
1 parent d8b79e8 commit 67e528a

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

.github/workflows/codex-update.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Codex Update
2+
3+
on:
4+
schedule:
5+
- cron: '0 9 * * *'
6+
workflow_dispatch:
7+
8+
env:
9+
CODEX_PACKAGE: '@openai/codex'
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
should_update: ${{ steps.check.outputs.should_update }}
16+
version: ${{ steps.check.outputs.version }}
17+
branch: ${{ steps.check.outputs.branch }}
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Check if update is required
24+
id: check
25+
run: |
26+
if ! npm outdated ${{ env.CODEX_PACKAGE }}; then
27+
echo "Package is up to date"
28+
exit 0
29+
fi
30+
31+
LATEST=$(npm view ${{ env.CODEX_PACKAGE }} version)
32+
BRANCH="codex-update/$LATEST"
33+
34+
if git ls-remote --exit-code --heads origin "refs/heads/$BRANCH" >/dev/null 2>&1; then
35+
echo "Branch $BRANCH already exists"
36+
exit 0
37+
fi
38+
39+
echo "version=$LATEST" >> $GITHUB_OUTPUT
40+
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
41+
echo "should_update=true" >> $GITHUB_OUTPUT
42+
43+
update:
44+
needs: check
45+
if: needs.check.outputs.should_update == 'true'
46+
runs-on: ubuntu-latest
47+
env:
48+
BRANCH: ${{ needs.check.outputs.branch }}
49+
VERSION: ${{ needs.check.outputs.version }}
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- name: Configure git user and prepare branch
54+
run: |
55+
git config user.name "github-actions[bot]"
56+
git config user.email "github-actions[bot]@users.noreply.github.com"
57+
git checkout -b "${{ env.BRANCH }}"
58+
59+
- name: Install new version of package and commit
60+
run: |
61+
npm install ${{ env.CODEX_PACKAGE }}@${{ env.VERSION }}
62+
npm run generate-types
63+
git add package.json package-lock.json src/app-server
64+
git commit -m "Update codex to ${{ env.VERSION }}"
65+
git push origin "${{ env.BRANCH }}"
66+
67+
- name: Generate GitHub App token
68+
id: app-token
69+
uses: actions/create-github-app-token@v1
70+
with:
71+
app-id: ${{ vars.GH_APP_ID }}
72+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
73+
74+
- name: Create PR
75+
env:
76+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
77+
run: |
78+
gh pr create \
79+
--base main \
80+
--title "Update codex to ${{ env.VERSION }}" \
81+
--body "[What's new](https://github.com/openai/codex/releases/tag/rust-v${{ env.VERSION }})" \
82+
--label "codex-update"

0 commit comments

Comments
 (0)