2019-08-13 10:26:50 +08:00
|
|
|
name: CI
|
|
|
|
|
2019-08-13 11:00:51 +08:00
|
|
|
on:
|
|
|
|
- pull_request
|
2019-08-13 10:26:50 +08:00
|
|
|
|
|
|
|
jobs:
|
2020-08-13 05:47:11 +08:00
|
|
|
syntax:
|
|
|
|
name: syntax
|
2019-12-20 16:37:06 +08:00
|
|
|
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
|
|
|
|
if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'syntax-only')
|
|
|
|
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)
|
|
|
|
}
|
2019-08-14 12:47:01 +08:00
|
|
|
|
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 }}
|
2019-08-14 12:47:01 +08:00
|
|
|
|
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 }}'
|
2020-08-15 10:13:57 +08:00
|
|
|
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
|
2020-07-27 21:55:41 +08:00
|
|
|
run: |
|
2020-08-13 05:47:11 +08:00
|
|
|
brew ruby <<'EOF'
|
|
|
|
cask = Cask::CaskLoader.load('${{ matrix.cask }}')
|
|
|
|
installer = Cask::Installer.new(cask)
|
2020-07-27 21:55:41 +08:00
|
|
|
|
2020-08-13 05:47:11 +08:00
|
|
|
cask_and_formula_dependencies = installer.missing_cask_and_formula_dependencies
|
|
|
|
|
|
|
|
puts cask_and_formula_dependencies.map(&:inspect)
|
|
|
|
|
|
|
|
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_dependencies::#{JSON.generate(cask_dependencies)}"
|
|
|
|
puts "::set-output name=formula_dependencies::#{JSON.generate(formula_dependencies)}"
|
|
|
|
EOF
|
|
|
|
working-directory: ${{ matrix.working_directory }}
|
|
|
|
timeout-minutes: 30
|
|
|
|
|
|
|
|
- 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
|