do not repeat yourself!, lol, ok, I'm trying to see if I can consolidate my 2 github workflows awk sources into 1. I tried a few things, but for some reason I kept ending up with weird column stuff. retrospectively I might have been assigning not comparing variables. I decided not to polute the question with broken code.
awk is being run as git diff-tree -r --no-commit-id --name-status HEAD | awk -f .github/files/changed.awk, no options. The output of git diff-tree looks something like this
( cat << EOF
A .config/plantuml/theme.puml
M .github/workflows/main.yml
M .github/workflows/plantuml.yml
M README.md
A app/gradle.lockfile
A authn/gradle.lockfile
A docs/README.md
A docs/domain-model/README.md
A docs/domain-model/user.md
A docs/domain-model/user.puml
A docs/domain-model/foo.puml
M settings.gradle.kts
D user.puml
D foo.puml
EOF
) | awk -f file.awk
These are what I came up with.
$2 ~ /\.puml$/ &&
$2 !~ /(theme|config)\.puml$/ &&
$1 !~ /^D$/ {
changed[++n]=$2
}
END {
for ( i in changed ) result = result " " changed[i]
printf "::set-output name=changed-files::%s\n", result
printf "::warning::changed-files %s\n", result
}
outputs
::set-output name=changed-files:: docs/domain-model/user.puml docs/domain-model/foo.puml
::warning::changed-files docs/domain-model/user.puml docs/domain-model/foo.puml
$2 ~ /\.puml$/ &&
$2 !~ /(theme|config)\.puml$/ &&
$1 ~ /^D$/ {
split($2, fn, ".")
changed[++n]=fn[1] ".svg"
}
END {
for ( i in changed ) result = result " " changed[i]
printf "::set-output name=removed-files::%s\n", result
printf "::warning::removed-files %s\n", result
}
outputs
::set-output name=removed-files:: user.svg foo.svg
::warning::removed-files user.svg foo.svg
Here's the current workflow file if that helps. note: the change to awk -f is being made in a currently broken branch, which I'll delete and squash when finished.
the goal is to get output similar to the following. I don't care about the order of lines, and the whitespace within the list only matters so much as it can be passed to git add, git rm and plantuml on the shell.
# adding empty lines between just for readability here, comments do nott matter either
::set-output name=changed-files:: docs/domain-model/user.puml docs/domain-model/foo.puml
::warning::changed-files docs/domain-model/user.puml docs/domain-model/foo.puml
::set-output name=removed-files:: user.svg foo.svg
::warning::removed-files user.svg foo.svg
How would you deduplicate and improve it?