Skip to content

Make our GH Actions source YML files more readable by factoring out strings#3328

Open
mvidner wants to merge 5 commits intomasterfrom
actions-readable-with-env
Open

Make our GH Actions source YML files more readable by factoring out strings#3328
mvidner wants to merge 5 commits intomasterfrom
actions-readable-with-env

Conversation

@mvidner
Copy link
Contributor

@mvidner mvidner commented Mar 24, 2026

Problem

I read our GitHub Actions that autosubmit Agama to OBS and find them hard to read:

  • The expression for the target OBS project is repeated
  • Shell commands are squashed to a single line

Solution

  • Declare env.obs_project
  • Use shell variables to break up the monster lines to tame ones

Testing

  • Tested manually: ran devel/branch2obs.sh so that the submission actions run
    • Fixed a quoting error in this PR
    • Fixed a bug in branch2obs when you have multiple remotes

Screenshots

No, but here is a Workflow run to demonstrate that the env expressions indeed work, even in boolean contexts.

Documentation

  • No new functionality
  • Mentioned reference docs links in the commits

@mvidner mvidner force-pushed the actions-readable-with-env branch from 42c6bea to e5d6d4e Compare March 26, 2026 08:30
mvidner added 2 commits March 26, 2026 10:02
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)
@mvidner mvidner force-pushed the actions-readable-with-env branch from e5d6d4e to 6a362d8 Compare March 26, 2026 09:03
…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.
@mvidner mvidner marked this pull request as ready for review March 26, 2026 09:14
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.*)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it is more readable now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is complex and dense, but IMHO better than the previous version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice..I fix that by using gh repo set-default, but your solution looks better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants