forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 1
92 lines (80 loc) · 3.27 KB
/
Copy pathupstream-release-sync.yml
File metadata and controls
92 lines (80 loc) · 3.27 KB
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
name: Sync upstream release
on:
schedule:
- cron: '39 6 * * Tue'
workflow_dispatch:
concurrency:
group: upstream-release-sync
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v3
id: app-token
with:
app-id: ${{ secrets.SYNC_AGENT_APP_ID }}
private-key: ${{ secrets.SYNC_AGENT_PRIVATE_KEY }}
- name: Setup GitHub CLI
run: |
git init --bare
git remote add origin https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/${{ github.repository }}.git
gh repo set-default ${{ github.repository }}
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Get latest upstream release
id: upstream
run: |
tag=$(gh release view --repo misskey-dev/misskey --json tagName --jq '.tagName')
echo "tag=$tag" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Check if PR already exists
id: check
run: |
if gh pr list --json isCrossRepository --state all --base develop --head upstream/${{ steps.upstream.outputs.tag }} | \
jq -e '.[] | select(.isCrossRepository == false)' > /dev/null 2>&1
then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Sync from origin
if: steps.check.outputs.exists == 'false'
run: git fetch --filter=blob:none origin develop
- name: Add upstream remote and fetch tag
if: steps.check.outputs.exists == 'false'
run: |
git remote add upstream https://github.com/misskey-dev/misskey.git
git fetch upstream tag "${{ steps.upstream.outputs.tag }}" --no-tags
- name: Create and push branch
if: steps.check.outputs.exists == 'false'
id: branch
run: |
if git merge-base --is-ancestor ${{ steps.upstream.outputs.tag }} origin/develop; then
echo "develop branch is newer than tag:${{ steps.upstream.outputs.tag }}"
echo "newer=true" >> $GITHUB_OUTPUT
exit 0
fi
git push origin "refs/tags/${{ steps.upstream.outputs.tag }}:refs/heads/upstream/${{ steps.upstream.outputs.tag }}"
- name: Create PR
if: steps.branch.outputs.newer != 'true'
run: |
body=$(gh release view "${{ steps.upstream.outputs.tag }}" --repo misskey-dev/misskey --json body --jq '.body')
if [[ -z "$body" ]]; then
body="Sync upstream release: ${{ steps.upstream.outputs.tag }}"
fi
echo "$body" > /tmp/pr-body.txt
gh pr create \
--title "upstream: ${{ steps.upstream.outputs.tag }}" \
--body-file /tmp/pr-body.txt \
--head "upstream/${{ steps.upstream.outputs.tag }}" \
--base develop
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}