goreleaser / goreleaser-cross

Docker image for Golang cross-compiling with CGO
MIT License
156 stars 26 forks source link

Image no longer works in GitHub Actions #29

Closed arbourd closed 1 year ago

arbourd commented 1 year ago

Due to a bug in actions/checkout, this action cannot be used as a container without an additional step:

- run: git config --system --add safe.directory <path>

This is not unique to goreleaser-cross and will affect all versions until actions/checkout is fixed.

But, in the meantime, there is a method we can apply to the image that will allow it work without that extra step in the workflows. We could bake the command into the image itself with something like:

RUN git config --system --add safe.directory '*'

This would effectively disable the safe directory functionality within the goreleaser-cross container.

troian commented 1 year ago

interesting, so this does not work? needs to be a wildcard * ?

arbourd commented 1 year ago

Oh, I didn't know that was even in there! No, the pwd should be fine and it's a better/safer solution than what I suggested. The wildcard would match everything.

It might still be broken in actions because the global config doesn't seem to exist properly. Let me test with the latest v1.20.0 -- I was using v1.19.4 earlier.

troian commented 1 year ago

try image from ghcr.io

arbourd commented 1 year ago

Appears to be unresolved:

  ⨯ release failed after 0s                  error=current folder is not a git repository

The error "not a git repository" is due to the rev-parse command failing, due to an unsafe/dubious folder.

I will build and try --system over --global and see if that resolves it tomorrow/Monday.

troian commented 1 year ago

i think the best option would be to keep an extra run step instead of adding it goreleaser-cross and wait till checkout/action makes a fix

kamikazechaser commented 1 year ago

For those who are facing the same issue, here is a fix:

jobs:
  goreleaser:
    runs-on: ubuntu-latest
    container:
      image: goreleaser/goreleaser-cross
    environment: build
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Workaround Git Security Warning
        run: |
          # Workaround a bug in github actions:
          git config --global --add safe.directory "$GITHUB_WORKSPACE"          
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.19
MickStanciu commented 1 year ago

Hey guys! I have the same problem but cannot solve it with the workaround posted above. I am using docker to trigger go releaser cross compile:

docker run......ghcr.io/goreleaser/goreleaser-cross:1.20.1 -f .goreleaser.yml release --clean

The error is: • starting release... • loading config file file=.goreleaser.yml • loading environment variables • using token from "$GITHUB_TOKEN" • getting and validating git state ⨯ release failed after 0s error=current folder is not a git repository

Any suggestions? Thank you

troian commented 1 year ago

how do you mount workdir to docker?

MickStanciu commented 1 year ago

how do you mount workdir to docker?

Hi troian, this is the full command:

docker run \ --rm \ --privileged \ --entrypoint ./goreleaser_entry.sh \ --env-file .release-env \ -v /var/run/docker.sock:/var/run/docker.sock \ -vpwd:/go/src/$(PACKAGE_NAME) \ -w /go/src/$(PACKAGE_NAME) \ goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \ -f .goreleaser.yml release --rm-dist

troian commented 1 year ago

do you use custom entry point --entrypoint ./goreleaser_entry.sh ?