I have a GitHub workflow that pulls data via an API then commits the data to the repo (an R package) if there are changes to the data pull. This all works fine.
I use something like this:
- name: commit data files
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add someFile
git commit -m "automated commit from api yml"
git push
I then manually update the DESCRIPTION and NEWS.md and create a release. I am trying to automate this part by using usethis::use_github_release in the workflow. Something like this.:
But i recieve this error and don't know how to solve. Any help would be greatly appreciated
env:
GITHUB_PAT: ***
R_REMOTES_NO_ERRORS_FROM_WARNINGS: false
R_LIBS_USER: /home/runner/work/_temp/Library
TZ: UTC
_R_CHECK_SYSTEM_CLOCK_: FALSE
NOT_CRAN: true
✔ Setting active project to '/home/runner/work/teststocksmartapi/teststocksmartapi'
Error in `stop_bad_github_remote_config()`:
! Unsupported GitHub remote configuration: 'no_github'
• Host = NA
• origin = <not configured>
• upstream = <not configured>
• Neither 'origin' nor 'upstream' is a GitHub repo.
If i use "origin" instead of "upstream" in usethis::use_git_remotes i get the following error
✔ Setting active project to '/home/runner/work/teststocksmartapi/teststocksmartapi'
Error in `stop_bad_github_remote_config()`:
! Unsupported GitHub remote configuration: 'theirs'
• Host = 'https://github.com'
• origin = 'andybeet/teststocksmartapi' (can not push)
• upstream = <not configured>
• The only configured GitHub remote is 'origin', which
you cannot push to.
If your goal is to make a pull request, you must fork-and-clone.
`usethis::create_from_github()` can do this.
When i type git remote -v from withing R-Studio's terminal i see "https://github.com/.../myrepo"
Not sure if you meant to do that from local machine or from within the github action.
The command usethis::git_remotes()[["origin"]] (used in the current workflow, above) provides the same result, "http://github.com/.../myrepo.
I edited by initial thread to show the error when i use "origin" instead of "upstream"
Yes, from the GHA workflow, as that's where you call usethis from.
usethis is a bit peculiar about your git/github repo setup. It supports a number of common setups, but it wasn't really designed for running it on GHA.
• Host = 'https://github.com'
• origin = 'andybeet/teststocksmartapi' (can not push)
• upstream = <not configured>
• The only configured GitHub remote is 'origin', which
you cannot push to.
This seems pretty close. Seems like usethis uses the GH API to check if you (i.e. the GH PAT) can push to the repo. So you'll need a token that is allowed to push. Maybe by adding a token manually to the workflow and then injecting it into the GITHUB_PAT env var. Alternatively, maybe adding
permissions:
contents: write
to the job works as well, with the automatic token.
In addition i also commit and push sucessfully earlier in the workflow.
Either way i added the permissions snippet. It made no difference (assuming i added it in the correct place)
Anyway here is a link to the workflow (maybe i should have done this from the beginning).
Maybe i just can't use the usethis package for this type of thing.
Thanks
But did you actually add a secret manually, with a token that has write access? If you haven't then that's just the default token that does not have write permissions.
So my knowledge of tokens is quite limited. I have been reading the GitHub documentation for PATs and thought i created a personal token (fine grained) and called it GH_RELEASE. i set read/write permission on a bunch of fields.
I then added
env:
GITHUB_PAT: ${{ secrets.GH_RELEASE }}
to the workflow
and now i get a different error
✔ Setting active project to '/home/runner/work/teststocksmartapi/teststocksmartapi'
Error in `stop_maybe_github_remote_config()`:
! Pull request functions can't work with GitHub remote configuration: 'maybe_ours_or_theirs'
The most likely problem is that we aren't discovering your GitHub personal access token
Call `gh_token_help()` for help
• Host = 'https://github.com'
• origin = 'andybeet/teststocksmartapi'
• upstream = <not configured>
• 'origin' is a GitHub repo and 'upstream' is either not configured or is not a GitHub repo.
I think we may have strayed off the original topic and are now in the realms of access tokens and not usethis. I should probably create a new post asking for help with access tokens since i am clearly not understanding what i need to do
Thanks
You have to copy and save the token, to your computer or another safe place. Then add the token as a secret to the repository you want to use is in. Settings -> Secrets and Variables -> Actions -> New repository secret and name the secret GH_RELEASE.
@Gabor OK, think i have it. And i gave the PAT permissions for everything! Looks like it got past the last issue. But now a different error now. Doesn't seem to be able to see commit hash in the repo.
Run usethis::use_github_release(publish = F)
usethis::use_github_release(publish = F)
shell: /usr/local/bin/Rscript {0}
env:
GITHUB_PAT: ***
R_REMOTES_NO_ERRORS_FROM_WARNINGS: false
R_LIBS_USER: /home/runner/work/_temp/Library
TZ: UTC
_R_CHECK_SYSTEM_CLOCK_: FALSE
NOT_CRAN: true
✔ Setting active project to '/home/runner/work/teststocksmartapi/teststocksmartapi'
✔ Using current HEAD commit for the release
✔ Checking that remote branch 'origin/main' has the changes in 'main'
Error in libgit2::git_remote_fetch :
object not found - no match for id (2ed587b255a9cb4af2bc8dace2ba4c7f67998aa4)
Calls: <Anonymous> ... git_branch_compare -> <Anonymous> -> raise_libgit2_error
Execution halted
Error: Process completed with exit code 1.
Try to use the latest action/checkout@v4 action, and also try to check out all refs. The checkout action only checks out the last commit of a a single branch by default. See here: GitHub - actions/checkout: Action for checking out a repo