Update and Build Formulae #254
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update and Build Formulae | |
on: | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: '0 0 * * *' | |
repository_dispatch: | |
workflow_dispatch: | |
pull_request: | |
env: | |
HOMEBREW_DEVELOPER: 1 | |
HOMEBREW_GITHUB_ACTIONS: 1 | |
HOMEBREW_NO_AUTO_UPDATE: 1 | |
HOMEBREW_CHANGE_ARCH_TO_ARM: 1 | |
concurrency: | |
group: "build-${{ github.ref }}" | |
cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
jobs: | |
tap-syntax: | |
if: "!contains(github.event.head_commit.message, 'skip-build')" | |
runs-on: ubuntu-latest | |
env: | |
HOMEBREW_FORCE_HOMEBREW_ON_LINUX: 1 | |
outputs: | |
testing_formulae: ${{ steps.formulae-detect.outputs.testing_formulae }} | |
added_formulae: ${{ steps.formulae-detect.outputs.added_formulae }} | |
deleted_formulae: ${{ steps.formulae-detect.outputs.deleted_formulae }} | |
steps: | |
- name: Set up Homebrew | |
id: set-up-homebrew | |
uses: Homebrew/actions/setup-homebrew@master | |
- name: Cache Bundler RubyGems | |
uses: actions/cache@v1 | |
with: | |
path: ${{ steps.set-up-homebrew.outputs.gems-path }} | |
key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }} | |
restore-keys: ${{ runner.os }}-rubygems- | |
- name: Install Bundler RubyGems | |
run: brew install-bundler-gems | |
- run: brew test-bot --only-tap-syntax | |
- run: brew test-bot --only-formulae-detect | |
if: github.event_name == 'pull_request' | |
id: formulae-detect | |
create-pr: | |
if: github.event_name != 'pull_request' && !contains(github.event.head_commit.message, 'skip-build') | |
needs: tap-syntax | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Patch formula | |
env: | |
GITHUB_MESSAGE: ${{ github.event.head_commit.message || github.event.inputs.github_message }} | |
run: bash ./.github/scripts/edit.sh | |
- name: Create Pull Request | |
id: cpr | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
token: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }} | |
commit-message: Update | |
committer: transip-bot <[email protected]> | |
author: transip-bot <[email protected]> | |
signoff: false | |
base: main | |
branch: update | |
branch-suffix: short-commit-hash | |
delete-branch: true | |
title: 'Update' | |
body: | | |
Build | |
labels: automated-pr | |
assignees: xvilo | |
draft: false | |
- name: Check outputs | |
run: | | |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" | |
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" | |
set-environment: | |
if: github.event_name == 'pull_request' && !contains(github.event.head_commit.message, 'skip-build') | |
runs-on: ubuntu-latest | |
needs: tap-syntax | |
outputs: | |
syntax-only: ${{ steps.check-labels.outputs.syntax-only }} | |
linux-runner: ${{ steps.check-labels.outputs.linux-runner }} | |
fail-fast: ${{ steps.check-labels.outputs.fail-fast }} | |
test-dependents: ${{ steps.check-labels.outputs.test-dependents }} | |
timeout-minutes: ${{ steps.check-labels.outputs.timeout-minutes }} | |
container: ${{ steps.check-labels.outputs.container }} | |
test-bot-formulae-args: ${{ steps.check-labels.outputs.test-bot-formulae-args }} | |
test-bot-dependents-args: ${{ steps.check-labels.outputs.test-bot-dependents-args }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Check for CI labels | |
id: check-labels | |
uses: actions/github-script@v3 | |
env: | |
SCRIPTS_PATH: .github/scripts | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const path = require('path') | |
const script = require(path.resolve(`${process.env.SCRIPTS_PATH}/environment.js`)) | |
const formula_detect = { | |
testing_formulae: '${{needs.tap-syntax.outputs.testing_formulae}}', | |
added_formulae: '${{needs.tap-syntax.outputs.added_formulae}}', | |
deleted_formulae: '${{needs.tap-syntax.outputs.deleted_formulae}}' | |
} | |
try { | |
await script({github, context, core}, formula_detect) | |
} catch (error) { | |
console.error(error); | |
} | |
build-formula: | |
needs: set-environment | |
if: github.event_name == 'pull_request' && !contains(github.event.head_commit.message, 'skip-build') | |
strategy: | |
matrix: | |
include: | |
- runner: 'macos-12-arm64' | |
- runner: 'macos-11-arm64' | |
- runner: 'macos-12' | |
- runner: 'macos-11' | |
- runner: 'macos-10.15' | |
- runner: ${{needs.set-environment.outputs.linux-runner}} | |
container: ${{fromJson(needs.set-environment.outputs.container)}} | |
workdir: /github/home | |
timeout: 4320 | |
fail-fast: ${{fromJson(needs.set-environment.outputs.fail-fast)}} | |
runs-on: ${{matrix.runner}} | |
container: ${{matrix.container}} | |
timeout-minutes: ${{ matrix.timeout || fromJson(needs.set-environment.outputs.timeout-minutes) }} | |
defaults: | |
run: | |
shell: /bin/bash -e {0} | |
working-directory: ${{matrix.workdir || github.workspace}} | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
HOMEBREW_GITHUB_API_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
steps: | |
- name: Set environment variables | |
if: runner.os == 'macOS' | |
run: echo 'PATH=/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin' >> $GITHUB_ENV | |
- name: Prepare Container | |
if: runner.os == 'Linux' | |
run: | | |
sudo chmod 777 ${{matrix.workdir || github.workspace}} | |
brew update | |
- name: Set up Homebrew | |
id: set-up-homebrew | |
uses: Homebrew/actions/setup-homebrew@master | |
- name: Setup Xcode | |
if: runner.os == 'macOS' | |
run: | | |
if [ "${{ matrix.runner }}" = "macos-10.15" ]; then | |
sudo xcode-select -s /Applications/Xcode_11.7.app || exit 1 | |
else | |
latest_stable_xcode_path="$(find -E /Applications -maxdepth 1 -regex '.*Xcode_[0-9]+.[0-9]+.app' | sort -V | tail -1)" | |
sudo xcode-select -s "$latest_stable_xcode_path" || exit 1 | |
fi | |
- run: brew test-bot --only-cleanup-before | |
- run: brew test-bot --only-setup | |
- name: Run brew test-bot ${{ needs.set-environment.outputs.test-bot-formulae-args }} | |
id: brew-test-bot-formulae | |
run: | | |
mkdir bottles | |
cd bottles | |
brew test-bot ${{ needs.set-environment.outputs.test-bot-formulae-args }} | |
- name: Failures summary for brew test-bot ${{ needs.set-environment.outputs.test-bot-formulae-args }} | |
if: always() | |
run: | | |
touch bottles/steps_output.txt | |
cat bottles/steps_output.txt | |
rm bottles/steps_output.txt | |
- name: Output brew linkage result | |
if: always() | |
run: | | |
cat bottles/linkage_output.txt | |
rm bottles/linkage_output.txt | |
- name: Output brew bottle result | |
if: always() | |
run: | | |
cat bottles/bottle_output.txt | |
rm bottles/bottle_output.txt | |
- name: Run brew test-bot ${{ needs.set-environment.outputs.test-bot-dependents-args }} --skipped-or-failed-formulae=${{ steps.brew-test-bot-formulae.outputs.skipped_or_failed_formulae }} | |
if: ${{(success() || failure()) && fromJson(needs.set-environment.outputs.test-dependents)}} | |
run: | | |
cd bottles | |
brew test-bot ${{ needs.set-environment.outputs.test-bot-dependents-args }} --skipped-or-failed-formulae=${{ steps.brew-test-bot-formulae.outputs.skipped_or_failed_formulae }} | |
- name: Failures summary for brew test-bot ${{ needs.set-environment.outputs.test-bot-dependents-args }} --skipped-or-failed-formulae=${{ steps.brew-test-bot-formulae.outputs.skipped_or_failed_formulae }} | |
if: ${{always() && fromJson(needs.set-environment.outputs.test-dependents) == true}} | |
run: | | |
touch bottles/steps_output.txt | |
cat bottles/steps_output.txt | |
rm bottles/steps_output.txt | |
- name: Upload logs | |
if: always() | |
uses: actions/upload-artifact@main | |
with: | |
name: logs-${{ matrix.runner }} | |
path: ${{matrix.workdir || github.workspace}}/bottles/logs | |
- name: Delete logs and home | |
if: always() | |
run: | | |
rm -rvf bottles/logs | |
rm -rvf bottles/home | |
- name: Count bottles | |
id: bottles | |
if: always() | |
run: | | |
cd bottles | |
count=$(ls *.json | wc -l | xargs echo -n) | |
echo "$count bottles" | |
echo "::set-output name=count::$count" | |
failures=$(ls failed/*.json | wc -l | xargs echo -n) | |
echo "$failures failed bottles" | |
echo "::set-output name=failures::$failures" | |
- name: Upload failed bottles | |
if: always() && steps.bottles.outputs.failures > 0 | |
uses: actions/upload-artifact@main | |
with: | |
name: bottles-${{ matrix.runner }} | |
path: ${{matrix.workdir || github.workspace}}/bottles/failed | |
# Must be run before the `Upload bottles` step so that failed | |
# bottles are not included in the `bottles` artifact. | |
- name: Delete failed bottles | |
if: always() | |
run: rm -rvf bottles/failed | |
- name: Upload bottles | |
if: always() && steps.bottles.outputs.count > 0 | |
uses: actions/upload-artifact@main | |
with: | |
name: bottles | |
path: ${{matrix.workdir || github.workspace}}/bottles | |
- name: Post cleanup | |
if: always() | |
run: | | |
brew test-bot --only-cleanup-after | |
rm -rvf bottles | |
if [ -L "$GITHUB_WORKSPACE" ]; then | |
sudo rm -rf "$GITHUB_WORKSPACE" | |
fi | |
label: | |
needs: build-formula | |
if: github.event_name == 'pull_request' && !contains(github.event.head_commit.message, 'skip-build') && github.event.pull_request.user.login == github.repository_owner | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: "Add Label" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: gh pr edit "$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')" --add-label "build-complete" |