Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflows/scheduled: improve coverage of scheduled online checks #192485

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 57 additions & 19 deletions .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ concurrency:
group: scheduled
cancel-in-progress: true

permissions:
issues: write
permissions: {}

env:
GH_NO_UPDATE_NOTIFIER: 1
GH_PROMPT_DISABLED: 1
GH_REPO: ${{ github.repository }}
REPORTING_ISSUE: 139929
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

jobs:
create_matrix:
Expand All @@ -31,7 +37,6 @@ jobs:
json: ${{ steps.matrix.outputs.json }}
env:
TEST_COUNT: 50
TAP: homebrew/core
steps:
- name: Set up Homebrew
id: set-up-homebrew
Expand All @@ -43,33 +48,68 @@ jobs:

- name: Generate matrix
id: matrix
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
run: |
formula="$(find "$(brew --repo "${TAP}")/Formula" -type f | shuf -n "${TEST_COUNT}" | xargs -I{} basename {} .rb)"
# shellcheck disable=SC2086
# Index all formulae so that we test (n ranges from 0 to TEST_COUNT - 1):
# - formulae 0, 365, 630,..., 0 + 365 * n,... on the first day of the year
# - formulae 1, 366, 631,..., 1 + 365 * n,... on the second day of the year
# - formulae 2, 367, 632,..., 2 + 365 * n,... on the third day of the year
# - ...
# This works fine as long as we have fewer than 365 * TEST_COUNT formulae.
carlocab marked this conversation as resolved.
Show resolved Hide resolved
mapfile -t formulae < <(find Formula -type f -execdir basename -s '.rb' {} + | sort)
carlocab marked this conversation as resolved.
Show resolved Hide resolved
formulae_count="${#formulae[@]}"

DAYS_PER_YEAR=365
if (( formulae_count > DAYS_PER_YEAR * TEST_COUNT )); then
echo "::error ::Too many formulae (${formulae_count})! Adjust TEST_COUNT to a number greater than ${TEST_COUNT}."
exit 1
fi

day="$(date +%j)"
testing_formulae=()
for (( i=0; i < TEST_COUNT; i++ )); do
index="$(( (day + i * DAYS_PER_YEAR - 1) % formulae_count ))"
testing_formulae+=("${formulae[${index}]}")
done

json="$(
brew info --json=v2 $formula |
jq --compact-output '[.formulae[] | select(.deprecated == false and .disabled == false) | .name]'
brew info --json=v2 "${testing_formulae[@]}" |
jq --compact-output '[.formulae[] | select(.deprecated or .disabled | not) | .name]'
)"
echo "json=${json}" >> "$GITHUB_OUTPUT"

comment_on_failure:
needs: create_matrix
if: needs.create_matrix.result == 'failure'
runs-on: ubuntu-latest
permissions:
issues: write
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Post comment on failure
run: |
gh issue comment "$REPORTING_ISSUE" \
--body "\`create_matrix\` job failed. Check $RUN_URL" \
--repo "$GITHUB_REPOSITORY"

audit_online:
if: startsWith( github.repository, 'Homebrew/' )
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
container:
image: ghcr.io/homebrew/ubuntu22.04:master
permissions:
issues: write
needs: create_matrix
name: "Online check (${{ matrix.os }}): ${{ matrix.formula }}"
name: "Online check: ${{ matrix.formula }}"
env:
HOMEBREW_GITHUB_API_TOKEN: "${{ github.token }}"
GH_TOKEN: "${{ github.token }}"
REPORTING_ISSUE: 139929
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
FORMULA: ${{ matrix.formula }}
strategy:
fail-fast: false
matrix:
formula: ${{ fromJson(needs.create_matrix.outputs.json) }}
os: [ubuntu-22.04]
steps:
- name: Set up Homebrew
id: set-up-homebrew
Expand All @@ -81,35 +121,33 @@ jobs:

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

- name: Report online issues
if: ${{ failure() && steps.archived.conclusion == 'failure' }}
if: failure() && steps.archived.conclusion == 'failure'
run: |
gh issue comment "$REPORTING_ISSUE" \
--body "$FORMULA should be archived. Check $RUN_URL" \
--repo "$GITHUB_REPOSITORY"

- name: Check formula for unavailable homepage.
id: homepage
if: matrix.os != 'macos-latest'
run: brew audit --online --skip-style --only homepage "$FORMULA"

- name: Report homepage issues
if: ${{ failure() && steps.homepage.conclusion == 'failure' }}
if: failure() && steps.homepage.conclusion == 'failure'
run: |
gh issue comment "$REPORTING_ISSUE" \
--body "$FORMULA has homepage issues. Check $RUN_URL" \
--repo "$GITHUB_REPOSITORY"

- name: Check formula for missing sources.
id: fetch
if: matrix.os != 'macos-latest'
run: brew fetch -s "$FORMULA"
if: always() && steps.archived.conclusion != 'failure'
run: brew fetch --build-from-source "$FORMULA"

- name: Report fetch issues
if: ${{ failure() && steps.fetch.conclusion == 'failure' }}
if: failure() && steps.fetch.conclusion == 'failure'
run: |
gh issue comment "$REPORTING_ISSUE" \
--body "$FORMULA source has problems. Check $RUN_URL" \
Expand Down
Loading