-
Notifications
You must be signed in to change notification settings - Fork 70
161 lines (145 loc) · 5.42 KB
/
sync-shared-config.yml
File metadata and controls
161 lines (145 loc) · 5.42 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Sync shared configurations
on:
push:
branches:
- main
pull_request:
schedule:
# This should be run after dependabot.yml for this repository (Monday)
# and before dependabot.yml for synced repositories (Friday).
# This maximises the chance of a single sync per week handling both any
# changes and any dependabot updates.
- cron: "0 8 * * 3" # Every Wednesday at 8 AM
workflow_dispatch:
permissions:
contents: read
defaults:
run:
shell: bash -xeuo pipefail {0}
concurrency:
group: "sync-shared-config-${{ github.ref }}"
cancel-in-progress: true
jobs:
generate-matrix:
runs-on: ubuntu-slim
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
steps:
- name: Generate matrix
id: generate-matrix
env:
SKIP_PRIVATE: ${{ github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' }}
run: |
repositories=(
Homebrew/.github
Homebrew/actions
Homebrew/brew
Homebrew/brew-pip-audit
Homebrew/brew.sh
Homebrew/ci-orchestrator-private
Homebrew/discussions
Homebrew/formulae.brew.sh
Homebrew/glibc-bootstrap
Homebrew/homebrew-cask
Homebrew/homebrew-core
Homebrew/install
Homebrew/private
Homebrew/ruby-macho
Homebrew/homebrew-brew-vulns
)
if [[ "${SKIP_PRIVATE}" == true ]]; then
read -r -a repositories <<< "${repositories[@]//*private}"
fi
echo "matrix=$(jq -cn '$ARGS.positional' --args -- "${repositories[@]}")" >> "${GITHUB_OUTPUT}"
sync:
if: github.repository == 'Homebrew/.github'
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
matrix:
repo: ${{fromJson(needs.generate-matrix.outputs.matrix)}}
fail-fast: false
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@main
- name: Set up Homebrew portable Ruby
uses: Homebrew/actions/setup-ruby@main
with:
portable-ruby: true
- name: Clone source repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- run: brew install-bundler-gems --groups=style
if: matrix.repo == 'Homebrew/.github'
env:
HOMEBREW_DEVELOPER: 1
- run: brew style .github/actions/sync/*.rb
if: matrix.repo == 'Homebrew/.github'
env:
HOMEBREW_DEVELOPER: 1
- name: Clone target repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: ${{ matrix.repo }}
path: target/${{ matrix.repo }}
token: ${{ secrets.HOMEBREW_DOTGITHUB_WORKFLOW_TOKEN || github.token }}
# Intentioanlly persisted to allow `git push` below.
persist-credentials: true
- name: Configure Git user
uses: Homebrew/actions/git-user-config@main
with:
username: BrewTestBot
- name: Set up SSH commit signing
if: github.event_name != 'pull_request' || github.actor != 'dependabot[bot]'
uses: Homebrew/actions/setup-commit-signing@main
with:
signing_key: ${{ secrets.BREWTESTBOT_SSH_SIGNING_KEY }}
- name: Sync initial Ruby version
run: cp /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/.ruby-version .
- name: Detect changes
id: detect_changes
env:
TARGET: target/${{ matrix.repo }}
run: ./.github/actions/sync/shared-config.rb "${TARGET}" '/home/linuxbrew/.linuxbrew/Homebrew'
- name: Create pull request
if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && steps.detect_changes.outputs.pull_request == 'true'
run: |
cd "target/$GH_REPO"
git checkout -b sync-shared-config
# Stagger network calls over the next 10 minutes to minimise errors.
sleep "$(( RANDOM % 60 * 10 ))"
if gh api \
-X GET \
--header 'Accept: application/vnd.github+json' \
--header 'X-GitHub-Api-Version: 2022-11-28' \
"/repos/${GH_REPO}/pulls" \
-f head=Homebrew:sync-shared-config \
-f state=open |
jq --exit-status 'length == 0'
then
git push --set-upstream --force origin sync-shared-config
# We don't want backticks to be expanded.
# shellcheck disable=SC2016
gh pr create --head sync-shared-config --title "Synchronize shared configuration" --body 'This pull request was created automatically by the [`sync-shared-config`](https://github.com/Homebrew/.github/blob/HEAD/.github/actions/sync/shared-config.rb) workflow.'
else
git fetch origin sync-shared-config
if ! git diff --no-ext-diff --quiet --exit-code origin/sync-shared-config
then
git push --force origin sync-shared-config
fi
fi
env:
GH_REPO: ${{ matrix.repo }}
GH_TOKEN: ${{ secrets.HOMEBREW_DOTGITHUB_WORKFLOW_TOKEN }}
conclusion:
needs: sync
runs-on: ubuntu-slim
if: always()
steps:
- name: Result
env:
RESULT: ${{ needs.sync.result }}
run: |
[[ "${RESULT}" == success ]]