Skip to content

Commit 741b0b6

Browse files
authored
Merge pull request #192485 from Homebrew/systematic-schedule
workflows/scheduled: improve coverage of scheduled online checks
2 parents e09d3b9 + b1a5e28 commit 741b0b6

File tree

1 file changed

+57
-19
lines changed

1 file changed

+57
-19
lines changed

.github/workflows/scheduled.yml

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ concurrency:
1818
group: scheduled
1919
cancel-in-progress: true
2020

21-
permissions:
22-
issues: write
21+
permissions: {}
22+
23+
env:
24+
GH_NO_UPDATE_NOTIFIER: 1
25+
GH_PROMPT_DISABLED: 1
26+
GH_REPO: ${{ github.repository }}
27+
REPORTING_ISSUE: 139929
28+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
2329

2430
jobs:
2531
create_matrix:
@@ -31,7 +37,6 @@ jobs:
3137
json: ${{ steps.matrix.outputs.json }}
3238
env:
3339
TEST_COUNT: 50
34-
TAP: homebrew/core
3540
steps:
3641
- name: Set up Homebrew
3742
id: set-up-homebrew
@@ -43,33 +48,68 @@ jobs:
4348

4449
- name: Generate matrix
4550
id: matrix
51+
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
4652
run: |
47-
formula="$(find "$(brew --repo "${TAP}")/Formula" -type f | shuf -n "${TEST_COUNT}" | xargs -I{} basename {} .rb)"
48-
# shellcheck disable=SC2086
53+
# Index all formulae so that we test (n ranges from 0 to TEST_COUNT - 1):
54+
# - formulae 0, 365, 630,..., 0 + 365 * n,... on the first day of the year
55+
# - formulae 1, 366, 631,..., 1 + 365 * n,... on the second day of the year
56+
# - formulae 2, 367, 632,..., 2 + 365 * n,... on the third day of the year
57+
# - ...
58+
# This works fine as long as we have fewer than 365 * TEST_COUNT formulae.
59+
mapfile -t formulae < <(find Formula -type f -execdir basename -s '.rb' {} + | sort)
60+
formulae_count="${#formulae[@]}"
61+
62+
DAYS_PER_YEAR=365
63+
if (( formulae_count > DAYS_PER_YEAR * TEST_COUNT )); then
64+
echo "::error ::Too many formulae (${formulae_count})! Adjust TEST_COUNT to a number greater than ${TEST_COUNT}."
65+
exit 1
66+
fi
67+
68+
day="$(date +%j)"
69+
testing_formulae=()
70+
for (( i=0; i < TEST_COUNT; i++ )); do
71+
index="$(( (day + i * DAYS_PER_YEAR - 1) % formulae_count ))"
72+
testing_formulae+=("${formulae[${index}]}")
73+
done
74+
4975
json="$(
50-
brew info --json=v2 $formula |
51-
jq --compact-output '[.formulae[] | select(.deprecated == false and .disabled == false) | .name]'
76+
brew info --json=v2 "${testing_formulae[@]}" |
77+
jq --compact-output '[.formulae[] | select(.deprecated or .disabled | not) | .name]'
5278
)"
5379
echo "json=${json}" >> "$GITHUB_OUTPUT"
5480
81+
comment_on_failure:
82+
needs: create_matrix
83+
if: needs.create_matrix.result == 'failure'
84+
runs-on: ubuntu-latest
85+
permissions:
86+
issues: write
87+
env:
88+
GH_TOKEN: ${{ github.token }}
89+
steps:
90+
- name: Post comment on failure
91+
run: |
92+
gh issue comment "$REPORTING_ISSUE" \
93+
--body "\`create_matrix\` job failed. Check $RUN_URL" \
94+
--repo "$GITHUB_REPOSITORY"
95+
5596
audit_online:
5697
if: startsWith( github.repository, 'Homebrew/' )
57-
runs-on: ${{ matrix.os }}
98+
runs-on: ubuntu-latest
5899
container:
59100
image: ghcr.io/homebrew/ubuntu22.04:master
101+
permissions:
102+
issues: write
60103
needs: create_matrix
61-
name: "Online check (${{ matrix.os }}): ${{ matrix.formula }}"
104+
name: "Online check: ${{ matrix.formula }}"
62105
env:
63106
HOMEBREW_GITHUB_API_TOKEN: "${{ github.token }}"
64107
GH_TOKEN: "${{ github.token }}"
65-
REPORTING_ISSUE: 139929
66-
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
67108
FORMULA: ${{ matrix.formula }}
68109
strategy:
69110
fail-fast: false
70111
matrix:
71112
formula: ${{ fromJson(needs.create_matrix.outputs.json) }}
72-
os: [ubuntu-22.04]
73113
steps:
74114
- name: Set up Homebrew
75115
id: set-up-homebrew
@@ -81,35 +121,33 @@ jobs:
81121

82122
- name: Check formula source is not archived.
83123
id: archived
84-
if: matrix.os != 'macos-latest'
85124
run: brew audit --online --skip-style --only github_repository_archived,gitlab_repository_archived "$FORMULA"
86125

87126
- name: Report online issues
88-
if: ${{ failure() && steps.archived.conclusion == 'failure' }}
127+
if: failure() && steps.archived.conclusion == 'failure'
89128
run: |
90129
gh issue comment "$REPORTING_ISSUE" \
91130
--body "$FORMULA should be archived. Check $RUN_URL" \
92131
--repo "$GITHUB_REPOSITORY"
93132
94133
- name: Check formula for unavailable homepage.
95134
id: homepage
96-
if: matrix.os != 'macos-latest'
97135
run: brew audit --online --skip-style --only homepage "$FORMULA"
98136

99137
- name: Report homepage issues
100-
if: ${{ failure() && steps.homepage.conclusion == 'failure' }}
138+
if: failure() && steps.homepage.conclusion == 'failure'
101139
run: |
102140
gh issue comment "$REPORTING_ISSUE" \
103141
--body "$FORMULA has homepage issues. Check $RUN_URL" \
104142
--repo "$GITHUB_REPOSITORY"
105143
106144
- name: Check formula for missing sources.
107145
id: fetch
108-
if: matrix.os != 'macos-latest'
109-
run: brew fetch -s "$FORMULA"
146+
if: always() && steps.archived.conclusion != 'failure'
147+
run: brew fetch --build-from-source "$FORMULA"
110148

111149
- name: Report fetch issues
112-
if: ${{ failure() && steps.fetch.conclusion == 'failure' }}
150+
if: failure() && steps.fetch.conclusion == 'failure'
113151
run: |
114152
gh issue comment "$REPORTING_ISSUE" \
115153
--body "$FORMULA source has problems. Check $RUN_URL" \

0 commit comments

Comments
 (0)