-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (106 loc) · 4.45 KB
/
sync-klipper-mirror.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Klipper fork sync
on:
schedule:
- cron: "0 */3 * * ?"
workflow_dispatch:
jobs:
sync_repo:
runs-on: ubuntu-latest
outputs:
DID_REBASE: ${{ steps.check_if_head_present.outputs.REF_IS_IN_BRANCH == 'false' }}
steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_PRIVKEY }}
owner: Laikulo
repositories: "klipper"
- name: Sync klipper fork master branch
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
run: gh repo sync Laikulo/klipper -b master
- name: Get current upstream head
id: get_upstream_head
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
echo "upstream_head=$(git ls-remote https://github.com/Klipper3d/klipper.git master | cut -f 1)" >> "$GITHUB_OUTPUT"
- name: Checkout modified workbranch
uses: actions/checkout@v4
with:
repository: 'Laikulo/klipper'
ref: 'laikulo-devel'
token: ${{ steps.generate_token.outputs.token }}
path: klipper
fetch-depth: 0
- name: Check if upstream head is in forked work branch
id: check_if_head_present
env:
REF_TO_FIND: ${{ steps.get_upstream_head.outputs.upstream_head }}
run: |
cd "$GITHUB_WORKSPACE/klipper"
branch_list="$(git branch --contains "$REF_TO_FIND" laikulo-devel 2>/dev/null)"
if [[ $branch_list ]]; then
RETVAL=true
else
RETVAL=false
fi
echo "REF_IS_IN_BRANCH=${RETVAL}" | tee -a "$GITHUB_OUTPUT"
- name: Rebase laikulo branch
if: ${{ steps.check_if_head_present.outputs.REF_IS_IN_BRANCH == 'false' }}
run: |
cd "$GITHUB_WORKSPACE/klipper"
git config user.name "Klippy-Tools-Bot"
git config user.email "[email protected]"
git fetch https://github.com/Klipper3d/klipper.git master
git rebase FETCH_HEAD
- name: Push rebased branch back
if: ${{ steps.check_if_head_present.outputs.REF_IS_IN_BRANCH == 'false' }}
run: |
cd "$GITHUB_WORKSPACE/klipper"
git push -f
trigger_repogen:
needs:
- sync_repo
if: ${{ needs.sync_repo.outputs.DID_REBASE == 'true' }}
uses: ./.github/workflows/generate-repo.yml
secrets: inherit
trigger_factory:
runs-on: ubuntu-latest
needs:
- sync_repo
- trigger_repogen
if: ${{ needs.sync_repo.outputs.DID_REBASE == 'true' }}
steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_PRIVKEY }}
owner: Laikulo
repositories: "Klipper-firmware"
- name: Get latest head of klipper fork
id: get_klipper_fork
run: |
tee -a <<<"KLIPPER_FORK_HEAD=$(git ls-remote https://github.com/Laikulo/klipper.git laikulo-devel | cut -f1)" "$GITHUB_OUTPUT"
- name: Trigger factory
env:
KLIPPER_FORK_HEAD: ${{ steps.get_klipper_fork.outputs.KLIPPER_FORK_HEAD }}
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
gh workflow run --repo Laikulo/Klipper-firmware docker-publish-factory.yml -f klipperVer="$KLIPPER_FORK_HEAD" -f klipperRepo="https://github.com/Laikulo/klipper.git" -f tagName="${KLIPPER_FORK_HEAD::7}"
sleep 4
RUN_NUMBER="$(gh run --repo Laikulo/klipper-firmware list -e workflow_dispatch --limit 1 -w docker-publish-factory.yml --json databaseId --template '{{ printf "%.0f" ((index . 0).databaseId) }}')"
gh run --repo Laikulo/Klipper-firmware watch "$RUN_NUMBER"
- name: Trigger firmware builds
env:
KLIPPER_FORK_HEAD: ${{ steps.get_klipper_fork.outputs.KLIPPER_FORK_HEAD }}
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
gh workflow run --repo Laikulo/Klipper-firmware factory-all.yml -f factoryTag="${KLIPPER_FORK_HEAD::7}"
sleep 4
RUN_NUMBER="$(gh run --repo Laikulo/klipper-firmware list -e workflow_dispatch --limit 1 -w factory-all.yml --json databaseId --template '{{ printf "%.0f" ((index . 0).databaseId) }}')"
gh run --repo Laikulo/Klipper-firmware watch "$RUN_NUMBER"