-
-
Save Dkendal/065c7713aea782c232bd0f94985504a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
next | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment