forked from nostr-jp/nips-ja
-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (69 loc) · 2.45 KB
/
sync.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
name: Sync
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 5"
permissions: {}
jobs:
sync:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/create-github-app-token@v1
id: create_token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
token: ${{ steps.create_token.outputs.token }}
- name: Sync with upstream
id: sync
run: |
echo ::group::Setting up git and gh
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
gh repo set-default ${{ github.repository }}
echo ::endgroup::
echo ::group::Fetching upstream
git remote add upstream https://github.com/nostr-protocol/nips
git fetch upstream
echo ::endgroup::
echo ::group::Fetching origin
git fetch origin
echo ::endgroup::
echo ::group::Switching to sync branch
git switch -c sync
git log -1 --format=%H
echo ::endgroup::
echo ::group::Merging upstream to sync branch
if ! git merge upstream/master --no-edit --commit -m "Sync with upstream"; then
git add -A
git commit -m "Sync with upstream including CONFLICT"
fi
echo ::endgroup::
if ! git diff --quiet main; then
echo "diff_main=1" >> $GITHUB_OUTPUT
echo ::group::Pushing sync branch
git push -f origin sync
echo ::endgroup::
else
echo "diff_main=0" >> $GITHUB_OUTPUT
echo "main is in sync with upstream"
fi
env:
GITHUB_TOKEN: ${{ steps.create_token.outputs.token }}
- name: Check if sync pull request exists
id: sync_pr_existence
run: |
echo "count=$(gh pr list --head sync --base main | wc -l)" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ steps.create_token.outputs.token }}
- name: Create pull request if needed
if: ${{ steps.sync_pr_existence.outputs.count == 0 && steps.sync.outputs.diff_main == 1 }}
run: |
gh pr create --head "sync" --base "main" --title "Sync with upstream" --body ""
env:
GITHUB_TOKEN: ${{ steps.create_token.outputs.token }}