-
Notifications
You must be signed in to change notification settings - Fork 13
94 lines (81 loc) · 2.57 KB
/
fork-sync.yaml
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
#
# 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"