homebrew-cask/.github/workflows/ci.yml

240 lines
9.1 KiB
YAML
Raw Normal View History

2019-08-13 10:26:50 +08:00
name: CI
2019-08-13 11:00:51 +08:00
on:
pull_request_target:
types: [synchronize, opened, reopened, labeled, unlabeled]
2019-08-13 10:26:50 +08:00
jobs:
2020-08-13 05:47:11 +08:00
syntax:
name: syntax
runs-on: macos-latest
2019-08-13 10:26:50 +08:00
steps:
2020-08-13 05:47:11 +08:00
- uses: actions/checkout@main
- name: Check out Pull Request
uses: ./.github/actions/checkout_cask_pr
id: checkout_cask_pr
- name: Cache Homebrew Gems
uses: actions/cache@v2
with:
path: ${{ steps.checkout_cask_pr.outputs.homebrew_gems_cache_dir }}
key: homebrew-gems-cache-${{ steps.checkout_cask_pr.outputs.homebrew_gems_cache_id }}
restore-keys: homebrew-gems-cache-
- name: Install Homebrew Gems
run: brew install-bundler-gems
- name: Uninstall third-party taps
run: brew untap adoptopenjdk/openjdk
- name: Run brew cask style
run: brew cask style
- name: Run brew cask audit
run: brew cask audit
if: always()
generate-matrix:
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
runs-on: macos-latest
2020-08-23 03:50:45 +08:00
if: github.event_name == 'pull_request_target' && !contains(github.event.pull_request.labels.*.name, 'syntax-only')
2020-08-13 05:47:11 +08:00
steps:
- uses: actions/checkout@main
- name: Check out Pull Request
uses: ./.github/actions/checkout_cask_pr
id: checkout_cask_pr
- name: Generate CI matrix
id: generate-matrix
run: brew ruby "$(brew --repository homebrew/cask)/cmd/lib/generate-matrix.rb"
working-directory: ${{ steps.checkout_cask_pr.outputs.tap_path }}
test:
name: test (${{ matrix.name }})
needs: generate-matrix
runs-on: macos-latest
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@main
- name: Check out Pull Request
uses: ./.github/actions/checkout_cask_pr
id: checkout_cask_pr
2020-08-11 10:27:12 +08:00
- name: Clean up CI machine
run: |
if ! brew cask ls visual-studio &>/dev/null; then
if ! rm -r '/Applications/Visual Studio.app'; then
echo '::warning::Workaround for Visual Studio is no longer needed.'
fi
fi
2019-08-13 17:02:53 +08:00
2020-07-30 15:20:47 +08:00
- name: Cache Homebrew Gems
uses: actions/cache@v2
with:
2020-08-13 05:47:11 +08:00
path: ${{ steps.checkout_cask_pr.outputs.homebrew_gems_cache_dir }}
key: homebrew-gems-cache-${{ steps.checkout_cask_pr.outputs.homebrew_gems_cache_id }}
2020-08-11 07:41:19 +08:00
restore-keys: homebrew-gems-cache-
2020-08-13 05:47:11 +08:00
2020-07-30 15:20:47 +08:00
- name: Install Homebrew Gems
run: brew install-bundler-gems
2020-08-13 05:47:11 +08:00
- name: Gather cask information
id: info
2020-07-30 15:20:47 +08:00
run: |
2020-08-13 05:47:11 +08:00
brew ruby <<'EOF'
cask = Cask::CaskLoader.load('${{ matrix.cask }}')
2019-08-13 17:02:53 +08:00
2020-08-13 05:47:11 +08:00
was_installed = cask.installed?
manual_installer = cask.artifacts.any? { |artifact|
artifact.is_a?(Cask::Artifact::Installer::ManualInstaller)
}
2020-08-13 05:47:11 +08:00
macos_requirement_satisfied = if macos_requirement = cask.depends_on.macos
macos_requirement.satisfied?
else
true
end
puts "::set-output name=was_installed::#{JSON.generate(was_installed)}"
puts "::set-output name=manual_installer::#{JSON.generate(manual_installer)}"
puts "::set-output name=macos_requirement_satisfied::#{JSON.generate(macos_requirement_satisfied)}"
EOF
working-directory: ${{ matrix.working_directory }}
2020-08-13 05:47:11 +08:00
- name: Run brew cask style ${{ matrix.name }}
2019-08-13 17:02:53 +08:00
run: |
2020-08-13 05:47:11 +08:00
brew cask style '${{ matrix.cask }}' || brew ruby <<'EOF'
path = Pathname('${{ matrix.cask }}')
json = Cask::Cmd::Style.rubocop(path.expand_path, json: true)
json.fetch("files").each do |file|
file.fetch("offenses").each do |o|
line = o.fetch("location").fetch("start_line")
column = o.fetch("location").fetch("start_column")
message = Tty.strip_ansi(o.fetch("message"))
.gsub(/\r/, '%0D')
.gsub(/\n/, '%0A')
.gsub(/]/, '%5D')
.gsub(/;/, '%3B')
puts "::error file=#{path},line=#{line},col=#{column}::#{message}"
end
end
exit 1
EOF
working-directory: ${{ matrix.working_directory }}
- name: Run brew cask audit ${{ matrix.name }}
run: brew cask audit ${{ join(matrix.audit_args, ' ') }} '${{ matrix.cask }}'
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_READ_ONLY_GITHUB_API_TOKEN }}
2020-08-13 05:47:11 +08:00
working-directory: ${{ matrix.working_directory }}
timeout-minutes: 30
- name: Gather dependency information
id: deps
run: |
2020-08-13 05:47:11 +08:00
brew ruby <<'EOF'
require 'cask/cask_loader'
require 'cask/installer'
2020-08-13 05:47:11 +08:00
cask = Cask::CaskLoader.load('${{ matrix.cask }}')
cask_conflicts = cask.conflicts_with&.dig(:cask).to_a.select { |c| Cask::CaskLoader.load(c).installed? }
formula_conflicts = cask.conflicts_with&.dig(:formula).to_a.select { |f| Formula[f].any_version_installed? }
2020-08-13 05:47:11 +08:00
installer = Cask::Installer.new(cask)
cask_and_formula_dependencies = installer.missing_cask_and_formula_dependencies
2020-08-13 05:47:11 +08:00
cask_dependencies = cask_and_formula_dependencies.select { |d| d.is_a?(Cask::Cask) }.map(&:full_name)
formula_dependencies = cask_and_formula_dependencies.select { |d| d.is_a?(Formula) }.map(&:full_name)
puts "::set-output name=cask_conflicts::#{JSON.generate(cask_conflicts)}"
2020-08-13 05:47:11 +08:00
puts "::set-output name=cask_dependencies::#{JSON.generate(cask_dependencies)}"
puts "::set-output name=formula_conflicts::#{JSON.generate(formula_conflicts)}"
2020-08-13 05:47:11 +08:00
puts "::set-output name=formula_dependencies::#{JSON.generate(formula_dependencies)}"
EOF
working-directory: ${{ matrix.working_directory }}
timeout-minutes: 30
- name: Uninstall conflicting formulae
run: |
brew uninstall ${{ join(fromJSON(steps.deps.outputs.formula_conflicts), ' ') }}
working-directory: ${{ matrix.working_directory }}
if: success() && join(fromJSON(steps.deps.outputs.formula_conflicts)) != ''
timeout-minutes: 30
- name: Uninstall conflicting casks
run: |
brew cask uninstall ${{ join(fromJSON(steps.deps.outputs.cask_conflicts), ' ') }}
working-directory: ${{ matrix.working_directory }}
if: success() && join(fromJSON(steps.deps.outputs.cask_conflicts)) != ''
timeout-minutes: 30
2020-08-13 05:47:11 +08:00
- name: Run brew cask zap ${{ matrix.name }}
run: |
brew cask zap '${{ matrix.cask }}'
working-directory: ${{ matrix.working_directory }}
if: fromJSON(steps.info.outputs.was_installed)
timeout-minutes: 30
- name: Take snapshot of installed and running apps and services
id: snapshot
run: |
brew ruby -r "$(brew --repository homebrew/cask)/cmd/lib/check.rb" <<'EOF'
puts "::set-output name=before::#{JSON.generate(Check.all)}"
EOF
- name: Run brew cask install ${{ matrix.name }}
id: install
run: |
brew cask install '${{ matrix.cask }}'
working-directory: ${{ matrix.working_directory }}
if: success() && fromJSON(steps.info.outputs.macos_requirement_satisfied)
timeout-minutes: 30
- name: Run brew cask uninstall ${{ matrix.name }}
run: brew cask uninstall '${{ matrix.cask }}'
working-directory: ${{ matrix.working_directory }}
if: steps.install.outcome == 'success' && !fromJSON(steps.info.outputs.manual_installer)
timeout-minutes: 30
- name: Uninstall formula dependencies
run: |
brew uninstall ${{ join(fromJSON(steps.deps.outputs.formula_dependencies), ' ') }}
working-directory: ${{ matrix.working_directory }}
if: success() && join(fromJSON(steps.deps.outputs.formula_dependencies)) != ''
timeout-minutes: 30
- name: Uninstall cask dependencies
run: |
brew cask uninstall ${{ join(fromJSON(steps.deps.outputs.cask_dependencies), ' ') }}
working-directory: ${{ matrix.working_directory }}
if: success() && join(fromJSON(steps.deps.outputs.cask_dependencies)) != ''
timeout-minutes: 30
- name: Compare installed and running apps and services with snapshot
run: |
brew ruby -r "$(brew --repository homebrew/cask)/cmd/lib/check.rb" <<'EOF'
before = JSON.parse(<<~'EOS').transform_keys(&:to_sym)
${{ steps.snapshot.outputs.before }}
EOS
after = Check.all
errors = Check.errors(before, after)
errors.each do |error|
onoe error
end
error = errors.map { |e|
Tty.strip_ansi(e)
.gsub(/\r/, '%0D')
.gsub(/\n/, '%0A')
.gsub(/]/, '%5D')
.gsub(/;/, '%3B')
}.join("\n\n")
puts "::error file=${{ matrix.cask }}::#{error}"
exit 1 if errors.any?
EOF