← All recipes
Moderne licensed

Pin GitHub Actions to commit SHAs

Recipe IDorg.openrewrite.github.security.PinGitHubActionsToShaArtifactorg.openrewrite.recipe:rewrite-github-actions

Replaces mutable tag or branch references in GitHub Actions uses: declarations with immutable commit SHAs. A static mapping of well-known actions is checked first; if the action is not found, the GitHub API is used to resolve the reference at recipe run time. By default only third-party actions are pinned; set pinOfficialActions to include actions from the actions and github organizations. To pin only a specific allow-list of actions, set includedActions.

Single recipesupply-chaingithubsecurityactionsMSAL

Add to your build

Get a download tokenThis recipe is Moderne licensed, so the token must belong to a Moderne customer. It replaces YOUR_DOWNLOAD_TOKEN below.

~/.gradle/gradle.properties

codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN

build.gradle.kts

plugins {
    id("org.openrewrite.rewrite") version("latest.release")
}

rewrite {
    activeRecipe("org.openrewrite.github.security.PinGitHubActionsToSha")
}

repositories {
    mavenCentral()
    maven {
        url = uri("https://artifacts.codegenomeproject.org/maven")
        credentials {
            username = providers.gradleProperty("codeGenomeUsername").get()
            password = providers.gradleProperty("codeGenomeToken").get()
        }
    }
}

dependencies {
    rewrite("org.openrewrite.recipe:rewrite-github-actions:3.32.0")
}

Then run

./gradlew rewriteRun

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.github.security.PinGitHubActionsToSha

If the recipe isn’t available locally, install it with:

mod config recipes jar install org.openrewrite.recipe:rewrite-github-actions:RELEASE

Options

NameTypeDescription
pinOfficialActionsBooleanWhen set to true, also pins actions from official GitHub organizations (e.g., actions/*, github/*). Defaults to false, meaning only third-party actions are pinned.
githubApiTokenStringA GitHub personal access token used to resolve tags/branches to commit SHAs via the GitHub API. Only needed for actions not found in the built-in static mapping. Without a token, unauthenticated requests are rate-limited to 60/hour.
e.g. ghp_exampleTokenNotARealToken
trustedOwnersListOptional list of trusted owners/organizations, actions that belong to these organizations will not be pinned. This option overrides the 'Included actions' list.
e.g. my-organization, my-other-organization
includedActionsListOptional allow-list of actions to pin. When provided, only uses: references matching one of these patterns are pinned; all other actions are left untouched. Patterns may be owner/repo (exact match), owner/* (any repo in an org), or owner/repo/subpath (exact match including a subpath). When omitted or empty, all third-party actions (and optionally official actions, per pinOfficialActions) are pinned.
e.g. codecov/codecov-action

Data tables

Structured output this recipe can produce.

  • Source files that had resultsSource files that were modified by the recipe run.org.openrewrite.table.SourcesFileResults
  • Source files that had search resultsSearch results that were found during the recipe run.org.openrewrite.table.SearchResults
  • Source files that errored on a recipeThe details of all errors produced by a recipe run.org.openrewrite.table.SourcesFileErrors
  • Recipe performanceStatistics used in analyzing the performance of recipes.org.openrewrite.table.RecipeRunStats