Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions actions/homebrew-alias/modernize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
# Usage:
# modernize.sh render <cask-file>
# Print the cask with only deprecated install-step block declarations
# renamed. Already-modern casks pass through unchanged.
# renamed. Already-modern casks pass through unchanged. Fails when a
# system_command call is left that the rewrite could not convert.
set -euo pipefail

render() {
local file="$1"
[ -f "$file" ] || { echo "::error::cask not found: $file" >&2; return 1; }

local out
Comment thread
piekstra marked this conversation as resolved.
out=$(mktemp)
awk '
/^[[:space:]]*preflight[[:space:]]+do[[:space:]]*$/ {
sub(/preflight[[:space:]]+do[[:space:]]*$/, "preflight_steps do")
Expand All @@ -33,7 +36,18 @@ render() {
gsub(/#\{staged_path\}/, "{{staged_path}}")
}
{ print }
' "$file"
' "$file" > "$out"

# The install-step DSL has no system_command, so one left in place (an
# assignment such as `result = system_command ...`, which the line-start
# rewrite above skips) makes Homebrew reject the whole cask as invalid.
if grep -nE '^[^#]*\bsystem_command\b' "$out" >&2; then
echo "::error::$file: system_command calls above cannot be converted to install steps; make each a bare system_command line" >&2
rm -f "$out"
return 1
fi
cat "$out"
rm -f "$out"
}

case "${1:-}" in
Expand Down
14 changes: 14 additions & 0 deletions actions/homebrew-alias/test_modernize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,19 @@ rerendered=$(bash modernize.sh render "$tmp/modern.rb")
bash modernize.sh render "$tmp/missing.rb" >/dev/null 2>&1 \
&& bad "missing file should fail" || ok "missing file fails"

printf 'cask "example" do\nend\n\n' > "$tmp/trailing.rb"
cmp -s "$tmp/trailing.rb" <(bash modernize.sh render "$tmp/trailing.rb") \
&& ok "trailing blank lines preserved" || bad "trailing blank lines preserved"

cat > "$tmp/assigned.rb" <<'RB'
cask "example" do
postflight do
result = system_command "#{staged_path}/example", args: ["refresh"], must_succeed: false
end
end
RB
bash modernize.sh render "$tmp/assigned.rb" >/dev/null 2>&1 \
&& bad "unconvertible system_command should fail" || ok "unconvertible system_command fails"

echo "----"
if [ "$fails" -eq 0 ]; then echo "all modernization tests passed"; else echo "$fails failed"; exit 1; fi
Loading