Repository navigation
feat: add run-script reusable workflow #2
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| name: "Run script" | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| run: | ||
| description: "Script for the run step" | ||
| type: string | ||
| required: true | ||
| pre-commit-cache: | ||
| description: "Restore the pre-commit cache, saving it on non-PR events" | ||
| type: boolean | ||
| default: false | ||
| full-git-history: | ||
| type: boolean | ||
| description: "Whether to fetch full git history rather than just current HEAD" | ||
| default: false | ||
| github-token: | ||
| type: boolean | ||
| description: "Expose the job's read-only GitHub token to the script as GH_TOKEN" | ||
| default: false | ||
| secrets: | ||
| STEP_SECURITY_API_KEY: | ||
| required: false | ||
| permissions: {} | ||
| jobs: | ||
| run: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| env: | ||
| HARDEN_RUNNER: ${{ secrets.STEP_SECURITY_API_KEY != '' }} # zizmor: ignore[secrets-outside-env] | ||
| steps: | ||
| - name: Harden Runner | ||
| if: env.HARDEN_RUNNER == 'true' | ||
| uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1 | ||
| with: | ||
| use-policy-store: true | ||
| api-key: ${{ secrets.STEP_SECURITY_API_KEY }} # zizmor: ignore[secrets-outside-env] | ||
|
|
||
| - name: Checkout | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| persist-credentials: false | ||
| fetch-depth: ${{ inputs.full-git-history && '0' || '1' }} | ||
|
|
||
| - name: Install mise | ||
| uses: jdx/mise-action@7a4e45a543138629540c9a1616d08632b893e492 # v5.0.1 | ||
| with: | ||
| minimum_release_age: 7d | ||
| cache: true | ||
|
|
||
| # Always read the cache, it's safe to do so even on untrusted PRs. | ||
| - name: Restore pre-commit cache | ||
| if: inputs.pre-commit-cache | ||
|
albertodonato marked this conversation as resolved.
|
||
| id: pre-commit-cache | ||
| uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | ||
| with: | ||
| path: ~/.cache/pre-commit | ||
| key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }} | ||
|
|
||
| - name: Run | ||
| run: ${{ inputs.run }} # zizmor: ignore[template-injection] caller-provided script | ||
| env: | ||
| GH_TOKEN: ${{ inputs.github-token && github.token || '' }} | ||
| # Point prek at the pre-commit cache path so the cache step covers both. | ||
| PREK_HOME: ~/.cache/pre-commit | ||
|
|
||
| # Cache ssave is gated to non-PR events: an untrusted PR run must not be | ||
| # able to write a hook-environment cache that a later trusted build | ||
| # restores and executes (cache poisoning). | ||
| - name: Save pre-commit cache | ||
| if: inputs.pre-commit-cache && github.event_name != 'pull_request' && steps.pre-commit-cache.outputs.cache-hit != 'true' | ||
| uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | ||
| with: | ||
| path: ~/.cache/pre-commit | ||
| key: ${{ steps.pre-commit-cache.outputs.cache-primary-key }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
P2: Renaming these job IDs changes the status check names (
lint / runbecomesLint / run,testbecomesTests). Any branch protection or ruleset that requires the old names will wait forever for checks that no longer run. Confirm the required-check list is updated in the same change, or keep the existing job IDs.Prompt for AI agents
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.
that's handled in https://github.com/stacklet/cloud-infra/pull/1323