cheekybits / genny

Elegant generics for Go
MIT License
1.71k stars 167 forks source link

Drops imports on github actions #77

Closed ghstahl closed 2 years ago

ghstahl commented 2 years ago

reproducible project

genny-github-actions-issue

I am on windows 10 latest

vscode

The following works fine.

genny -in ./internal/genny/sarulabsdi/interface-types.go -out ./pkg/interface-types.go -pkg pkg gen "InterfaceType=IHello"
// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/cheekybits/genny

package pkg

import (
    "reflect"

    di "github.com/fluffy-bunny/sarulabsdi"
)

// ReflectTypeIHello used when your service claims to implement IHello
var ReflectTypeIHello = di.GetInterfaceReflectType((*IHello)(nil))

// AddIHelloByObj adds a prebuilt obj
func AddIHelloByObj(builder *di.Builder, obj interface{}) {
    di.AddSingletonWithImplementedTypesByObj(builder, obj, ReflectTypeIHello)
}

// AddSingletonIHello adds a type that implements IHello
func AddSingletonIHello(builder *di.Builder, implType reflect.Type) {
    di.AddSingletonWithImplementedTypes(builder, implType, ReflectTypeIHello)
}

Github actions issue

When I run the same command on github it produces the following output.

Where did the following go?

di "github.com/fluffy-bunny/sarulabsdi"
// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/cheekybits/genny

package pkg

import "reflect"

// ReflectTypeIHello used when your service claims to implement IHello
var ReflectTypeIHello = di.GetInterfaceReflectType((*IHello)(nil))

// AddIHelloByObj adds a prebuilt obj
func AddIHelloByObj(builder *di.Builder, obj interface{}) {
    di.AddSingletonWithImplementedTypesByObj(builder, obj, ReflectTypeIHello)
}

// AddSingletonIHello adds a type that implements IHello
func AddSingletonIHello(builder *di.Builder, implType reflect.Type) {
    di.AddSingletonWithImplementedTypes(builder, implType, ReflectTypeIHello)
}

So yea, its working on my machine but not on github actions. I am windows 10, github it ubuntu-latest.

ghstahl commented 2 years ago

SOLVED: Turns out I need to do the following before running genny.

          go mod tidy
          go mod download
name: Go

on:
  push:
    branches: [ main ]
    paths-ignore:
      - 'README.md'
  pull_request:
    branches: [ main ]
jobs:
# Preflight
  preflight-genny:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: '^1.17'

      - name: Install genny
        run: |
          go version
          go get github.com/cheekybits/genny@latest

      - name: generate generics
        run: |
          # NOTE: go mod tidy and go mod download brings everything down so that genny has everthing it needs
          go mod tidy
          go mod download
          genny -in ./internal/genny/sarulabsdi/interface-types.go -out ./pkg/interface-types.go -pkg pkg gen "InterfaceType=IHello"

      - name: AutoCommit
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: Apply mockgen changes          

  build:
    runs-on: ubuntu-latest
    needs: [preflight-genny]
    steps:
    - uses: actions/checkout@v2

    - name: Set up Go
      uses: actions/setup-go@v2
      with:
        go-version: '^1.17'

    - name: Build
      run: go build -v ./...

    - name: Test
      run: go test -v ./...