Skip to content

Commit 4e50b9a

Browse files
committed
ci: pin PyPI publisher action by commit
1 parent 66d871d commit 4e50b9a

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎.github/workflows/package.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,14 @@ jobs:
336336

337337
- name: Publish to TestPyPI
338338
if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish_target == 'testpypi' }}
339-
uses: pypa/gh-action-pypi-publish@v1.14.2 # v1.14.2 image tag is required by this composite action
339+
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
340340
with:
341341
packages-dir: dist
342342
repository-url: https://test.pypi.org/legacy/
343343

344344
- name: Publish to PyPI
345345
if: ${{ (github.event_name == 'push' && github.ref_type == 'tag') || (github.event_name == 'workflow_dispatch' && inputs.publish_target == 'pypi') }}
346-
uses: pypa/gh-action-pypi-publish@v1.14.2 # v1.14.2 image tag is required by this composite action
346+
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
347347
with:
348348
packages-dir: dist
349349

‎tests/test_package_workflow.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import re
34
from pathlib import Path
45

56
import yaml
@@ -24,11 +25,18 @@ def test_package_workflow_can_recover_an_immutable_tag_from_default_branch() ->
2425
assert '--source-commit "$SOURCE_COMMIT"' in workflow
2526

2627

27-
def test_package_workflow_uses_a_published_pypi_publisher_image_tag() -> None:
28+
def test_package_workflow_uses_the_pinned_pypi_publisher_release() -> None:
2829
workflow = (Path(__file__).resolve().parents[1] / ".github/workflows/package.yml").read_text(encoding="utf-8")
2930

30-
assert workflow.count("uses: pypa/gh-action-pypi-publish@v1.14.2") == 2
31-
assert "pypa/gh-action-pypi-publish@a892a5a61159132606e93a2fa6f4358831b04d26" not in workflow
31+
assert workflow.count("uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086") == 2
32+
33+
34+
def test_package_workflow_pins_every_third_party_action_to_a_full_sha() -> None:
35+
workflow = (Path(__file__).resolve().parents[1] / ".github/workflows/package.yml").read_text(encoding="utf-8")
36+
refs = re.findall(r"^\s*-?\s*uses:\s+[^@\s]+@([^\s#]+)", workflow, flags=re.MULTILINE)
37+
38+
assert refs
39+
assert all(re.fullmatch(r"[0-9a-f]{40}", ref) for ref in refs), refs
3240

3341

3442
def test_package_workflow_does_not_replace_published_release_assets() -> None:

0 commit comments

Comments
 (0)