Skip to content

Commit 27b6eb4

Browse files
authored
feat: add auto update for v3 branch (#27)
1 parent 898fe67 commit 27b6eb4

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

.github/scripts/auto-update-pr.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = async ({ github, context }, head, base) => {
2+
try {
3+
const { repo, owner } = context.repo;
4+
const result = await github.rest.pulls.create({
5+
title: 'Auto Update from main',
6+
owner,
7+
repo,
8+
head,
9+
base,
10+
body: '(o゜▽゜)o ☆ ☜(゚ヮ゚☜)'
11+
});
12+
13+
await github.rest.issues.addLabels({
14+
owner,
15+
repo,
16+
issue_number: result.data.number,
17+
labels: ['automated update']
18+
});
19+
20+
return result.data.html_url;
21+
} catch (e) {
22+
console.error(e);
23+
}
24+
return false;
25+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
name: Auto Update PR
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
head:
8+
required: true
9+
type: string
10+
base:
11+
required: true
12+
type: string
13+
14+
permissions:
15+
pull-requests: write
16+
contents: write
17+
18+
jobs:
19+
create-pull-request:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: ⬇️ Checkout repo
23+
uses: actions/checkout@v3
24+
25+
- name: ↔ Create Pull Request
26+
uses: actions/github-script@v6
27+
id: create-pr
28+
with:
29+
result-encoding: string
30+
script: |
31+
const script = require('./.github/scripts/auto-update-pr.js')
32+
const head = '${{ inputs.head }}';
33+
const base = '${{ inputs.base }}';
34+
return await script({github, context}, head, base)
35+
36+
- name: 🤖 Enable auto-merge for auto-update
37+
run: |
38+
if [[ $PR_URL != false ]];
39+
then
40+
gh pr merge --auto --merge "$PR_URL"
41+
fi
42+
env:
43+
PR_URL: ${{steps.create-pr.outputs.result}}
44+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

.github/workflows/auto-update.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
name: Schedule Auto Update
3+
4+
on:
5+
schedule:
6+
- cron: "0 0 * * *"
7+
8+
jobs:
9+
auto-update:
10+
strategy:
11+
matrix:
12+
update: [{ head: "main", base: "v3" }]
13+
uses: ./.github/workflows/99-auto-update-pr.yml
14+
with:
15+
head: ${{ matrix.update.head }}
16+
base: ${{ matrix.update.base }}

0 commit comments

Comments
 (0)