Make our GH Actions source YML files more readable by factoring out strings#3328
Make our GH Actions source YML files more readable by factoring out strings#3328
Conversation
But, on jobs.JOBID.if, env CANNOT be used because... GitHub docs say so: https://docs.github.com/en/actions/reference/workflows-and-actions/contexts#context-availability (the VS Code GitHub Actions extension will helpfully flag it fortunately)
42c6bea to
e5d6d4e
Compare
Seriously, a 204-character single-line command is UNREADABLE, and that was AFTER shortening it with env.obs_project. Also in YAML syntax: replace "|-" by "|", the "-" means to strip the trailing newline, which does not really matter in these shell commands and only served to confuse the reader (in this case, the commit author, dear reader)
e5d6d4e to
6a362d8
Compare
…otes add an explicit -R/--repo option to gh, like the other invocations do, otherwise it fails with: > Starting GitHub Action obs-staging-live.yml... > X No default remote repository has been set. To learn more about the default repository, run: gh repo set-default --help > please run `gh repo set-default` to select a default remote repository.
| update_obs_package: | ||
| # do not run in forks which do not set the OBS_PROJECTS variable, | ||
| # or the mapping for the current branch is missing | ||
| # (BTW, jobs.FOO.if cannot see env.*) |
There was a problem hiding this comment.
it should be able using context. At least it is what doc says https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-variables#using-the-env-context-to-access-environment-variable-values
There was a problem hiding this comment.
No. That doc uses env for jobs.<job_id>.steps.if, but env is not available for jobs.<job_id>.if. Beautiful, right?
https://docs.github.com/en/actions/reference/workflows-and-actions/contexts#context-availability
| SED_EXPR="s#${BEG}.*${END}#${BEG}https://github.com/${{ github.repository }}.git${END}#" | ||
| sed -e "${SED_EXPR}" ${{ inputs.service_file }} > $OUT_SERVICE | ||
| BEG='<param name="versionformat">' | ||
| if [ -z "$(git tag -l)" ]; then sed -i -e "s#${BEG}.*${END}##" $OUT_SERVICE; fi |
There was a problem hiding this comment.
I am not sure if it is more readable now.
There was a problem hiding this comment.
Yes it is complex and dense, but IMHO better than the previous version
There was a problem hiding this comment.
well, it makes reading a bit harder as you do not see what sed is in fact doing. I ask AI how to make it more readable and here is AI proposal which is for me more readable ( but still it includes sed expressions :)
OUT_SERVICE="./${{ env.obs_project }}/${{ inputs.package_name }}/_service"
REPO_URL="https://github.com/${{ github.repository }}.git"
# Replace the URL parameter and output to the new file
sed "s#<param name=\"url\">.*</param>#<param name=\"url\">${REPO_URL}</param>#" \
"${{ inputs.service_file }}" > "$OUT_SERVICE"
# Strip the versionformat parameter if there are no git tags
if [ -z "$(git tag -l)" ]; then
sed -i "s#<param name=\"versionformat\">.*</param>##" "$OUT_SERVICE"
fi
| for workflow in "${workflows[@]}"; do | ||
| echo "Starting GitHub Action $workflow..." | ||
| gh workflow run "$workflow" --ref "$BRANCH" | ||
| gh -R "$repo_slug" workflow run "$workflow" --ref "$BRANCH" |
There was a problem hiding this comment.
nice..I fix that by using gh repo set-default, but your solution looks better.
Problem
I read our GitHub Actions that autosubmit Agama to OBS and find them hard to read:
Solution
env.obs_projectTesting
devel/branch2obs.shso that the submission actions runScreenshots
No, but here is a Workflow run to demonstrate that the
envexpressions indeed work, even in boolean contexts.Documentation