From ac3e0d300ff9731c34734e4a72882c9dda6d35d8 Mon Sep 17 00:00:00 2001
From: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Date: Thu, 21 Nov 2024 21:59:57 -0500
Subject: [PATCH] Use go version from go.mod files in CI

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
---
 .github/workflows/checks.yml                  | 29 ++-----------------
 .github/workflows/flytectl-release.yml        |  2 +-
 .github/workflows/flyteidl-checks.yml         | 19 ------------
 .github/workflows/generate_flyte_manifest.yml |  2 +-
 .github/workflows/go_generate.yml             |  5 +---
 .github/workflows/integration.yml             |  5 +---
 .github/workflows/lint.yml                    |  3 --
 .github/workflows/single-binary.yml           |  2 +-
 .github/workflows/tests.yml                   |  4 +--
 .github/workflows/unit-tests.yml              |  5 +---
 flyteadmin/go.mod                             |  2 +-
 11 files changed, 11 insertions(+), 67 deletions(-)

diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml
index 3a1f9869dc..edce3d4c6f 100644
--- a/.github/workflows/checks.yml
+++ b/.github/workflows/checks.yml
@@ -11,22 +11,10 @@ on:
       - master
       - 'release-v**'
 env:
-  GO_VERSION: "1.22"
   PRIORITIES: "P0"
 jobs:
-  unpack-envvars:
-    runs-on: ubuntu-latest
-    outputs:
-      go-version: ${{ steps.step.outputs.go-version }}
-    steps:
-      - id: step
-        run: |
-          echo "go-version=${{ env.GO_VERSION }}" >> $GITHUB_OUTPUT
-
   lint:
     name: Lint
-    needs:
-      - unpack-envvars
     strategy:
       fail-fast: false
       matrix:
@@ -42,11 +30,8 @@ jobs:
     uses: ./.github/workflows/lint.yml
     with:
       component: ${{ matrix.component }}
-      go-version: ${{ needs.unpack-envvars.outputs.go-version }}
   unit-tests:
     name: Unit Tests
-    needs:
-      - unpack-envvars
     strategy:
       fail-fast: false
       matrix:
@@ -61,7 +46,6 @@ jobs:
     uses: ./.github/workflows/unit-tests.yml
     with:
       component: ${{ matrix.component }}
-      go-version: ${{ needs.unpack-envvars.outputs.go-version }}
     secrets:
       CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
 
@@ -77,7 +61,6 @@ jobs:
     name: Integration Test
     needs:
       - flyteadmin-int-tests-image-build
-      - unpack-envvars
     strategy:
       fail-fast: false
       matrix:
@@ -87,12 +70,9 @@ jobs:
     with:
       component: ${{ matrix.component }}
       cache_key: ${{ needs.flyteadmin-int-tests-image-build.outputs.cache_key }}
-      go-version: ${{ needs.unpack-envvars.outputs.go-version }}
 
   generate:
     name: Check Go Generate
-    needs:
-      - unpack-envvars
     strategy:
       fail-fast: false
       matrix:
@@ -105,7 +85,6 @@ jobs:
     uses: ./.github/workflows/go_generate.yml
     with:
       component: ${{ matrix.component }}
-      go-version: ${{ needs.unpack-envvars.outputs.go-version }}
     secrets:
       FLYTE_BOT_PAT: ${{ secrets.FLYTE_BOT_PAT }}
 
@@ -121,8 +100,6 @@ jobs:
   dry_run_goreleaser:
     name: Dry Run Goreleaser
     runs-on: ubuntu-latest
-    needs:
-      - unpack-envvars
     steps:
       - name: Checkout
         uses: actions/checkout@v4
@@ -130,7 +107,7 @@ jobs:
           fetch-depth: "0"
       - uses: actions/setup-go@v4
         with:
-          go-version: ${{ needs.unpack-envvars.outputs.go-version }}
+          go-version-file: go.mod
       - name: Run GoReleaser dry run
         uses: goreleaser/goreleaser-action@v5
         with:
@@ -146,8 +123,6 @@ jobs:
     defaults:
       run:
         working-directory: flytectl
-    needs:
-      - unpack-envvars
     steps:
       - uses: insightsengineering/disk-space-reclaimer@v1
       - name: Checkout
@@ -161,7 +136,7 @@ jobs:
       - name: Set up Go
         uses: actions/setup-go@v4
         with:
-          go-version: ${{ needs.unpack-envvars.outputs.go-version }}
+          go-version-file: go.mod
       - name: Build Flytectl binary
         run: make compile
       - name: Create a sandbox cluster
diff --git a/.github/workflows/flytectl-release.yml b/.github/workflows/flytectl-release.yml
index 2aba67dbe9..fb87a217a5 100644
--- a/.github/workflows/flytectl-release.yml
+++ b/.github/workflows/flytectl-release.yml
@@ -37,7 +37,7 @@ jobs:
       - name: Set up Go
         uses: actions/setup-go@v4
         with:
-          go-version: "1.21"
+          go-version-file: flytectl/go.mod
       - name: Run GoReleaser
         uses: goreleaser/goreleaser-action@v5
         with:
diff --git a/.github/workflows/flyteidl-checks.yml b/.github/workflows/flyteidl-checks.yml
index 781b173e40..c9e430433c 100644
--- a/.github/workflows/flyteidl-checks.yml
+++ b/.github/workflows/flyteidl-checks.yml
@@ -10,46 +10,27 @@ on:
     branches:
       - master
       - 'release-v**'
-env:
-  GO_VERSION: "1.22"
 jobs:
