Skip to content

Fork Sync

Fork Sync #4243

Workflow file for this run

#
# Author: Hari Sekhon
# Date: Tue Feb 4 09:53:28 2020 +0000
#
# vim:ts=2:sts=2:sw=2:et
#
# https://github.com/HariSekhon/GitHub-Actions
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback
#
# https://www.linkedin.com/in/HariSekhon
#
# ============================================================================ #
# G i t H u b F o r k R e p o S y n c
# ============================================================================ #
# This has the advantage of not triggering GitHub Actions workflows upon updates, and is fast
#
# The disadvantage is that updates to the default branch happened without much auditing such as happens with PRs
#
# Run just before fork-update-pr.yaml if you only want environment branch updates audited via PRs
---
name: Fork Sync
on:
workflow_call:
inputs:
debug:
type: string
required: false
default: false
workflow_dispatch:
inputs:
debug:
type: boolean
required: false
default: false
schedule:
- cron: '0 */3 * * *'
permissions:
contents: write
defaults:
run:
shell: bash -euxo pipefail {0}
env:
GH_TOKEN: ${{ github.token }}
GH_NO_UPDATE_NOTIFIER: 1
DEBUG: ${{ inputs.debug == true || github.event.inputs.debug == 'true' || '' }}
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false # killing this part way through may leave PRs without auto-merging
jobs:
sync:
name: Sync
# github.event.repository.fork isn't available in scheduled workflows
if: |
github.repository_owner != 'HariSekhon' &&
(
github.event_name == 'schedule' ||
( github.ref_type == 'branch' && github.ref_name == github.event.repository.default_branch )
)
runs-on: ubuntu-latest
steps:
- name: Environment
run: env | sort
# not needed since everything is done via the GitHub API
#- uses: actions/checkout@v3
- name: GH CLI auth status
run: |
gh config set prompt disabled
gh auth status
# because github.event.repository context is missing from scheduled workflows:
#
# https://github.com/github/feedback/discussions/12269
#
- name: Generate environment variable IS_FORK
run: |
IS_FORK="$(gh api "/repos/$GITHUB_REPOSITORY" -q '.fork')"
echo "IS_FORK=$IS_FORK" >> "$GITHUB_ENV"
- name: Sync Fork
if: github.event.repository.fork == true || env.IS_FORK == 'true'
run: |
gh repo sync "$GITHUB_REPOSITORY"