canonical / observability

Umbrella repository for the observability initiatives at Canonical.
Apache License 2.0
5 stars 11 forks source link

[rock ci] Use yq v4 #166

Closed sed-i closed 3 months ago

sed-i commented 5 months ago

Problem

In our CI, rock version comes from:

rock_version=$(yq -r '.version' $GITHUB_WORKSPACE/rock/$file)

#...

upload_item_format='{"source":"%s","commit":"%s","directory":"%s","release":%s}'
upload_item=$(printf "$upload_item_format" \
  "canonical/${{ inputs.rock-name }}-rock" \
  "${{ steps.commit-sha.outputs.commit_sha }}" \
  "$rock_version" \
  "$rock_tags" \
)

oci-factory CI failed because the version "0.120" was parsed as 0.12. Manually adding quotations helped.

Solution

Before this PR, our CI specified runs-on ubuntu:latest without specifying a yq version. This PR adds a step for installing yq v4, to match oci-factory.

lucabello commented 4 months ago

The problem with this is that yq doesn't really pick it up (meaning !!str remains in the final yaml) and I'm concerned it might break CI on the OCI Factory side as that has been a bit too precise in the past.

I'm experimenting locally, and finding that with version yq (https://github.com/mikefarah/yq/) version v4.40.5, the current CI would add quotes. I see that no yq version is explicitly specified, so maybe we're using the wrong one?

I'd ask you to also try the current code locally and see what happens; if can run:

# 1. `cd` to your oci-factory cloned repo
# 2. Make sure you're using `bash` instead of your shell, to be 100% sure
upload_item_format='{"source":"%s","commit":"%s","directory":"%s","release":"%s"}'
upload_item=$(printf "$upload_item_format" "canonical/alertmanager-rock" "89abcd" "0.120" "0.120-22.04")
yq ".upload += $upload_item" ~/Repositories/Canonical/oci-factory-lucabello/oci/alertmanager/image.yaml

You should see directory: "0.120", with the quotes being there.