2

Full error:

File "/opt/hostedtoolcache/Python/3.9.6/x64/lib/python3.9/site-packages/github/Repository.py", line 2154, in update_file
    headers, data = self._requester.requestJsonAndCheck(
  File "/opt/hostedtoolcache/Python/3.9.6/x64/lib/python3.9/site-packages/github/Requester.py", line 353, in requestJsonAndCheck
    return self.__check(
  File "/opt/hostedtoolcache/Python/3.9.6/x64/lib/python3.9/site-packages/github/Requester.py", line 378, in __check
    raise self.__createException(status, responseHeaders, output)
github.GithubException.UnknownObjectException: 404 {"message": "Not Found", "documentation_url": "https://docs.github.com/rest/reference/repos#create-or-update-file-contents"}
Error: Process completed with exit code 1.

I am trying to run a script from my github repo using github workflow which updates a file with new contents.

Here is the code:

g = Github(token)
repo = g.get_repo(repoName)
oldFile = repo.get_contents(oldFilePath)
repo.update_file(oldFile.path, "update file", updatedFile, oldFile.sha, branch="main")

Note: The script, .yml workflow file, and the file being updated are all in the same repo. This same code runs smoothly when I run it on my local machine. But the error occurs when its running via Github workflow.

.yml code:

- name: run .py file
    run: python script.py

Also note: The github token is accessed from the script with os.environ.get(TOKEN_SECRET_NAME)

Sukanta
  • 75
  • 6

1 Answers1

2

You are not passing secret token as env. Try below code

   - name: run .py file
     run: python script.py
     env:
        TOKEN_SECRET_NAME: ${{ secrets.token }}
Sam-Sundar
  • 511
  • 1
  • 4
  • 12
  • This should not be a problem. I know the secret is accessed properly as it is used to authenticate in `g = Github(token)` . I tried it nonetheless and the workflow wont start because of this error: `Invalid workflow file : .github/workflows/python-app.yml#L40 The workflow is not valid. .github/workflows/python-app.yml (Line: 40, Col: 22): Unrecognized named-value: 'secret'. Located at position 1 within expression: secret.TEST_SECRET` – Sukanta Aug 26 '21 at 08:29
  • HOLYYYY SHITT IT WORKED. The only change is thats `secrets.TEST_SECRET` not `secret`. Thank you so much! – Sukanta Aug 26 '21 at 08:38
  • Please feel free to accept my response as answer also in have edited my typo of `secrets` – Sam-Sundar Aug 26 '21 at 19:09