-
-
Notifications
You must be signed in to change notification settings - Fork 60
102 lines (95 loc) · 3.47 KB
/
upstream.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
102
name: Upstream synchronization
on:
schedule:
- cron: "0 6 * * 3" # 6am every Wednesday
workflow_dispatch:
env:
LABEL: automated-upstream-merge
jobs:
sync-upstream:
name: Sync upstream branch
runs-on: ubuntu-latest
steps:
- name: Checkout local `upstream` branch (us)
uses: actions/checkout@v3
with:
ref: upstream
fetch-depth: 0
- name: Checkout upstream `master` branch (them)
run: |
git remote add upstream git://sourceware.org/git/valgrind.git
git fetch --tags upstream master
shell: bash
- name: Configure git credentials
run: |
git config --global user.name "upstream-sync[bot]"
git config --global user.email "upstream-sync[bot]@users.noreply.github.com"
- name: Rebase local `upstream` branch onto upstream `master`
run: |
git rebase upstream/master
git push -f origin upstream
git push --tags origin
shell: bash
upstream-merge-pr:
name: Merge upstream changes into main
runs-on: ubuntu-latest
steps:
- name: Checkout local `main` branch (us)
uses: actions/checkout@v3
with:
ref: main
fetch-depth: 0
- name: Checkout upstream `master` branch (them)
run: |
git remote add upstream git://sourceware.org/git/valgrind.git
git fetch upstream master
shell: bash
- name: Configure git credentials
run: |
git config --global user.name "upstream-sync[bot]"
git config --global user.email "upstream-sync[bot]@users.noreply.github.com"
- name: Create a merge which merge them into us
id: merge
run: |
NAME=$(date +%Y-%m-%d-%s)
BRANCH=feature/upstream-${NAME}
CHANGES=$(git log --oneline main..upstream/master)
git merge upstream/master
echo "Branch: ${BRANCH}"
echo "Generated: ${NAME}"
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
echo "generated=${NAME}" >> $GITHUB_OUTPUT
echo "changes<<EOF" >> $GITHUB_OUTPUT
echo "${CHANGES}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
shell: bash
- name: Create pull request
id: cpr
uses: peter-evans/create-pull-request@v5
with:
title: "chore(upstream): merge upstream changes into main"
body: |
This is an automated PR merging upstream changes into main.
Generated on: ${{ steps.merge.outputs.generated }}
Changes:
```
${{ steps.merge.outputs.changes }}
```
branch: ${{ steps.merge.outputs.branch }}
delete-branch: true
reviewers: LouisBrunner
labels: upstream,chore,${{ env.LABEL }}
- name: Close older pull requests
run: |
echo "New PR: ${{ steps.cpr.outputs.pull-request-number }} (${{ steps.cpr.outputs.pull-request-url }})"
gh pr list --label ${{ env.LABEL }} --json number --jq '.[].number' | while read -r NUM; do
if [ $NUM -eq ${{ steps.cpr.outputs.pull-request-number }} ]; then
continue
fi
URL=$(gh pr view $NUM --json url --jq .url)
echo "# Closing PR: $NUM ($URL)"
gh pr close $NUM -d -c 'Stale pull request, see new one here: ${{ steps.cpr.outputs.pull-request-url }}'
done
shell: bash
env:
GH_TOKEN: ${{ github.token }}