From d5d083cda206f53f7005f73cce34614c3f1b8bb4 Mon Sep 17 00:00:00 2001 From: Simon Richardson Date: Tue, 25 Jun 2024 16:09:15 +0100 Subject: [PATCH] feat: add github action to ensure consistency If the snapcraft yaml is out of sync with the go.mod file, fail the build --- .github/workflows/static-analysis.yml | 36 +++++++++++++++++++++++++++ snap/snapcraft.yaml | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index fc2f77befaef..c9ecb3ee3a51 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -149,3 +149,39 @@ jobs: steps: - uses: actions/checkout@v4 - uses: wagoid/commitlint-github-action@v6 + + go-version: + name: Go Version + runs-on: [self-hosted, linux, arm64, aws, large] + if: github.event.pull_request.draft == false + strategy: + fail-fast: false + matrix: + binary: ["jujud", "juju"] + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + cache: true + + - name: Get go.mod version + id: go_mod_version + shell: bash + run: echo "GO_MOD_VERSION=$(go mod edit -json | jq -r .Go)" >> $GITHUB_ENV + + - name: Get binary snapcraft.yaml + id: get_binary_snapcraft + uses: mikefarah/yq@master + with: + cmd: yq -r '.parts | .["${{ matrix.binary }}"] | .["go-channel"]' snap/snapcraft.yaml + + - name: Ensure go version + echo ${{ steps.get_binary_snapcraft.outputs.result }} | grep -q "$GO_MOD_VERSION" + if [ $? -ne 0 ]; then + echo "Go version in go.mod ($mod_version) does not match snapcraft.yaml ($snap_version)" + exit 1 + fi diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 00f670c37183..c53bf546baf8 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -391,7 +391,7 @@ parts: after: - libdqlite plugin: juju-go - go-channel: 1.20/stable + go-channel: 1.21/stable source: . go-packages: - github.com/juju/juju/cmd/jujud