Skip to content

test: add gh-pin pre-commit#447

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

test: add gh-pin pre-commit#447
dipinknair wants to merge 4 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

modified = False

for line in lines:
bare = line.rstrip("\r\n")

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 only true for Windows files.. shouldn't you strip the line ending for LF files? (i.e. \n)

# 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.

Comment on lines +175 to +176
bare = line.rstrip("\r\n")
eol = line[len(bare) :] # preserves original line ending (LF or CRLF)

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 logic seems a bit convoluted... you are only stripping on Windows, and preserving the line ending in other cases to store the eol... Can we clarify this logic and make it simpler?

@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.

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

Labels

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