Add return_token input to enable sharing rotated tokens across jobs
Closes #4 (closed)
Summary
This MR adds a return_token boolean input to all token rotation components, allowing tokens to be returned via dotenv artifacts for use in downstream jobs. This enables platform project owners to rotate a token once and update multiple CI/CD variables across different projects.
Changes
- Add
return_tokenboolean input (default: false) to all three components:rotate-patrotate-project-access-tokenrotate-group-access-token
- Create dotenv artifact with
NEW_TOKENwhenreturn_token: true - Add
verify-new-tokentest job to validate token availability in downstream jobs - Update
test-name-basedjob to usereturn_token: true - Add comprehensive usage example to README showing multi-project updates
Implementation Details
When return_token: true, the component:
- Rotates the token as usual
- Updates the specified CI/CD variable (existing behavior)
- Creates a
token.envartifact containingNEW_TOKEN=<rotated_token> - Downstream jobs can access
$NEW_TOKENvia GitLab's dotenv artifact feature
Testing
- Updated existing test to use
return_token: true - Added new verification job that checks:
-
$NEW_TOKENvariable is set - Token has correct format (starts with
glpat-) - Token length is reasonable
-
Use Case Example
stages:
- rotate
- update-vars
include:
- component: .../rotate-pat@1.0.0
inputs:
token_name: shared-deployment-token
return_token: true
# ... other inputs
update-project-a:
stage: update-vars
needs: [rotation-job]
script:
- # Use $NEW_TOKEN to update Project A
update-project-b:
stage: update-vars
needs: [rotation-job]
script:
- # Use $NEW_TOKEN to update Project B
This eliminates the workaround of needing one token per CI/CD variable.