Skip to content

test: add gh-pin pre-commit - #447

Draft
dipinknair wants to merge 13 commits into
mainfrom
feat/gh-pin
Draft

test: add gh-pin pre-commit#447
dipinknair wants to merge 13 commits into
mainfrom
feat/gh-pin

Conversation

@dipinknair

Copy link
Copy Markdown
Contributor

Add ghaction-pin pre-commit hook

Adds a new hook that automatically pins GitHub Actions uses: references from mutable tags to immutable commit SHAs, improving supply-chain security.

Before:

- uses: ansys/actions/code-style@v10.3.2

After:

- uses: ansys/actions/code-style@d946b24b9a765f4169bcc94afdb27bd1a0533741 # v10.3.2

What it does

  • Scans one or more workflow YAML files or directories recursively
  • Resolves each tag/branch ref to its full 40-character commit SHA via the GitHub commits API (no authentication required for public repos)
  • Preserves the original tag as an inline comment for human readability
  • Skips lines already pinned to a SHA; warns about uses: lines missing a ref entirely
  • Handles both LF and CRLF line endings

Usage

- repo: https://github.com/ansys/pre-commit-hooks
  rev: <tag>
  hooks:
    - id: ghaction-pin
      args:
        - .github/workflows

@github-actions github-actions Bot added maintenance Package and maintenance related enhancement New features or code improvements labels Jun 17, 2026
@dipinknair

Copy link
Copy Markdown
Contributor Author

This is a test run that I ran in embedding example repo
https://github.com/ansys/pymechanical-embedding-examples/pull/327/changes

@dipinknair
dipinknair requested review from a team, AlejandroFernandezLuces, RobPasMue, SMoraisAnsys and jorgepiloto and removed request for a team, AlejandroFernandezLuces and SMoraisAnsys June 17, 2026 17:03

@RobPasMue RobPasMue left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! I just see a few issues JSYK, but maybe we can document this. And solve/improve the logic-related ones

Comment thread src/ansys/pre_commit_hooks/ghaction_pin.py Outdated
# Constants
# ---------------------------------------------------------------------------

_GITHUB_API = "https://api.github.com"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to fail on pre-commit.ci... pre-commit.ci has no access to the web.

@dipinknair dipinknair Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://results.pre-commit.ci/run/github/627525284/1782166214.Op1Xr2HgRWKkTFLLOsqXNA

this was with the branch and commits at the time you commented this. Does this mean pre-commit ci will not have any issues ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm interesting.. seems like they changed something and now pre-commit.ci might have access to the web.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give it a try so that the hook "fails" (i..e. it detects actions that need to be pinned down and have pre-commit.ci change them)

@dipinknair dipinknair Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if pre-commit,ci is unable to access internet then silently passes gh-pin check. May be it might bot be effective with pre-commit.ci but its really helpful doing local commit.

Comment thread src/ansys/pre_commit_hooks/ghaction_pin.py Outdated
@dipinknair

Copy link
Copy Markdown
Contributor Author

I like it! I just see a few issues JSYK, but maybe we can document this. And solve/improve the logic-related ones

Thank you. I will rectify the issues and thank you for the valuable feedbacks.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jun 22, 2026
@RobPasMue

Copy link
Copy Markdown
Member

I see this branch is still in draft mode ... let us know when we can review it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New features or code improvements maintenance Package and maintenance related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants