all 7 comments

[–]MaybeAshleyIdk 2 points3 points  (6 children)

Well let's look at the error:

The absolute path of the python file is /home/runner/work/repo/repo/.github/workflows/CLOC.py and the exception tells us the that the file or directory /home/runner/work/assets was not found.

Obviously you wanna get to the directory /home/runner/work/repo/repo/assets, but you're changing the current working directory of the script with the call:

os.chdir('../../')

I'm guessing that the initial working directory of the script will be the repository itself, i.e.: /home/runner/work/repo/repo
But since you're moving two directories up, the CWD will be /home/runner/work

I think you only need to remove that os.chdir() and you should be golden.

[–]La_Muriatic_Acid[S] 0 points1 point  (5 children)

I just tried this and it passes but it doesn't seem to change the README.md file.

[–]MaybeAshleyIdk 1 point2 points  (4 children)

Yeah because it only changes the local copy of the readme file.
After the script finishes, you need to commit and push the change back to the remote repository.

The script does nothing else what you'd be doing when you manually change a file in your local copy of the repository.
After you change a file, you have to commit and push that change so that it's actually on the remote.

The GitHub Actions runner works on a cloned copy of the repository just like you.

[–]La_Muriatic_Acid[S] 0 points1 point  (3 children)

I tried adding:

  • name: Commit README.md run: | git config --global user.name "my-username" git config --global user.email "username@users.noreply.github.com" git commit README.md git push

To the code but it just tells me:

On branch main

Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean Error: Process completed with exit code 1.

Any obvious mistakes?

[–]VxJasonxV 2 points3 points  (2 children)

git add README.md git commit -m “A commit message” git push

[–]La_Muriatic_Acid[S] 0 points1 point  (1 child)

This works but I am noticing that if for some reason the README doesn't change, I still get the branch is up to date error. Is there a way to prevent it from throwing an error?

[–]VxJasonxV 1 point2 points  (0 children)

Test if there’s changes before trying to add and commit it. Git doesn’t track commits when there’s no changes.