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

feat: Add token-type as action input #70

Merged
merged 9 commits into from
Dec 7, 2023

Conversation

Injabie3
Copy link
Contributor

@Injabie3 Injabie3 commented Nov 13, 2023

Currently, a personal access token (PAT) is required to use this action. This requires granting the user- or organization-wide delete:packages scope, which may be undesirable if it's pertaining to images generated from the same repository where this action is being used.

In order to use the GITHUB_TOKEN token during an action run, this PR adds a token-type input to the action. This is an enum that can take either pat or github-token. If it is set to github-token, then ${{ secrets.GITHUB_TOKEN }} can be passed into the token input.

The caveat is that the image_names input must be a single image that matches the package name of the repository from where this action is being invoked: GITHUB_TOKEN currently doesn't have sufficient permissions to look into other packages of the user/organization. This is also the reason why all lookups to list packages are skipped when token-type is set to github-token.

If the images-names input doesn't match the package name for the repository, then the action will fail.

This touches upon #27 for single images only.

This commit adds the ability to use the built-in GITHUB_TOKEN secret as
passed into the GitHub Actions runner instead of providing a personal
access token (PAT) as a secret into the action for image deletion for a
package that lives in the same repository as the GitHub repository.

In order to do so, `image-name` needs to match the package name for the
repository from where this action is being invoked.
Copy link
Member

@sondrelg sondrelg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if this is a bit premature. I see the PR is still a draft. That said, do you think it might be clearer to users if we call it TOKEN_IS_GITHUB_TOKEN or something to that effect, rather than USE_GITHUB_TOKEN? Perhaps GITHUB_TOKEN_TYPE and have the default be PAT?

main.py Outdated Show resolved Hide resolved
@Injabie3
Copy link
Contributor Author

That said, do you think it might be clearer to users if we call it TOKEN_IS_GITHUB_TOKEN or something to that effect, rather than USE_GITHUB_TOKEN? Perhaps GITHUB_TOKEN_TYPE and have the default be PAT?

Thanks for the feedback! I like the TOKEN_TYPE idea: I'll swap to this and have it be an enum that takes either pat or github-token.

This commit changes the `use-github-token` input to `token-type`, which
accepts a value of either `pat` or `github-token`.
This commit moves the `token-type` info within README.md closer to
`token`. It also adds a small snippet to token regarding the use of
GITHUB_TOKEN.
@sondrelg
Copy link
Member

Sounds great. Just ping me when you want me to take a look 👍

This commit adds a test case to validate the `token_type` passed into
Inputs against valid GithubTokenType enum values.

Note to self: In order for pydantic validation to work, the `input_names`
validator needs to check for the existence of `token_type` in
ValidationInput. This will not exist if `token_type` is invalid, and it
will be caught by the default validator. This is similar to what was
done in the `validate_org_name` field validator.
Copy link

codecov bot commented Nov 13, 2023

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (a45cd46) 93.27% compared to head (d855ecd) 90.51%.
Report is 7 commits behind head on main.

Files Patch % Lines
main.py 81.63% 8 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #70      +/-   ##
==========================================
- Coverage   93.27%   90.51%   -2.76%     
==========================================
  Files           1        1              
  Lines         223      253      +30     
  Branches       54       63       +9     
==========================================
+ Hits          208      229      +21     
- Misses          7       15       +8     
- Partials        8        9       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Injabie3 Injabie3 changed the title feat: Add use-github-token as action input feat: Add token-type as action input Nov 13, 2023
@Injabie3
Copy link
Contributor Author

I think this is ready for additional feedback. FWIW, I hooked my workflow to fb14774, and it was able to delete images from my repository as expected.

@Injabie3 Injabie3 marked this pull request as ready for review November 13, 2023 23:11
@jasonwc
Copy link

jasonwc commented Nov 27, 2023

@Injabie3 Hey really appreciate this work! We just switched our workflows to use GITHUB_TOKEN and are eagerly awaiting this PRs merge. In the meantime, would it be helpful for us to opt in to your change to help test?

@Injabie3
Copy link
Contributor Author

@Injabie3 Hey really appreciate this work! We just switched our workflows to use GITHUB_TOKEN and are eagerly awaiting this PRs merge. In the meantime, would it be helpful for us to opt in to your change to help test?

That would be great, thanks. Do let me know if you have any additional feedback. :)

@Injabie3
Copy link
Contributor Author

Injabie3 commented Dec 7, 2023

@sondrelg just in case this missed your inbox.

@sondrelg
Copy link
Member

sondrelg commented Dec 7, 2023

It did, sorry about that! Will take a look at this today 👍

@sondrelg
Copy link
Member

sondrelg commented Dec 7, 2023

Looks solid @Injabie3. I'll have to rely on @jasonwc and you to verify this works in practice, so please report back if you spot anything. Will release this shortly 👏

@sondrelg sondrelg merged commit 9505983 into snok:main Dec 7, 2023
2 of 4 checks passed
@bendoerr
Copy link

bendoerr commented Dec 7, 2023

Woot! For what it's worth I've been using @Injabie3's branch for the past week and has been working great!

@ChandlerFerry
Copy link
Contributor

I'd have loved to see this be a 3.0.0 release instead of a 2.2.0.
This change is not backwards compatible with snok/container-retention-policy@v2.

@Injabie3 Injabie3 deleted the use-github-token branch December 8, 2023 07:04
@sondrelg
Copy link
Member

sondrelg commented Dec 8, 2023

In what way @ChandlerFerry? The default keeps the old behavior, no?

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

Successfully merging this pull request may close these issues.

5 participants