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

github action fails to download ansible-lint-requirements.txt, assumes .git dir exists in working directory #3938

Closed
tigattack opened this issue Dec 11, 2023 · 9 comments · Fixed by #4103
Assignees
Labels

Comments

@tigattack
Copy link

tigattack commented Dec 11, 2023

Summary
Issue Type
  • Bug Report
OS / ENVIRONMENT

github actions

STEPS TO REPRODUCE

ansible-lint workflow:

- uses: ansible/ansible-lint@v6.22.1
  with:
    working_directory: ansible
Desired Behavior

Requirements file is downloaded to a path that exists and used successfully.

Actual Behavior

It seems that the action assumes there will be a .git directory, which isn't necessarily the case if using anything other than the repository root as the working directory (such as shown in the example above).

2023-12-11T02:01:18.5977779Z ##[group]Run wget --output-document=.git/ansible-lint-requirements.txt https://raw.githubusercontent.com/ansible/ansible-lint/$GH_ACTION_REF/.config/requirements-lock.txt
2023-12-11T02:01:18.5980286Z �[36;1mwget --output-document=.git/ansible-lint-requirements.txt https://raw.githubusercontent.com/ansible/ansible-lint/$GH_ACTION_REF/.config/requirements-lock.txt�[0m
2023-12-11T02:01:18.6021388Z shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
2023-12-11T02:01:18.6022054Z env:
2023-12-11T02:01:18.6022395Z   GH_ACTION_REF: v6.22.1
2023-12-11T02:01:18.6022818Z ##[endgroup]
2023-12-11T02:01:18.6176869Z .git/ansible-lint-requirements.txt: No such file or directory
2023-12-11T02:01:18.6198199Z ##[error]Process completed with exit code 1.
@ssbarnea
Copy link
Member

Look at our action usage example https://github.com/ansible/ansible-lint --- you MUST clone before calling the action or it will fail.

@tigattack
Copy link
Author

tigattack commented Dec 12, 2023

I am doing so. Here's the full workflow (private repo so no link, sorry):

---
name: Ansible Lint

on:
  push:
    paths: ['ansible/**']
  workflow_dispatch:

jobs:
  lint:
    name: Ansible Lint
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Run ansible-lint
        uses: ansible/ansible-lint@v6.22.1
        with:
          working_directory: ansible

As described in the initial issue, because I am setting the working directory to a subdirectory of the cloned repository, there is no .git directory.

As a result, wget --output-document=.git/ansible-lint-requirements.txt <url> fails, since it expects .git to exist.

@Qalthos Qalthos self-assigned this Dec 13, 2023
@audgirka audgirka removed the new Triage required label Dec 14, 2023
@jhg03a
Copy link

jhg03a commented Apr 5, 2024

This is also an issue if you're using self-hosted runners with git < 2.18. When this is detected any version of the standard checkout action will use the GitHub REST API instead of real git which means there's no .git directory.

@ajfabbri
Copy link
Contributor

ajfabbri commented Apr 6, 2024

Is it fair to paraphrase this bug as: ansible-lint is broken for monorepo users? I.e. those who put automation/ansible scripts in a subdirectory, and happen to use anything outside of ansible.builtins, can't really put ansible-lint in CI? For now my workaround is to skip a good portion of our .yml files under exclude_paths in .ansible-lint. Open to suggestions on better workaround.

@jhg03a
Copy link

jhg03a commented Apr 8, 2024

I think that's a separate issue from this @ajfabbri

@ajfabbri
Copy link
Contributor

ajfabbri commented Apr 8, 2024

@jhg03a can you elaborate? IIUC this bug is the thing keeping us from being able to use ansible-lint on files with requirements (outside of ansible.builtins) in our monorepo CI. Since our ansible scripts are in a subdirectory, and .git directory is only at the root level, lint fails to find external requirements, causing an un-skippable lint failure.

@ssbarnea
Copy link
Member

ssbarnea commented Apr 9, 2024

The action is not supposed to work on sparse checkouts. You need a .git folder. I will closing this as a wont fix because I do not think there is anything we can do.

If we decide to dump the requirements lock file in to the current directory, we might broke the codebase because we would create a file that is not tracked or ignored by git.

Use of .git folder was seen as an acceptable alternative in this case, as it would always be ignored by git.

It should also be noted that the security model used by GHA does not allow us to write files to other random locations on disk outside current project directory.

Still, if someone finds a better solution for this, we will be more than happy to consider it.

@ssbarnea ssbarnea closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2024
@github-project-automation github-project-automation bot moved this from Roadmap to Done in 🧰 devtools project board Apr 9, 2024
ajfabbri added a commit to ajfabbri/ansible-lint that referenced this issue Apr 9, 2024
Setting `working_directory` for ansible-lint action would fail due to
hard-coded `.git`, introduced in commit 6f728e0, when fetching
`.config/requirements-lock.txt`, introduced in

This fix replaces `.git` with `${{ github.workspace }}/.git` to make
`working_directory` argument work again.
ajfabbri added a commit to ajfabbri/ansible-lint that referenced this issue Apr 9, 2024
Fix ansible#3938: don't assume working_directory is github.workspace
ajfabbri added a commit to ajfabbri/ansible-lint that referenced this issue Apr 9, 2024
Setting `working_directory` for ansible-lint action would fail due to
hard-coded `.git`, introduced in commit 6f728e0, when fetching
`.config/requirements-lock.txt`, introduced in

This fix replaces `.git` with `${{ github.workspace }}/.git` to make
`working_directory` argument work again.
ajfabbri added a commit to ajfabbri/ansible-lint that referenced this issue Apr 9, 2024
Setting `working_directory` for ansible-lint action would fail due to
hard-coded `.git`, introduced in commit 6f728e0, when fetching
`.config/requirements-lock.txt`.

This fix replaces `.git` with `${{ github.workspace }}/.git` to make
`working_directory` argument work again.
@ajfabbri
Copy link
Contributor

ajfabbri commented Apr 9, 2024

Thanks for looking @ssbarnea. The description here is a bit confusing, but it does not require a sparse checkout to reproduce. The linked PR has a fix and the description includes the GH action I'm using to test it. Hope this helps.

@tigattack
Copy link
Author

tigattack commented Jul 22, 2024

The fix for this in #4103 was reverted by #4213. It's now broken again. This issue should be reopened.

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

Successfully merging a pull request may close this issue.

6 participants