forked from Homebrew/homebrew-cask-versions
-
Notifications
You must be signed in to change notification settings - Fork 0
225 lines (187 loc) · 8.01 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: CI
on: pull_request
env:
HOMEBREW_DEVELOPER: 1
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
generate-matrix:
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
runs-on: ubuntu-latest
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
with:
test-bot: false
- name: Check out Pull Request
uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false
- name: Generate CI matrix
id: generate-matrix
run: |
brew ruby -- "$(brew --repository homebrew/cask)/cmd/lib/generate-matrix.rb" "${{ github.event.pull_request.url }}"
test:
name: ${{ matrix.name }}
needs: generate-matrix
runs-on: macos-latest
strategy:
matrix:
include: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
with:
test-bot: false
- name: Check out Pull Request
uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false
- 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::Removing Visual Studio is no longer necessary.'
fi
fi
if ! rm /usr/local/bin/dotnet; then
echo '::warning::Removing `dotnet` symlink is no longer necessary.'
fi
if ! rm /usr/local/bin/pod; then
echo '::warning::Removing `cocoapods` symlink is no longer necessary.'
fi
if brew tap-info adoptopenjdk/openjdk; then
brew untap adoptopenjdk/openjdk
else
echo '::warning::Untapping adoptopenjdk/openjdk is no longer necessary.'
fi
- name: Cache Homebrew Gems
uses: actions/cache@v2
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 Homebrew Gems
run: brew install-bundler-gems
- name: Run brew cask style
run: brew cask style
if: success() && !matrix.cask
- name: Run brew cask audit ${{ matrix.cask.token }}
run: |
if ${{ !matrix.cask }}; then
brew cask audit
exit $?
fi
brew cask audit ${{ join(matrix.audit_args, ' ') }} '${{ matrix.cask.path }}'
timeout-minutes: 30
if: always()
- name: Gather cask information
id: info
run: |
brew ruby <<'EOF'
require 'cask/cask_loader'
require 'cask/installer'
cask = Cask::CaskLoader.load('${{ matrix.cask.path }}')
was_installed = cask.installed?
manual_installer = cask.artifacts.any? { |artifact|
artifact.is_a?(Cask::Artifact::Installer::ManualInstaller)
}
macos_requirement_satisfied = if macos_requirement = cask.depends_on.macos
macos_requirement.satisfied?
else
true
end
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? }
installer = Cask::Installer.new(cask)
cask_and_formula_dependencies = installer.missing_cask_and_formula_dependencies
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=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)}"
puts "::set-output name=cask_conflicts::#{JSON.generate(cask_conflicts)}"
puts "::set-output name=cask_dependencies::#{JSON.generate(cask_dependencies)}"
puts "::set-output name=formula_conflicts::#{JSON.generate(formula_conflicts)}"
puts "::set-output name=formula_dependencies::#{JSON.generate(formula_dependencies)}"
EOF
if: always() && matrix.cask
- name: Uninstall conflicting formulae
run: |
brew uninstall ${{ join(fromJSON(steps.info.outputs.formula_conflicts), ' ') }}
if: always() && steps.info.outcome == 'success' && join(fromJSON(steps.info.outputs.formula_conflicts)) != ''
timeout-minutes: 30
- name: Uninstall conflicting casks
run: |
brew cask uninstall ${{ join(fromJSON(steps.info.outputs.cask_conflicts), ' ') }}
if: always() && steps.info.outcome == 'success' && join(fromJSON(steps.info.outputs.cask_conflicts)) != ''
timeout-minutes: 30
- name: Run brew cask zap ${{ matrix.cask.token }}
run: |
brew cask zap '${{ matrix.cask.path }}'
if: always() && steps.info.outcome == 'success' && 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
if: always() && steps.info.outcome == 'success'
- name: Run brew cask install ${{ matrix.cask.token }}
id: install
run: brew cask install '${{ matrix.cask.path }}'
if: >
always() && steps.info.outcome == 'success' &&
fromJSON(steps.info.outputs.macos_requirement_satisfied) &&
!matrix.skip_install
timeout-minutes: 30
- name: Run brew cask uninstall ${{ matrix.cask.token }}
run: brew cask uninstall '${{ matrix.cask.path }}'
if: always() && steps.install.outcome == 'success' && !fromJSON(steps.info.outputs.manual_installer)
timeout-minutes: 30
- name: Uninstall formula dependencies
run: |
brew uninstall ${{ join(fromJSON(steps.info.outputs.formula_dependencies), ' ') }}
if: always() && steps.install.outcome == 'success' && join(fromJSON(steps.info.outputs.formula_dependencies)) != ''
timeout-minutes: 30
- name: Uninstall cask dependencies
run: |
brew cask uninstall ${{ join(fromJSON(steps.info.outputs.cask_dependencies), ' ') }}
if: always() && steps.install.outcome == 'success' && join(fromJSON(steps.info.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.path }}::#{error}"
exit 1 if errors.any?
EOF
if: always() && steps.snapshot.outcome == 'success'
conclusion:
name: conclusion
needs: test
runs-on: ubuntu-latest
if: always()
steps:
- name: Result
run: ${{ needs.test.result == 'success' }}