Skip to main content

Using actions.lock

This tutorial explains how to pin the actions used in the GitHub Actions workflow that deploys to KurocoFront to fixed commits, using a workflow dependency lockfile (.github/workflows/actions.lock).

What is actions.lock?​

In a workflow's uses:, actions are referenced by a tag or branch, such as actions/checkout@v7. A tag or branch is a name that points to a specific commit, and the owner of the repository that publishes the action can later change which commit it points to. Each time the workflow runs, GitHub Actions runs the code of the commit that the tag or branch points to at that moment.

For example, a tag such as v7 is commonly updated to point to the latest commit each time a new version is released. In addition, if the account of the repository owner is compromised, even a tag that specifies a detailed version, such as v7.0.1, can be moved to a commit that contains malicious code. In that case, the code it was moved to runs at the next deployment, even if you have not changed your workflow.

actions.lock is a file that pins each action used by your workflows (including the actions used inside those actions) to a single commit. It is generated with the GitHub CLI extension gh actions-lock and is never edited by hand.

For details, see Workflow dependency lockfiles in GitHub Docs.

note

The following are not pinned by actions.lock. The YAML sample shown on the Kuroco management screen uses neither of them.

  • Reusable workflows called with a job-level uses: (jobs.<job_id>.uses)
  • Actions in the same repository referenced with a path starting with ./ (local actions). If a local action uses external actions, gh actions-lock fails with an error. For how to handle this, see Locking action dependencies in a repository's workflows in GitHub Docs.
info

actions.lock is generated for each repository that contains the workflows, so it is not included in the YAML sample shown on the Kuroco management screen. After placing the YAML file in .github/workflows, generate it in your own repository.
For how to place the YAML file, see Deploying the data source from GitHub to KurocoFront.

Prerequisites​

  • The YAML file for deploying to KurocoFront is placed under .github/workflows in your repository.
  • The repository is cloned to your local environment.

Creating actions.lock​

1. Check the action versions​

actions.lock pins each action to the commit that its tag or branch points to when the file is created. Before creating it, check that the versions of the actions in uses: of your YAML file are the versions you want to pin.

To update action versions, see Is there a way to keep GitHub Actions workflow actions up to date?

2. Install gh actions-lock​

Install the GitHub CLI, then log in to GitHub with the following command.

gh auth login

Install the gh actions-lock extension with the following command.

gh extension install github/gh-actions-lock

3. Generate actions.lock​

Run the following command in the root directory of your repository. All workflows under .github/workflows are processed, and .github/workflows/actions.lock is generated.

gh actions-lock

To process a specific workflow only, pass its path.

gh actions-lock .github/workflows/build.yml

4. Review the changes and commit​

In addition to generating actions.lock, gh actions-lock rewrites uses: in your workflows to the version it pinned. For example, actions/checkout@v7 becomes the resolved version, such as actions/checkout@v7.0.1. Because v7.0.1 points to the same commit as the original v7, the pinned commit does not change.

actions.lock looks like the following (excerpt from the sample repository front_next_media).

.github/workflows/actions.lock
# This file is machine-generated by `gh actions-lock`.
# Do not edit by hand; run `gh actions-lock` to update.
# Docs: https://gh.io/actions-lockfile
version: 'v0.0.3'
workflows:
'.github/workflows/build.yml':
- 'actions/checkout@v7.0.1'
...
dependencies:
'actions/checkout@v7.0.1':
ref: 'v7.0.1'
commit: 'sha1-3d3c42e5aac5ba805825da76410c181273ba90b1'
owner_id: 44036562
repo_id: 197814629
...

Review the diff, then commit both actions.lock and the rewritten workflows.

caution

If your repository, organization, or enterprise only allows specified actions, check the allowlist before you commit. For workflows covered by the lockfile, the allowlist is checked against the pinned commits instead of tags, so allowlist entries pinned to a tag, such as actions/checkout@v7, no longer match. In the allowlist, specify actions with a wildcard or a full commit SHA instead. For details, see Locking action dependencies in a repository's workflows in GitHub Docs.

5. Verify that actions.lock matches the workflows​

Run the following command to check that actions.lock matches your workflows.

gh actions-lock --verify

If they match, the following is displayed.

✓ All 1 workflow valid

Updating actions​

After changing uses: in a workflow, run gh actions-lock again and commit both the workflow and actions.lock. Do the same when you add a workflow, or add or remove uses: entries.

If an action used by a workflow is not included in actions.lock, GitHub Actions rejects the workflow run. If you change uses: without regenerating actions.lock, the deployment to KurocoFront does not run.

If you update actions with Dependabot, Dependabot also updates actions.lock in the same pull request for workflows covered by the lockfile.

Container image of diverta/workflow-webhook​

diverta/workflow-webhook, which the YAML on the management screen uses to notify Kuroco of deployments, is an action that runs a container image. actions.lock pins the action's commit, not the container image. Therefore, gh actions-lock shows a warning like the following. The same warning is also shown when you run gh actions-lock --verify. Even when the warning is shown, actions.lock is generated and the --verify check succeeds.

! container image ghcr.io/distributhor/workflow-webhook-container:v3.0.7 is not pinned by digest
↳ used by .github/workflows/build.yml: diverta/workflow-webhook@v3.0.7
↳ the lockfile pins action commits, not container images; ask the maintainer of diverta/workflow-webhook@v3.0.7 to pin it by digest
↳ https://github.com/github/gh-actions-lock/blob/main/docs/troubleshooting.md#container-image

Samples​

The following sample repositories use actions.lock.


Support

If you have any other questions, please contact us or check out Our Slack Community.