-
Notifications
You must be signed in to change notification settings - Fork 9
101 lines (89 loc) · 2.98 KB
/
update-deps.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
name: Update Dependencies
on:
schedule:
- cron: '0 7 * * *'
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Detect open PR
id: detect_open_pr
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
base: 'main',
head: `${context.repo.owner}:updates`,
});
// save pr number to github_env
if (pullRequests[0]) {
require('fs').appendFileSync(process.env.GITHUB_ENV,
`PR_NUMBER=${pullRequests[0].number}\n`
);
}
return pullRequests[0]?.head?.ref ?? 'main';
- id: create_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ steps.create_token.outputs.token }}
ref: ${{ steps.detect_open_pr.outputs.result }}
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Do updates
run: |
{
echo 'PR_BODY<<EOF'
node ./.github/workflows/update_deps.mjs ${{ steps.detect_open_pr.outputs.result }}
echo EOF
} >> $GITHUB_ENV
- name: Cargo update
run: cargo update
- name: Open PR
if: steps.detect_open_pr.outputs.result == 'main'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ steps.create_token.outputs.token }}
commit-message: 'ci: Update dependencies'
title: Update dependencies
body: ${{ env.PR_BODY }}
branch: updates
- name: Push to existing PR
if: steps.detect_open_pr.outputs.result != 'main'
run: |
if git diff --quiet; then
echo "No changes"
exit 1
fi
git add .
git config --local user.email "[email protected]"
git config --local user.name "create-o7-app[bot]"
git commit -m "ci: Update dependencies"
git push origin ${{ steps.detect_open_pr.outputs.result }}
- name: Comment on PR
if: steps.detect_open_pr.outputs.result != 'main'
uses: actions/github-script@v7
with:
github-token: ${{ steps.create_token.outputs.token }}
script: |
await github.rest.issues.createComment({
issue_number: ${{ env.PR_NUMBER }},
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.PR_BODY,
});