-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build-aux/snap, .github/workflows: bump go snap version for building …
…and testing (#14752) * build-aux/snap: up go snap channel, for snapd snap build, from 1.18/stable to 1.23/stable * .github/workflows: add workflow to determine required version of go snap for testing .github/workflows: changed versions to channels and other corrections * .github/workflows: review improvements
- Loading branch information
Showing
4 changed files
with
264 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Combine results | ||
description: | | ||
Determines a single result from one or more results. A single skipped or | ||
failed will cause the action to fail. Details for each job will be output | ||
as part of a results summary. | ||
inputs: | ||
needs-json: | ||
description: Job outputs in JSON format | ||
required: true | ||
type: string | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Summarise and combine results | ||
shell: bash | ||
run: | | ||
needs_results=$(echo '${{ inputs.needs-json }}' | jq -r 'to_entries[] | "\(.key) \(.value.result)"') | ||
echo "Summary:" | ||
failed="false" | ||
while IFS=" " read -r job result; do | ||
if [[ "$result" != "success" ]]; then | ||
failed="true" | ||
echo "- ❌ Job \"$job\" returned result \"$result\"" | ||
else | ||
echo "- ✅ Job \"$job\" returned result \"$result\"" | ||
fi | ||
done <<< "$needs_results" | ||
if [[ "$failed" == "false" ]]; then | ||
echo "Overall result: success" | ||
else | ||
echo "Overall result: failure" | ||
exit 1 | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
name: Resolve Go snap channels | ||
description: | | ||
Compiles a list of Go snap channels with unique versions according to the | ||
given optional input flags and specific channels. Looks up the snapd build | ||
and snapd FIPS build Go channels from build-aux/snap/snapcraft.yaml. Assumes | ||
risk stable if not specified. | ||
inputs: | ||
include-snapd-build-go-channel: | ||
description: Flag instructing to include the channel of Go snap used to build Snapd snap | ||
required: false | ||
type: boolean | ||
include-snapd-build-fips-go-channel: | ||
description: Flag instructing to include the channel of Go snap used to build Snapd snap for FIPS | ||
required: false | ||
type: string | ||
include-latest-go-channel: | ||
description: Flag instructing to include the latest channel of Go snap | ||
required: false | ||
type: boolean | ||
specific-go-channels: | ||
description: Space separated list of required Go snap channels | ||
required: false | ||
type: string | ||
|
||
outputs: | ||
go-channels: | ||
description: JSON list of Go snap channels | ||
value: ${{ steps.resolve-go-channels.outputs.go-channels }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Resolve Go snap channels | ||
id: resolve-go-channels | ||
shell: bash | ||
run: | | ||
# Get the Go snap version corresponding to a channel format <version>[/<risk>] | ||
# - If optional risk is omitted, default stable will be assumed | ||
# - Assumes both device and snap architecture amd64 | ||
go_version_from_channel() { | ||
channel=$1 | ||
risk_default="stable" | ||
arch_default="amd64" | ||
# channel=<track>/<risk> | ||
if [[ "$channel" =~ ^([0-9]+\.[0-9]+|[0-9]+\.[0-9]+-fips|latest)/(stable|candidate|beta|edge)$ ]]; then | ||
track=${channel%%/*} | ||
risk=${channel##*/} | ||
# channel=<track> | ||
elif [[ "$channel" =~ ^([0-9]+\.[0-9]+|[0-9]+\.[0-9]+-fips|latest)$ ]]; then | ||
track=$channel | ||
risk=$risk_default | ||
# Not supported | ||
else | ||
echo "Cannot use Go channel \"$channel\"" | ||
return 1 | ||
fi | ||
# Query params | ||
device_arch="Snap-Device-Architecture: $arch_default" | ||
channel_arch="$arch_default" | ||
device_series="Snap-Device-Series: 16" | ||
endpoint="https://api.snapcraft.io/v2/snaps/info/go" | ||
# Query store | ||
if ! result="$(curl -s --fail -H "$device_arch" -H "$device_series" -X GET "$endpoint")"; then | ||
echo "Cannot use endpoint \"$endpoint\": $result" | ||
return 1 | ||
else | ||
version="$(jq -r ".\"channel-map\"[] \ | ||
| select ( .channel.track == \"$track\" and .channel.risk == \"$risk\" and .channel.architecture == \"$channel_arch\" ) \ | ||
| .version" <<< "$result")" | ||
if [ -z "$version" ] || [ "$version" = "null" ]; then | ||
echo "Cannot find version corresponding to: arch=$channel_arch, track=$track, risk=$track" | ||
return 1 | ||
else | ||
# Return the version | ||
echo "$version" | ||
fi | ||
fi | ||
} | ||
go_channels=() | ||
echo "Gathering required Go channels" | ||
# Optional Go channel used to build Snapd snap | ||
if [ "${{ inputs.include-snapd-build-go-channel }}" = "true" ]; then | ||
echo "> Require Go channel used to build Snapd snap" | ||
yaml="build-aux/snap/snapcraft.yaml" | ||
if ! channel="$(yq '.parts.snapd.build-snaps[]' $yaml | grep "go/.*/.*")"; then | ||
echo "Error: Cannot find valid Snapd build Go channel" | ||
exit 1 | ||
fi | ||
channel="$(yq '.parts.snapd.build-snaps[] | select(. == "go/*/*") | sub("^go/", "")' $yaml)" | ||
echo "> Adding Go channel \"$channel\"" | ||
go_channels+=("$channel") | ||
fi | ||
# Optional Go channel used to build Snapd snap for FIPS | ||
if [ "${{ inputs.include-snapd-build-fips-go-channel }}" = "true" ]; then | ||
echo "> Require Go channel used to build Snapd snap for FIPS" | ||
yaml="build-aux/snap/snapcraft.yaml" | ||
if ! channel="$(yq '.parts.snapd.override-build' $yaml | grep "GO_TOOLCHAIN_FIPS_CHANNEL=\".*\"")"; then | ||
echo "Error: Cannot find valid Snapd FIPS build Go channel" | ||
exit 1 | ||
fi | ||
channel="$(echo "$channel" | sed -n 's/^GO_TOOLCHAIN_FIPS_CHANNEL="\([^"]*\)"/\1/p')" | ||
echo "> Adding Go channel \"$channel\"" | ||
go_channels+=("$channel") | ||
fi | ||
# Optional latest stable Go channel | ||
if [ "${{ inputs.include-latest-go-channel }}" = "true" ]; then | ||
echo "> Require latest stable Go channel" | ||
channel="latest/stable" | ||
echo "> Adding Go channel \"$channel\"" | ||
go_channels+=("$channel") | ||
fi | ||
# Optional specific Go channel(s) | ||
if [ -n "${{ inputs.specific-go-channels }}" ]; then | ||
echo "> Require specific Go channel(s)" | ||
for channel in ${{ inputs.specific-go-channels }}; do | ||
echo "> Adding Go channel \"$channel\"" | ||
go_channels+=("$channel") | ||
done | ||
fi | ||
|
||
declare -A go_versions | ||
go_channels_with_unique_version=() | ||
echo "Dropping Go channels that duplicates Go versions" | ||
|
||
# Iterate all the required channels and create list of | ||
# channels with unique versions. | ||
for channel in "${go_channels[@]}"; do | ||
if ! output="$(go_version_from_channel "$channel")"; then | ||
echo "Error: $output" | ||
else | ||
if [[ -v go_versions["$output"] ]]; then | ||
echo "> Dropping channel \"$channel\": same Go version as channel \"${go_versions[$output]}\"" | ||
else | ||
echo "> Keeping channel \"$channel\" with unique Go version \"$output\"" | ||
go_versions["$output"]="$channel" | ||
go_channels_with_unique_version+=("$channel") | ||
fi | ||
fi | ||
done | ||
|
||
# Convert to single line JSON array and remove duplicates | ||
go_channels_output="[]" | ||
if [[ ${#go_channels_with_unique_version[@]} -gt 0 ]]; then | ||
go_channels_output="$(printf '%s\n' "${go_channels_with_unique_version[@]}" | jq -R . | jq -s -c .)" | ||
fi | ||
echo "Unique Go channels: $go_channels_output" | ||
|
||
# Output the single line JSON array | ||
echo "go-channels=$go_channels_output" >> "$GITHUB_OUTPUT" |
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
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