-
Notifications
You must be signed in to change notification settings - Fork 1
/
alternative.yml
92 lines (71 loc) · 3.39 KB
/
alternative.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
name: Update from Template
# This workflow keeps the repo up to date with changes from the template repo (REMOTE_URL)
# It duplicates the REMOTE_BRANCH (into UPDATE_BRANCH) and tries to merge it into the
# this repos default branch (which is checked out here)
# Note that this requires a PAT (Personal Access Token) - at best from a servicing account
# Also note that you should have at least once merged the template repo into the current repo manually
# otherwise a "refusing to merge unrelated histories" error might occur.
on:
schedule:
- cron: '0 0 * * 1'
workflow_dispatch:
env:
UPDATE_BRANCH: update-from-template
REMOTE_URL: https://github.com/litetex/yourTemplateRepo.git
REMOTE_BRANCH: master
permissions:
contents: write
pull-requests: write
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# Required because otherwise there are always changes detected when executing diff/rev-list
fetch-depth: 0
# If no PAT is used the following error occurs on a push:
# refusing to allow a GitHub App to create or update workflow `.github/workflows/xxx.yml` without `workflows` permission
token: ${{ secrets.UPDATE_FROM_TEMPLATE_PAT }}
- name: Init Git
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
- name: Main workflow
id: main
run: |
echo "Adding remote template-repo"
git remote add template ${{ env.REMOTE_URL }}
echo "Fetching remote template repo"
git fetch template
echo "Deleting local branch that will contain the updates - if present"
git branch -D ${{ env.UPDATE_BRANCH }} || true
echo "Checking if the remote template repo has new commits"
git rev-list ..template/${{ env.REMOTE_BRANCH }}
if [ $(git rev-list --count ..template/${{ env.REMOTE_BRANCH }}) -eq 0 ]; then
echo "There are no commits new commits on the template repo"
echo "Deleting origin branch that contains the updates - if present"
git push -f origin --delete ${{ env.UPDATE_BRANCH }} || true
echo "abort=1" >> $GITHUB_OUTPUT
exit 0
fi
echo "Found new commits on the template repo"
echo "Creating update branch"
git branch ${{ env.UPDATE_BRANCH }} template/${{ env.REMOTE_BRANCH }}
git branch --unset-upstream ${{ env.UPDATE_BRANCH }}
echo "Pushing update branch"
git push -f -u origin ${{ env.UPDATE_BRANCH }}
echo "Getting current branch"
current_branch=$(git branch --show-current)
echo "Current branch is $current_branch"
echo "current_branch=$current_branch" >> $GITHUB_OUTPUT
echo "abort=0" >> $GITHUB_OUTPUT
- name: pull-request
uses: repo-sync/pull-request@v2
if: steps.main.outputs.abort == 0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_branch: ${{ env.UPDATE_BRANCH }}
destination_branch: ${{ steps.main.outputs.current_branch }}
pr_title: "Update from template"
pr_body: "An automated PR to sync changes from the template into this repo"