Skip to content

Commit 7f39f5d

Browse files
authored
Merge pull request #105 from critesjosh/main
add nightly check to update to the latest version
2 parents 1e3b75c + 3e58a4d commit 7f39f5d

File tree

2 files changed

+97
-17
lines changed

2 files changed

+97
-17
lines changed

.github/scripts/fetchRelease.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
21
async function main() {
3-
const fetchOpts = {
4-
headers: {},
5-
};
6-
7-
if (process.env.GITHUB_TOKEN)
8-
fetchOpts.headers = { Authorization: `token ${process.env.GITHUB_TOKEN}` };
2+
const fetchOpts = { headers: {} };
3+
if (process.env.GITHUB_TOKEN) {
4+
fetchOpts.headers.Authorization = `token ${process.env.GITHUB_TOKEN}`;
5+
}
96

107
const res = await fetch('https://api.github.com/repos/AztecProtocol/aztec-packages/releases', fetchOpts);
11-
128
const data = await res.json();
139

14-
const filtered = data.filter(
15-
release => release.tag_name.includes('aztec-packages'),
16-
);
17-
18-
const latest = filtered[0].tag_name;
10+
const release = data.find(r => !r.prerelease && !r.draft && !/nightly/i.test(r.tag_name));
11+
if (!release) {
12+
console.error('No suitable release found');
13+
process.exit(1);
14+
}
1915

20-
// TODO: add the prerelease to this object!
21-
// const workflowOutput = JSON.stringify({ latest });
22-
console.log(latest); // DON'T REMOVE, GITHUB WILL CAPTURE THIS OUTPUT
16+
console.log(release.tag_name); // GitHub captures this output
2317
}
2418

25-
main();
19+
main();
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Nightly Version Update
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "0 0 * * *" # Runs every night at midnight UTC
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
issues: write
12+
13+
jobs:
14+
update:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: '22'
24+
cache: 'yarn'
25+
26+
- name: Install Aztec CLI
27+
run: |
28+
curl -s https://install.aztec.network > tmp.sh
29+
bash tmp.sh <<< yes "yes"
30+
31+
- name: Update path
32+
run: echo "/home/runner/.aztec/bin" >> $GITHUB_PATH
33+
34+
- name: Fetch latest release
35+
id: latest
36+
run: |
37+
latest=$(node .github/scripts/fetchRelease.js)
38+
echo "latest=$latest" >> $GITHUB_OUTPUT
39+
40+
- name: Get current version
41+
id: current
42+
run: |
43+
current=$(grep -oP 'tag\s*=\s*"\K[^\"]+' Nargo.toml | head -1)
44+
echo "current=$current" >> $GITHUB_OUTPUT
45+
46+
- name: Set up Aztec for latest version
47+
if: steps.latest.outputs.latest != steps.current.outputs.current
48+
run: VERSION=${{ steps.latest.outputs.latest }} aztec-up
49+
50+
- name: Run yarn update
51+
if: steps.latest.outputs.latest != steps.current.outputs.current
52+
run: yarn update
53+
54+
- name: Commit changes
55+
if: steps.latest.outputs.latest != steps.current.outputs.current
56+
run: |
57+
git config user.email "github-actions[bot]@users.noreply.github.com"
58+
git config user.name "github-actions[bot]"
59+
git add .
60+
git commit -m "chore: update to ${{ steps.latest.outputs.latest }}" || echo "No changes"
61+
62+
- name: Create Pull Request
63+
if: steps.latest.outputs.latest != steps.current.outputs.current
64+
uses: peter-evans/create-pull-request@v6
65+
with:
66+
branch: nightly/update-${{ steps.latest.outputs.latest }}
67+
title: "Update to ${{ steps.latest.outputs.latest }}"
68+
body: "Automated nightly update to aztec-packages ${{ steps.latest.outputs.latest }}"
69+
commit-message: "chore: update to ${{ steps.latest.outputs.latest }}"
70+
71+
notify-failure:
72+
needs: update
73+
runs-on: ubuntu-latest
74+
if: failure()
75+
steps:
76+
- uses: actions/github-script@v7
77+
with:
78+
github-token: ${{ secrets.GITHUB_TOKEN }}
79+
script: |
80+
await github.rest.issues.create({
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
title: 'Nightly update failed',
84+
body: '@critesjosh The nightly update workflow failed. Please investigate.'
85+
})
86+

0 commit comments

Comments
 (0)