Skip to content

Sync fork

Sync fork #904

Workflow file for this run

name: Sync fork
on:
schedule:
- cron: "41 19 * * *"
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
strategy:
matrix:
branch:
- main
- release/v0.19
timeout-minutes: 5
steps:
- name: Checkout current fork HEAD
uses: actions/checkout@v4
with:
fetch-depth: 0
show-progress: false
ref: ${{ matrix.branch }}
- name: Set up upstream git remote
run: |
upstream="$(gh repo view "${{ github.repository }}" --json parent --jq '.parent.owner.login + "/" + .parent.name')"
echo "upstream=$upstream"
git remote add upstream "https://github.com/$upstream.git"
git fetch upstream "${{ matrix.branch }}"
git fetch upstream --tags
env:
GH_TOKEN: ${{ github.token }}
- name: Determine number of missing commits from usptream
id: check-missing-commits
run: |
upstream_commit_count="$(git rev-list --count "${{ matrix.branch }}..upstream/${{ matrix.branch }}")"
echo "commit-count=$upstream_commit_count" | tee -a "$GITHUB_OUTPUT"
- name: Rebase and push
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git rebase --committer-date-is-author-date "upstream/${{ matrix.branch }}"
git push --force
git push --force --tags
if: >-
fromJSON(steps.check-missing-commits.outputs.commit-count) > 0
# GitHub doesn't trigger push events when commits are pushed with github.token
- name: Trigger builds
uses: benc-uk/workflow-dispatch@e2e5e9a103e331dad343f381a29e654aea3cf8fc # v1.2.4
with:
ref: ${{ matrix.branch }}
workflow: build-images-fork.yml
if: >-
fromJSON(steps.check-missing-commits.outputs.commit-count) > 0
- name: Notify about CI failure
if: ${{ failure() }}
run: >-
curl
-s -o /dev/null
-H "Title: ${{ github.repository }} workflow failed"
-H "Content-Type: text/plain"
-d $'Repo: ${{ github.repository }}\nWorkflow: ${{ github.workflow }}\nCommit: ${{ github.sha }}\nRef: ${{ github.ref }}\nURL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
"$NTFY_URL"
env:
NTFY_URL: ${{ secrets.NTFY_URL }}