Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
132 lines (125 loc) · 5.7 KB
/
Copy pathaction.yml
File metadata and controls
132 lines (125 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Commit Check Action
description: "Commit policy as code for teams and AI agents: check every commit of a pull request against your cchk.toml"
author: shenxianpeng
branding:
icon: "git-commit"
color: "blue"
inputs:
message:
description: check git commit message following conventional commits
required: false
default: true
branch:
description: check git branch name following conventional branch
required: false
default: true
author-name:
description: check committer author name
required: false
default: false
author-email:
description: check committer author email
required: false
default: false
dry-run:
description: report failures (summary, PR comment, annotations as warnings) but always exit 0
required: false
default: false
job-summary:
description: display job summary to the workflow run
required: false
default: true
pr-comments:
description: post results to the pull request comments
required: false
default: false
pr-title:
description: check pull request title following conventional commits
required: false
default: false
message-ai-attribution:
description: check each commit against the AI attribution rules (ai_attribution in cchk.toml) only, without the format rules; overrides message
required: false
default: false
pr-body-ai-attribution:
description: check the pull request description against the AI attribution rules (ai_attribution in cchk.toml)
required: false
default: false
ai-label:
description: label the pull request when an AI tool wrote any of it; true for the label ai-assisted, or the label's name
required: false
default: false
outputs:
result:
description: Structured check results as JSON (status pass/warn/skip/fail + per-scope label, sha and checks). Consume with fromJSON(steps.<id>.outputs.result).
# Composite actions do not forward step outputs automatically: without this
# mapping (and the step id it refers to) the output is always the empty
# string, and fromJSON('') fails the calling workflow.
value: ${{ steps.commit-check.outputs.result }}
runs:
using: "composite"
steps:
- name: Install dependencies and run commit-check
id: commit-check
shell: bash
run: |
# Platform-specific settings
if [[ "$RUNNER_OS" == "Windows" ]]; then
PYTHON_CMD="python"
else
if [[ "$RUNNER_OS" == "Linux" ]]; then
# https://github.com/pypa/setuptools/issues/3269
export DEB_PYTHON_INSTALL_LAYOUT=deb
fi
PYTHON_CMD="python3"
fi
# The pinned commit-check needs Python 3.11+. Say so here: on an older
# python3, pip would only report that no matching version exists.
if ! $PYTHON_CMD -I -c 'import sys; sys.exit(sys.version_info < (3, 11))'; then
echo "::error::commit-check-action needs Python 3.11 or newer on PATH, found $($PYTHON_CMD --version 2>&1). Add actions/setup-python with python-version 3.11 or newer before this step."
exit 1
fi
# Everything the action installs lives under $RUNNER_TEMP, never in the
# caller's checkout: a later `git status`, linter or upload-artifact step
# must not see our venv or wheels.
WORK="$RUNNER_TEMP/commit-check-action"
rm -rf "$WORK" # a second invocation in the same job starts clean, so the wheel glob below matches exactly one file
mkdir -p "$WORK/wheels"
# -I (isolated mode) everywhere below: `python -m` otherwise puts the
# current directory, the caller's checkout, first on sys.path, so a
# pip.py or venv.py at the repository root would run in place of pip
# or venv, with this step's GITHUB_TOKEN.
$PYTHON_CMD -I -m venv "$WORK/venv"
if [[ "$RUNNER_OS" == "Windows" ]]; then
source "$WORK/venv/Scripts/activate"
else
source "$WORK/venv/bin/activate"
fi
# One download of the pinned closure, into the scratch dir. Wheels only:
# the offline install below cannot build an sdist, so a platform without
# binary wheels fails here, with pip's message, rather than later.
$PYTHON_CMD -I -m pip download -q --only-binary=:all: -d "$WORK/wheels" -r "$GITHUB_ACTION_PATH/requirements.txt"
# Verify the commit-check wheel's build provenance (PyGithub and the
# transitive wheels are pinned but not attested; see README "Runner requirements").
WHEEL=$(ls "$WORK"/wheels/commit_check-*.whl) # exactly one: pip download of a == pin
if ! gh attestation verify "$WHEEL" -R commit-check/commit-check; then
echo "::error::Attestation verification failed for $(basename "$WHEEL") (self-hosted runners need the gh CLI). Aborting installation."
exit 1
fi
# Install offline from the wheels we already downloaded and verified:
# no second trip to PyPI, and the installed set is exactly the downloaded set.
$PYTHON_CMD -I -m pip install -q --no-cache-dir --no-index --find-links "$WORK/wheels" -r "$GITHUB_ACTION_PATH/requirements.txt"
$PYTHON_CMD "$GITHUB_ACTION_PATH/main.py"
env:
MESSAGE: ${{ inputs.message }}
BRANCH: ${{ inputs.branch }}
AUTHOR_NAME: ${{ inputs.author-name }}
AUTHOR_EMAIL: ${{ inputs.author-email }}
DRY_RUN: ${{ inputs.dry-run }}
JOB_SUMMARY: ${{ inputs.job-summary }}
PR_COMMENTS: ${{ inputs.pr-comments }}
PR_TITLE: ${{ inputs.pr-title }}
MESSAGE_AI_ATTRIBUTION: ${{ inputs.message-ai-attribution }}
PR_BODY_AI_ATTRIBUTION: ${{ inputs.pr-body-ai-attribution }}
AI_LABEL: ${{ inputs.ai-label }}
GITHUB_TOKEN: ${{ github.token }}