From 6de88f7fc7f0bf70a9e8266deaaed2a9433a68b7 Mon Sep 17 00:00:00 2001 From: ernestl Date: Thu, 21 Nov 2024 11:41:57 +0200 Subject: [PATCH] .github/workflows: add workflow to determine required version of go snap for testing --- .github/workflows/determine-go-versions.yaml | 58 ++++++++++++++++++++ .github/workflows/test.yaml | 32 +++++++---- 2 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/determine-go-versions.yaml diff --git a/.github/workflows/determine-go-versions.yaml b/.github/workflows/determine-go-versions.yaml new file mode 100644 index 00000000000..d9a24b6c2a6 --- /dev/null +++ b/.github/workflows/determine-go-versions.yaml @@ -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" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 298ae4c1be1..3ebda3ce564 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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: @@ -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 }} @@ -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 @@ -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 }} @@ -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 }} @@ -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