Skip to content

build-aux/snap, .github/workflows: bump go snap version for building and testing #1

build-aux/snap, .github/workflows: bump go snap version for building and testing

build-aux/snap, .github/workflows: bump go snap version for building and testing #1

Workflow file for this run

name: Determine Go snap channels
on:
workflow_call:
inputs:
include-snapd-build-go-channel:
description: 'Flag instructing to lookup the channel of Go snap used to build Snapd'
required: false
type: boolean
include-latest-go-channel:
description: 'Flag instructing to lookup the latest channel of Go snap'
required: false
type: boolean
specific-go-channels:
description: 'Space separated list of required channels'
required: false
type: string
outputs:
go-channels:
description: 'JSON list of Go snap channels to use to populate the gochannel matrix'
value: ${{ jobs.determine.outputs.go-channels }}
jobs:
determine:
runs-on: ubuntu-latest
outputs:
go-channels: ${{ steps.determine.outputs.go-channels }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:

Check failure on line 31 in .github/workflows/go-channels.yaml

View workflow run for this annotation

GitHub Actions / .github/workflows/go-channels.yaml

Invalid workflow file

You have an error in your yaml syntax on line 31
fetch-depth: 0
- name: Find Go channel and version used for snapd build
run: |
yaml="build-aux/snap/snapcraft.yaml"
channel=$(yq '.parts.snapd.build-snaps[] | select(. == "go/*/*") | sub("^go/", "")' $yaml)
version=""
if [[ "$channel" =~ ^[0-9]+\.[0-9]+/(stable|candidate|beta|edge)$ ]]; then
version=$(snap info go | grep "$channel:" | awk '/\/.*:/ {print $2}' | awk "NR==1")
elif [[ "$channel" =~ ^[0-9]+\.[0-9]$ ]]; then
version=$(snap info go | grep "$channel/.*:" | awk '/\/.*:/ {print $2}' | awk "NR==1")
else
echo "Cannot use go channel \"$channel\" extracted from snapd snapcraft.yaml \"$yaml\""
exit 1
fi
echo "=Hello, World!" >> $GITHUB_ENV
- name: Determine Go snap channels
id: determine
run: |
# Get the go version for a channel in the go snap specific format <version>[/<risk>]
# For <version> without optional risk, it assumes stable
go_version_from_channel() {
channel=$1
version=""
# Retrieve go version for valid channel format
if [[ "$channel" =~ ^[0-9]+\.[0-9]+/(stable|candidate|beta|edge)$ ]]; then
version=$(snap info go | grep "$channel:" | awk '/\/.*:/ {print $2}' | awk "NR==1")
elif [[ "$channel" =~ ^[0-9]+\.[0-9]$ ]]; then
version=$(snap info go | grep "$channel/stable:" | awk '/\/.*:/ {print $2}' | awk "NR==1")
else
# Invalid channel format
echo "Cannot use Go channel \"$channel\""
return 1
fi
# Validate Go version
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+ ]]; then
echo "Invalid Go version \"$version\""
return 1
fi
# Return version
echo "$version"
}
go_version_snapd_build=""
go_channel_list=()
# Optionally add specific channels
if [ -n "${{ inputs.specific-go-channels }}" ]; then
for channel in ${{ inputs.specific-go-channels }}; do
go_channel_list+=("$channel")
done
fi
# Optionally consider channel that snapd is build with
if [ "${{ inputs.include-snapd-build-go-channel }}" = "true" ]; then
yaml="build-aux/snap/snapcraft.yaml"
channel=$(yq '.parts.snapd.build-snaps[] | select(. == "go/*/*") | sub("^go/", "")' $yaml)
if output=$(go_version_from_channel "$channel"); then
go_version_snapd_build=$output
go_channel_list+=("$channel")
else
echo "$output"
exit 1
fi
fi
# Optionally consider latest channel
if [ "${{ inputs.include-latest-go-channel }}" = "true" ]; then
channel="latest/stable"
if output=$(go_version_from_channel "$channel"); then
# Do not add it latest channel if it is the same version as snapd build
if [[ "$output" != "$go_version_snapd_build" ]]; then
go_channel_list+=("$channel")
fi
else
echo "$output"
exit 1
fi
fi
# Remove duplicates and convert to JSON array
unique_channels=$(printf '%s\n' "${go_channels[@]}" | sort -u | jq -R . | jq -s .)
# Output the list
{
echo 'go-channels<<EOF'
echo "$unique_channels"
echo EOF
} >> $GITHUB_OUTPUT