goreleaser / goreleaser-cross

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

release failed when running in a container #50

Closed dwisiswant0 closed 1 year ago

dwisiswant0 commented 1 year ago

Hello, I intended to experiment with cross-compilation using goreleaser-cross within a container. However, I encountered an issue where goreleaser detected that the cwd is "not a git repository." I'm looking for any suggestions on why this might occur and if there's a possible workaround.

Below is the GitHub workflow snippet that only has two steps.

# SNIPPED
jobs:
  release:
    name: goreleaser-cross
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/goreleaser/goreleaser-cross:latest
    if: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && (inputs.job == 'release' || inputs.job == 'both')) }}
    steps:
      - uses: actions/checkout@master
        with:
          ref: "${{ inputs.tag }}"
          fetch-depth: 0

      - run: goreleaser release
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
        working-directory: "${{ github.workspace }}"

Error occurred:

  goreleaser release
# shell: sh -e {0}
# env:
#   GITHUB_TOKEN: ***
  • starting release...
  • loading config file                              file=.goreleaser.yaml
  • 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
Error: Process completed with exit code 1.

Thanks!

dwisiswant0 commented 1 year ago

So basically I did this experiment based on this article which is that it's running on the GitLab registry, so I wanted to try it on the GitHub action.

dwisiswant0 commented 1 year ago

Upon investigation, I discovered that the problem stemmed from the GitHub runner image, issue actions/runner-images#6775. The command git rev-parse --is-inside-work-tree was returning the error: "dubious ownership in repository at [...]".

To resolve this issue, I implemented a (temporary) workaround by adding this step (after checking out the repo):

- run: git config --global --add safe.directory "$(pwd)"

Interestingly, even though I noticed that the entrypoint was running the same command: https://github.com/goreleaser/goreleaser-cross/blob/df843fc30e9ac0fa1ebee4b269be267690344120/entrypoint.sh#L78

I'm unsure how the problem initially occurred.