feat(actions): manage artifact and log retention - #3600
Conversation
The REST endpoints for artifact and log retention exist at both repository and organization scope, but the setting could only be changed by hand, leaving a storage-cost control outside Terraform. Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
|
👋 Hi, and thank you for this contribution! This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can. You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions. 🤖 This is an automated message. |
|
Please have only 1 PR open for review at a time |
|
@deiga I am just running into the limitations and deciding to contribute. I am not opening for code review without properly test the features against my own org. Do you prefer if I make 1 PR with everything? |
|
@yordis We have very limited capacity for new features at this moment and are going to start enforcing a 1 open PR per new contributor rule. Please don't combine multiple PRs into one, but just have 1 PR open that is self-contained. If you want to increase your chances of getting your PR merged, it would be highly appreciated if you can review other open PRs and spot anything that should be addressed by the authors. |
Resolves #3599
Before the change?
After the change?
Two behaviours worth calling out, because they are forced by the API rather than chosen:
min(90, maximum_allowed_days)so that resetting a repository under an organization with a lower ceiling does not fail.Enterprise scope is deliberately left out of this PR to keep it reviewable; I have no enterprise account to test it against.
How this was verified
Beyond the acceptance tests, both resources were run end to end against a real organization and a throwaway repository, using a locally built provider through
dev_overrides, on OpenTofu 1.9.0 with real credentials and remote state. Organization and repository names are elided below.1 added;GET /orgs/{org}/actions/permissions/artifact-and-log-retentionreturns the configured valuedaysandmaximum_allowed_daysplan -detailed-exitcodeexits0~ days = 7 -> 30, no replacement15 -> 30,1 to changestate rm,import <org>hydrateddaysandmaximum_allowed_days, and the follow-up plan exited0days = 0anddays = 401are both rejected withexpected days to be in the range (1 - 400)repository_idcomputed30, the ceiling, rather than 90; a fixed PUT of 90 would have failed with 409 hereTF_ACC=1, and restores the original value on cleanupOne note on the small error helper in this PR, since it is the least obvious part of the diff. These two endpoints return their rejection reason in an
errorsfield holding a plain string rather than the usual array, soCheckResponsecannot decode it intoErrorResponseand discards the parsed error, includingMessage. Users saw only:go-github does restore the raw body onto the response, which is the only place the reason survives, so the helper reads it back and the same failure now reports:
Pull request checklist
New resources, so no migration is needed.
Does this introduce a breaking change?
Please see our docs on breaking changes to help!
I used an AI assistant while writing this. I have read every line, verified the API behaviour against the REST docs and against live calls rather than taking the model's word for it, and ran the resources end to end against a real organization before opening this, as tabulated above.