-  unpack-envvars:
-    runs-on: ubuntu-latest
-    outputs:
-      go-version: ${{ steps.step.outputs.go-version }}
-    steps:
-      - id: step
-        run: |
-          echo "go-version=${{ env.GO_VERSION }}" >> $GITHUB_OUTPUT
   lint:
     name: Lint
-    needs:
-      - unpack-envvars
     strategy:
       fail-fast: false
     uses: ./.github/workflows/lint.yml
     with:
       component: flyteidl
-      go-version: ${{ needs.unpack-envvars.outputs.go-version }}
   unit-tests:
     name: Unit Tests
-    needs:
-      - unpack-envvars
     uses: ./.github/workflows/unit-tests.yml
     with:
       component: flyteidl
-      go-version: ${{ needs.unpack-envvars.outputs.go-version }}
     secrets:
       CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
   generate:
     name: Check Go Generate
-    needs:
-      - unpack-envvars
     strategy:
       fail-fast: false
     uses: ./.github/workflows/go_generate.yml
     with:
       component: flyteidl
-      go-version: ${{ needs.unpack-envvars.outputs.go-version }}
     secrets:
       FLYTE_BOT_PAT: ${{ secrets.FLYTE_BOT_PAT }}
diff --git a/.github/workflows/generate_flyte_manifest.yml b/.github/workflows/generate_flyte_manifest.yml
index a8c90a451e..c5fdc01f16 100644
--- a/.github/workflows/generate_flyte_manifest.yml
+++ b/.github/workflows/generate_flyte_manifest.yml
@@ -17,7 +17,7 @@ jobs:
           fetch-depth: "0"
       - uses: actions/setup-go@v5
         with:
-          go-version: "1.22"
+          go-version-file: go.mod
       - name: Update references
         env:
           VERSION: ${{ github.event.inputs.next-version }}
diff --git a/.github/workflows/go_generate.yml b/.github/workflows/go_generate.yml
index 2fb80653ae..4dfaad3032 100644
--- a/.github/workflows/go_generate.yml
+++ b/.github/workflows/go_generate.yml
@@ -6,9 +6,6 @@ on:
       component:
         required: true
         type: string
-      go-version:
-        required: true
-        type: string
     secrets:
       FLYTE_BOT_PAT:
         required: true
@@ -29,6 +26,6 @@ jobs:
           github_token: ${{ secrets.FLYTE_BOT_PAT }}
       - uses: actions/setup-go@v5
         with:
-          go-version: ${{ inputs.go-version }}
+          go-version-file: ${{ inputs.component }}/go.mod
       - name: Go generate and diff
         run: DELTA_CHECK=true make generate
diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml
index eb0118f6d1..5abc63c2ab 100644
--- a/.github/workflows/integration.yml
+++ b/.github/workflows/integration.yml
@@ -10,9 +10,6 @@ on:
         description: "Cache key for docker image"
         required: true
         type: string
-      go-version:
-        required: true
-        type: string
 jobs:
   integration:
     name: Integration tests
@@ -39,7 +36,7 @@ jobs:
       - name: Set up Go
         uses: actions/setup-go@v5
         with:
-          go-version: ${{ inputs.go-version }}
+          go-version-file: ${{ inputs.component }}/go.mod
       - name: Integration
         run: |
           # attempt to clean up some unneeded data: https://github.com/actions/virtual-environments/issues/2840#issuecomment-790492173
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index bd809d8c87..e22da59ec1 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -6,9 +6,6 @@ on:
       component:
         required: true
         type: string
-      go-version:
-        required: true
-        type: string
 jobs:
   lint:
     name: Run Lint
diff --git a/.github/workflows/single-binary.yml b/.github/workflows/single-binary.yml
index 92fb5e53e3..c2bde54f66 100644
--- a/.github/workflows/single-binary.yml
+++ b/.github/workflows/single-binary.yml
@@ -20,7 +20,7 @@ jobs:
       - uses: actions/checkout@v4
       - uses: actions/setup-go@v5
         with:
-          go-version: "1.22"
+          go-version-file: go.mod
       - name: golangci-lint
         uses: golangci/golangci-lint-action@v3
         with:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 8915d88fbe..7fee643e05 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -19,7 +19,7 @@ jobs:
       - name: Set up Go
         uses: actions/setup-go@v5
         with:
-          go-version: "1.22"
+          go-version-file: go.mod
       - name: Compile
         run: make compile
       - name: Run tests
@@ -83,6 +83,6 @@ jobs:
       - uses: actions/checkout@v4
       - uses: actions/setup-go@v5
         with:
-          go-version: "1.22"
+          go-version-file: go.mod
       - name: Helm and diff
         run: DELTA_CHECK=true make helm
diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
index 3911d64026..dff36b76ab 100644
--- a/.github/workflows/unit-tests.yml
+++ b/.github/workflows/unit-tests.yml
@@ -6,9 +6,6 @@ on:
       component:
         required: true
         type: string
-      go-version:
-        required: true
-        type: string
     secrets:
       CODECOV_TOKEN:
         required: true
@@ -25,7 +22,7 @@ jobs:
       - name: Set up Go
         uses: actions/setup-go@v5
         with:
-          go-version: ${{ inputs.go-version }}
+          go-version-file: ${{ inputs.component }}/go.mod
       - name: Unit Tests
         run: make install && make test_unit_codecov
       - name: Push CodeCov
diff --git a/flyteadmin/go.mod b/flyteadmin/go.mod
index bb714cb39d..82e2189f34 100644
--- a/flyteadmin/go.mod
+++ b/flyteadmin/go.mod
@@ -1,6 +1,6 @@
 module github.com/flyteorg/flyte/flyteadmin
 
-go 1.23
+go 1.22
 
 require (
 	cloud.google.com/go/iam v1.1.5