Skip to content
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

Use version from module and another version in matrix testing #450

Open
Jacalz opened this issue Jan 6, 2024 · 2 comments · May be fixed by #489
Open

Use version from module and another version in matrix testing #450

Jacalz opened this issue Jan 6, 2024 · 2 comments · May be fixed by #489
Labels
feature request New feature or request to improve the current logic

Comments

@Jacalz
Copy link

Jacalz commented Jan 6, 2024

Description:
Describe your proposal.

I want to be able to do something like this where the used Go versions are set automatically in matrix testing without having to manually maintain the workflows. This is very useful when having many repositories with CI/CD infrastructure set up. To minimize the versions of Go used for testing, I want to test with the latest stable and the minimum version that the project supports, i.e. I want to use stable and the version from my go.mod file.

My idea is to be able to specify something like go-version-file inside the go-version field:

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        go: [ 'go.mod', 'stable' ]
    name: Go ${{ matrix.go }} sample
    steps:
      - uses: actions/checkout@v4
      - name: Setup go
        uses: actions/setup-go@v4
        with:
          go-version: ${{ matrix.go }}
      - run: go run hello.go

Justification:
Justification or a use case for your proposal.

This is very useful when having many repositories with CI/CD infrastructure set up. To minimize the versions of Go used for testing, I want to test with the latest stable and the minimum version that the project supports, i.e. I want to use stable and the version from my go.mod file.

Are you willing to submit a PR?

Sorry. I'll let you handle this

@Jacalz Jacalz added feature request New feature or request to improve the current logic needs triage labels Jan 6, 2024
@aparnajyothi-y
Copy link

Hello @Jacalz,
Thank you for creating this issue, we will investigate it and come back to you as soon as we have some feedback.

@myaaaaaaaaa
Copy link

myaaaaaaaaa commented Jun 26, 2024

An (untested) proof-of-concept:

diff --git a/src/main.ts b/src/main.ts
index 690d277..2fdeb8a 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -133,24 +133,27 @@ export function parseGoVersion(versionString: string): string {
   // fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
   // expecting go<version> for runtime.Version()
   return versionString.split(' ')[2].slice('go'.length);
 }
 
 function resolveVersionInput(): string {
   let version = core.getInput('go-version');
-  const versionFilePath = core.getInput('go-version-file');
+  let versionFilePath = core.getInput('go-version-file');
 
   if (version && versionFilePath) {
     core.warning(
       'Both go-version and go-version-file inputs are specified, only go-version will be used'
     );
   }
 
   if (version) {
-    return version;
+    if (!version.endsWith('go.mod')) {
+      return version;
+    }
+    versionFilePath = version;
   }
 
   if (versionFilePath) {
     if (!fs.existsSync(versionFilePath)) {
       throw new Error(
         `The specified go version file at: ${versionFilePath} does not exist`
       );

@myaaaaaaaaa myaaaaaaaaa linked a pull request Jul 7, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request to improve the current logic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants