Federated via graft
1.7 kB
33 lines
1name: push-github
2on:
3 push:
4 branches: [main]
5
6jobs:
7 mirror:
8 runs-on: linux-host
9 steps:
10 - name: clone and push to GitHub, notify f1 on failure
11 run: |
12 set +e
13 rm -rf /tmp/graft-mirror
14 git clone --bare https://f1.cyberwild.org/forgeadmin/graft.git /tmp/graft-mirror
15 cd /tmp/graft-mirror
16 git push "https://x-access-token:${{ secrets.GH_PUSH_TOKEN }}@github.com/jeanbaptiste/graft.git" main:main
17 PUSH_STATUS=$?
18 cd /
19 rm -rf /tmp/graft-mirror
20
21 if [ "$PUSH_STATUS" -ne 0 ]; then
22 echo "push to GitHub failed (status $PUSH_STATUS) — notifying f1"
23 BODY=$(python3 -c "import json; print(json.dumps({'title': 'CI: push to GitHub failed (run ${GITHUB_RUN_NUMBER})', 'body': 'push-github failed to mirror main to GitHub, exit status $PUSH_STATUS. Most likely someone pushed directly to GitHub, causing a divergence a plain git push refuses to overwrite.\n\nResolve manually: compare https://github.com/jeanbaptiste/graft and https://f1.cyberwild.org/forgeadmin/graft/src/branch/main, reconcile, then push.\n\nRun: https://f1.cyberwild.org/forgeadmin/graft/actions/runs/${GITHUB_RUN_NUMBER}'}))")
24 curl -s -X POST \
25 -H "Authorization: token ${{ secrets.F1_ISSUE_TOKEN }}" \
26 -H "Content-Type: application/json" \
27 --data "$BODY" \
28 "https://f1.cyberwild.org/api/v1/repos/forgeadmin/graft/issues" \
29 -o /tmp/issue-create-resp.json -w "issue create HTTP: %{http_code}\n"
30 cat /tmp/issue-create-resp.json
31 exit 1
32 fi
33 echo "pushed to GitHub ok"