-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Determine Git commit author from token #85
Conversation
Signed-off-by: robot9001 <[email protected]>
action.yml
Outdated
|
||
echo "name=${USER_NAME}" >> "${GITHUB_OUTPUT}" | ||
echo "email=${USER_EMAIL}" >> "${GITHUB_OUTPUT}" | ||
# env GITHUB_TOKEN from action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the purpose of this comment? Is the GITHUB_TOKEN env variable used in gh
here or we need to do something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my concern is that if we don't use a token for the gh
cli we could get rate-limited. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it says that we can set the GH_TOKEN
env variable. Should we run gh as GH_TOKEN=GITHUB_TOKEN gh api ...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment just says that the GITHUB_TOKEN
environment variable is implicit and used/required here, just like in the other steps in the action.yml
further below it.
IMHO the better design would be instead of:
- name: Run release-plz
uses: MarcoIeni/[email protected]
with: # <--- Input variables
command: release-pr
registry: my-registry
project_manifest: rust-crates/my-crate/Cargo.toml
version: release-plz-v0.2.45
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
To use an explicit input variable for the token:
In action.yml
:
inputs:
token:
description: "INPUT: GitHub token with access as per https://release-plz.ieni.dev/docs/github/trigger "
required: false
default: ${{ github.token }}
In a user workflow:
- name: Run release-plz
uses: MarcoIeni/[email protected]
with: # <--- Input variables
command: release-pr
registry: my-registry
project_manifest: rust-crates/my-crate/Cargo.toml
version: release-plz-v0.2.45
# no token (i.e. default)
# or Personal Access Token
token: ${{ secrets.MY_PAT }}
# or App token from `actions/create-github-app-token`
# token: ${{ steps.generate-token.outputs.token }}
In action.yml
:
- run: |
…
env:
GITHUB_TOKEN: ${{ inputs.token }}
But that would be an unrelated change for this pull request.
The gh
CLI needs a token either as GH_TOKEN
/ GITHUB_TOKEN
env var (as per the documentation you linked or https://cli.github.com/manual/gh_help_environment or the one in #85 (comment) ). We need it to use the token we use in our Action, because we want to determine the "viewer" data from that very token (i.e. default / PAT / App). It is unlikely we get rate limited since we always use a token per design here, this step doesn't work without authn token.
GitHub Actions always at least have the default token available as GITHUB_TOKEN
env or ${{ github.token }}
variable ( https://docs.github.com/en/actions/learn-github-actions/contexts#github-context ) or ${{ secrets.GITHUB_TOKEN }}
secret ( https://docs.github.com/en/actions/security-guides/automatic-token-authentication ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or in other words, it says that the following is implicit:
- run: |
…
env:
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
because it is redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarcoIeni any updates on this?
I can create a new pull request for the Action to take the token as an input and then rebase this one here onto it once you've merged the other one.
Would you like me to change the code or explain something?
I could add tests for the PAT and App cases, but those would require you to add repository secrets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, sorry, but I didn't have the time to look into this yet. I will try to have a look in the following days 👍
Merged it, seems to work fine! |
I`ve used 5c035ca and successfully had it create a release as expected robo9k/rust-magic#136 (comment) The commits are now correctly attributed to my GitHub App https://github.com/robo9k/rust-magic/commits?author=arbeitsmaschine%5Bbot%5D |
For release-plz/release-plz#999
Determine Git
user.name
anduser.email
from the GitHub token.Examples
Default token:
Personal Access Token (@robo9k):
Note that this doesn not leak the user email, even if they have one set to publically visible on their profile https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-email-preferences/setting-your-commit-email-address#setting-your-commit-email-address-on-github
https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-user-account-settings/changing-your-github-username#your-git-commits
GitHub App (
arbeitsmaschine
):Note that the previously hardcoded
release-plz <[email protected]>
will NOT be used anymore.