Skip to content

Fix compatibility with go 1.24 and require go >= 1.23 #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 28, 2025

Conversation

jooola
Copy link
Contributor

@jooola jooola commented Mar 17, 2025

  • Remove EOL versions of golang from the test matrix.
  • Upgrade problematic dependencies causing issues with golang 1.24
  • Require supported golang versions (>= 1.23)
  • Group requires in the go.mod file (except for the go-cty library)

Related to #279

@jooola jooola changed the title ci: run tests against go 1.23 and 1.24 Fix compatibility with go 1.24 and require go >= 1.23 Mar 17, 2025
@jooola jooola marked this pull request as ready for review March 17, 2025 11:05
@jooola jooola requested a review from a team as a code owner March 17, 2025 11:05
@jooola
Copy link
Contributor Author

jooola commented Mar 17, 2025

I have tested those changes in our own project: hetznercloud/packer-plugin-hcloud@dcc7f00

For those who can upgrade to go>=1.24, I think its worth using go tool for the packer-sdc tool.

@jooola
Copy link
Contributor Author

jooola commented Mar 19, 2025

@lbajolet-hashicorp May I have your attention for this fix 🙏 ?

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jooola,

Thanks for the PR, I left a couple of comments on the version/toolchain bumps, but other than that, this LGTM!

I'll let you address my comments, and we can probably merge this one soon.

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jooola,

Thanks for the responses and apologies it took me a bit of time to go back to this PR.

I agree with the bump to 1.23.0, but as I mentioned regarding the toolchain directive, I'm not convinced we need it per-se, so I opted to remove it in a commit I pushed to your branch as to speed-up this change being merged.

With that, I'm approving this PR, thanks for the change!

Copy link
Contributor

@JenGoldstrich JenGoldstrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you Lucas and @jooola!

@lbajolet-hashicorp lbajolet-hashicorp merged commit 99a6159 into hashicorp:main Mar 28, 2025
8 checks passed
@tenthirtyam
Copy link

Just an FYI that this can be simplified with a reusable workflow to remove repetition.

For example, with go-test.yml as:

name: go-test

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

env:
  TEST_RESULTS_PATH: /tmp/test-results

permissions:
  contents: read

jobs:
  linux-tests:
    uses: ./.github/workflows/go-test-template.yml
    with:
      os: ubuntu-latest

  windows-tests:
    uses: ./.github/workflows/go-test-template.yml
    with:
      os: windows-latest

  darwin-tests:
    uses: ./.github/workflows/go-test-template.yml
    with:
      os: macos-latest

And then the ./.github/workflows/go-test-template.yml as:

name: Go Test Template

on:
  workflow_call:
    inputs:
      os:
        required: true
        type: string

env:
  TEST_RESULTS_PATH: /tmp/test-results

permissions:
  id-token: write
  contents: read

jobs:
  go-test:
    runs-on: ${{ inputs.os }}
    strategy:
      matrix:
        go-version:
          - '1.23.x'
          - '1.24.x'
    steps:
      - name: Run git config #Windows-only
        if: runner.os == 'Windows'
        run: git config --global core.autocrlf false

      - name: Setup Go
        uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
        with:
          go-version: ${{ matrix.go-version }}

      - name: Checkout code
        uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

      - name: Check that go.mod does not contain a replace
        run: |
          if grep -Eq "^\s*replace" <go.mod; then
            echo "go.mod contains a replace but should not." >&2
            false
          fi

      - name: Create test directory
        run: |
          mkdir -p ${{ env.TEST_RESULTS_PATH }}/packer-plugin-sdk

      - name: Install buf
        if: runner.os == 'Linux'
        uses: bufbuild/[email protected]

      - name: Run gofmt
        if: runner.os == 'Linux'
        run: |
            make fmt-check

      - name: Run Go Generate Check
        if: runner.os == 'Linux'
        run: |
            make generate-check

      - name: Install gotestsum
        shell: bash
        run: go install gotest.tools/[email protected]

      - name: Fix gocty
        run: |
          make install-gen-deps
          packer-sdc fix .
          go mod tidy

      - name: Run Go tests
        shell: bash
        run: |
          PACKAGE_NAMES="$(go list ./...)"
          echo "Running $(echo "$PACKAGE_NAMES" | wc -w) packages"
          echo "$PACKAGE_NAMES"
          echo "$PACKAGE_NAMES" | xargs -I {} gotestsum --format=short-verbose --junitfile "$TEST_RESULTS_PATH"/packer-plugin-sdk/gotestsum-report.xml -- -count 1 -p 2 {};

@jooola jooola deleted the go-1.24 branch March 31, 2025 10:27
@jooola
Copy link
Contributor Author

jooola commented Mar 31, 2025

Thanks for the responses and apologies it took me a bit of time to go back to this PR.

No rush, thanks for looking at it :)

I agree with the bump to 1.23.0, but as I mentioned regarding the toolchain directive, I'm not convinced we need it per-se, so I opted to remove it in a commit I pushed to your branch as to speed-up this change being merged.

Fine by me!

Are you folks planning to cut a release with this, or is are there not enough changes yet?

@lbajolet-hashicorp
Copy link
Contributor

Hey @jooola,

Yes we do plan to cut a SDK release soon, we're working over some vulnerability reports for now, so I just want to make sure we address them in the SDK before that, but the plan is to cut a release this week, as early as possible.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants