Skip to content

self-update

self-update #89

Workflow file for this run

name: self-update
permissions:
actions: write
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: ensure token
run: |
if [[ -z "$GH_SELF_UPDATE_TOKEN" ]]; then
echo "::error::GH_SELF_UPDATE_TOKEN secret is not set. Disabling this workflow for now. If you want your fork to update itself automatically, please set this secret and re-enable this workflow."
gh -R "$GITHUB_REPOSITORY" workflow disable "$GITHUB_WORKFLOW"
exit 1
fi
env:
GH_SELF_UPDATE_TOKEN: ${{ secrets.GH_SELF_UPDATE_TOKEN }}
GH_TOKEN: ${{ github.token }}
- name: get upstream repo
id: upstream
run: |
upstream="$(gh api /repos/"$REPO" | jq -er .parent.clone_url)"
echo "upstream=$upstream" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
- name: configure git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: clone repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_SELF_UPDATE_TOKEN }}
fetch-depth: 0
- name: add upstream remote
run: |
git remote add upstream "$UPSTREAM"
git fetch upstream HEAD:upstream/HEAD
env:
UPSTREAM: ${{ steps.upstream.outputs.upstream }}
- name: rebase
run: git rebase upstream/HEAD
- name: push
run: git push --force-with-lease