Skip to content

Instantly share code, notes, and snippets.

@Dkendal
Created September 15, 2022 21:14
Show Gist options
  • Save Dkendal/065c7713aea782c232bd0f94985504a7 to your computer and use it in GitHub Desktop.
Save Dkendal/065c7713aea782c232bd0f94985504a7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env -S gawk -f
# This script reformats the output of `earthly` to add grouping metadata
# in github actions
#
# Usage: earthly +target | ./earthly-group.awk
# Earthfile has a grammar roughly defined as:
#
# <output> ::= <line>*
# <line> ::= <heading> | <detail> | '\n'
# <heading> ::= ' ' NUMBER+ '. ' STRING ' ' EMOJI '\n' '-'+ '\n'
# <detail> ::= ' ' cmd ' | ' STRING
# <cmd> ::= STRING
#
# Everything between headings should be grouped under that heading.
# Everything with the same `cmd` should be grouped together.
#
# Something is grouped when it is formatted like:
#
# "::group::My title"
# "Inside group"
# "::endgroup::"
#
BEGIN {
group = false
}
# This is a heading
/(1\. Init|2\. Build|3\. Push|4\. Local Output)/ {
# We need to print the previous group if it exists
if (group) {
print "::endgroup::"
}
# Then we need to print the new group
group = $0
print "::group::" group
next
}
# This is a detail
# / \| / {
# match($0, /(.*)\| /, m)
# cmd = m[1]
# if (group == cmd) {
# print $0
# } else {
# if (group) {
# print "::endgroup::"
# }
# group = cmd
# print "::group::" group
# print $0
# }
# next
# }
/————————————————————————————————————————————————————————————————————————————————/ {
next
}
group {
# We are in a group, so we need to print the line
print
next
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment