Skip to content

Commit

Permalink
.github/workflows: add workflow to determine required version of go s…
Browse files Browse the repository at this point in the history
…nap for testing
  • Loading branch information
ernestl committed Nov 21, 2024
1 parent 1d8e8c7 commit 6de88f7
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 12 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/determine-go-versions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Determine Go snap versions

on:
workflow_call:
inputs:
include-snapd-build-go-version:
description: 'Flag instructing to lookup the version of Go snap used to build Snapd'
required: false
type: boolean
include-latest-go-version:
description: 'Flag instructing to lookup the latest version of Go snap'
required: false
type: boolean
specific-go-versions:
required: false
type: string
outputs:
gochannels:
description: 'JSON list of Go snap versions to use in gochannel matrix'

jobs:
determine:
runs-on: ubuntu-latest
outputs:
go-versions: ${{ steps.determine.outputs.go-versions }}
steps:
- name: Initialize Go versions list
id: determine
run: |
# Initialize an empty list
GO_VERSIONS=()
# Optionally add specific versions
if [ -n "${{ inputs.specific-go-versions }}" ]; then
for VERSION in ${{ inputs.specific-go-versions }}; do
GO_VERSIONS+=("$VERSION")
done
fi
# Optionally add version that snapd is build with
if [ "${{ inputs.include-snapd-build-go-version }}" = "true" ]; then
# Simulate fetching the Snapd Go build version (replace with actual logic)
BUILD_VERSION="1.18"
GO_VERSIONS+=("$BUILD_VERSION")
fi
# Optionally add latest version
if [ "${{ inputs.include-latest-go-version }}" = "true" ]; then
# Simulate fetching the latest Go version (replace with actual logic)
LATEST_VERSION="latest/stable"
GO_VERSIONS+=("$LATEST_VERSION")
fi
# Remove duplicates and convert to JSON array
UNIQUE_VERSIONS=$(printf '%s\n' "${GO_VERSIONS[@]}" | sort -u | jq -R . | jq -s .)
# Output the list
echo "::set-output name=go-versions::$UNIQUE_VERSIONS"
32 changes: 20 additions & 12 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ concurrency:
cancel-in-progress: true

jobs:
required-go-versions:
uses: ./.github/workflows/determine-go-versions.yaml
with:
# If build-version and latest version is the same,
# the duplicate will be removed
include-snapd-build-go-version: true
include-latest-go-version: true

snap-builds:
uses: ./.github/workflows/snap-builds.yaml
with:
Expand Down Expand Up @@ -81,7 +89,9 @@ jobs:

static-checks:
uses: ./.github/workflows/static-checks.yaml
needs: [cache-build-deps]
needs:
- required-go-versions
- cache-build-deps
with:
runs-on: ubuntu-latest
gochannel: ${{ matrix.gochannel }}
Expand All @@ -90,9 +100,7 @@ jobs:
# we cache successful runs so it's fine to keep going
fail-fast: false
matrix:
gochannel:
- 1.18
- latest/stable
gochannel: ${{ fromJson(needs.determine-go-versions.outputs.go-versions) }}

branch-static-checks:
runs-on: ubuntu-latest
Expand All @@ -117,7 +125,9 @@ jobs:

unit-tests:
uses: ./.github/workflows/unit-tests.yaml
needs: [static-checks]
needs:
- required-go-versions
- static-checks
with:
runs-on: ubuntu-22.04
gochannel: ${{ matrix.gochannel }}
Expand All @@ -126,16 +136,16 @@ jobs:
# we cache successful runs so it's fine to keep going
fail-fast: false
matrix:
gochannel:
- 1.18
- latest/stable
gochannel: ${{ fromJson(needs.determine-go-versions.outputs.go-versions) }}
unit-scenario:
- normal

# TODO run unit tests of C code
unit-tests-special:
uses: ./.github/workflows/unit-tests.yaml
needs: [static-checks]
needs:
- required-go-versions
- static-checks
with:
runs-on: ubuntu-22.04
gochannel: ${{ matrix.gochannel }}
Expand All @@ -144,9 +154,7 @@ jobs:
# we cache successful runs so it's fine to keep going
fail-fast: false
matrix:
gochannel:
- 1.18
- latest/stable
gochannel: ${{ fromJson(needs.determine-go-versions.outputs.go-versions) }}
unit-scenario:
- snapd_debug
- withbootassetstesting
Expand Down

0 comments on commit 6de88f7

Please sign in to comment.