-
Notifications
You must be signed in to change notification settings - Fork 4
79 lines (75 loc) · 3.11 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
# Sometimes template and main get out of wack.
# This tries to rectify that
name: sync template
on:
workflow_dispatch:
push:
branches: [ template ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: sync
run: |
echo "::group::Setup Git"
echo ">> Actor:${{ github.actor }}"
git config --global user.name '${{ github.actor }}'
git config --global user.email '${{ github.actor }}@users.noreply.github.com'
echo "::endgroup::"
# Aggressively resolve merge.
echo "::group::Merge"
cp ./.github/workflows/sync.yml ~
git fetch
git merge -s recursive -X ours origin/main || echo "merge failed (no branch?)"
git status | grep -P 'deleted by us|added by them' | awk '{print $4}' | xargs git rm || echo fine
# Update remote if changed
previous_user=$(cat .github/assets/remote.txt | cut -d/ -f4)
previous=$(cat .github/assets/remote.txt | cut -d/ -f4-5)
echo "$(git remote get-url origin)" > .github/assets/remote.txt
updated=$(cat .github/assets/remote.txt | cut -d/ -f4-5)
updated_user=$(cat .github/assets/remote.txt | cut -d/ -f4)
# Update references to remote (if applicable)
find .github/ -type f | xargs sed -i "s@$previous@$updated@g"
find .github/ -type f | xargs sed -i "s@$previous_user@$updated_user@g"
# Commit sync or open pr. Overwrite any changes made to sync.yml!
cp ~/sync.yml ./.github/workflows/sync.yml
echo "::endgroup::"
echo "::group::Sync"
# Check if this is a new template
git rev-parse --verify origin/main || {
sed -i '/#examples\s*-/,/\/examples\s*-/{/^#/!{/^\$/!d;};}' ./.github/README.md
}
git add --all
git commit -am "♻️" || echo "resolved"
# if this failed you probably didn't make workflow changes on template
git push
# if main doesn't exist we should make it (new template)
git rev-parse --verify origin/main || {
git checkout -b main && git push origin main;
ERROR=$(gh issue create -a '${{ github.actor }}' -t "finish setting up template" -F ./.github/template_todo.md 2>&1) || {
# If a "403" is in the output, then perform the following commands
if [[ -n "$ERROR" ]] && echo "$ERROR" | grep -q "403"; then
cat .github/workflow-setup.md >> $GITHUB_STEP_SUMMARY
echo "# Auth probz" >> $GITHUB_STEP_SUMMARY
fi
echo "\n---" >> $GITHUB_STEP_SUMMARY
echo "the raw error: $ERROR" >> $GITHUB_STEP_SUMMARY
exit 1 # make the script fail
}
}
echo "::endgroup::"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: sync-back
run: |
cp -r .github ~/github
git checkout main
rm -rf .github
cp -r ~/github .github
git add --all
git commit -am "♻️" && git push || echo "resolved"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}