-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (133 loc) · 5.84 KB
/
Copy pathcommit-override-handler.yml
File metadata and controls
147 lines (133 loc) · 5.84 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# file: .github/workflows/commit-override-handler.yml
# version: 1.3.5
# guid: 7a8b9c0d-1e2f-3456-789a-bcdef0123456
# ⚠️ DO NOT EDIT DIRECTLY - This file is managed in ghcommon repository
# All changes should be made in falkcorp/github-common and will be synced to other repositories
# Edit this file at: https://github.com/falkcorp/github-common/edit/main/.github/workflows/commit-override-handler.yml
name: Commit Override Handler
on:
workflow_call:
outputs:
skip-tests:
description: 'Whether to skip test execution'
value: ${{ jobs.check-overrides.outputs.skip-tests }}
skip-validation:
description: 'Whether to skip validation/linting'
value: ${{ jobs.check-overrides.outputs.skip-validation }}
skip-ci:
description: 'Whether to skip CI entirely'
value: ${{ jobs.check-overrides.outputs.skip-ci }}
skip-build:
description: 'Whether to skip build steps'
value: ${{ jobs.check-overrides.outputs.skip-build }}
commit-message:
description: 'The commit message(s) analyzed'
value: ${{ jobs.check-overrides.outputs.commit-message }}
push:
branches: [main, master, develop]
pull_request:
branches: [main, master, develop]
permissions:
contents: read
actions: read
jobs:
check-overrides:
name: Check Commit Overrides
runs-on: ubuntu-latest
outputs:
skip-tests: ${{ steps.check.outputs.skip-tests }}
skip-validation: ${{ steps.check.outputs.skip-validation }}
skip-ci: ${{ steps.check.outputs.skip-ci }}
skip-build: ${{ steps.check.outputs.skip-build }}
commit-message: ${{ steps.check.outputs.commit-message }}
steps:
# NOTE: fetch-depth set to 0 and explicit base branch fetch added to prevent
# 'fatal: bad revision' / exit 128 errors when computing commit range
# on PRs. (Previously the job failed before producing outputs.)
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: recursive
# Need full history (or at least all commits in PR) plus base branch ref for range comparisons
fetch-depth: 0
- name: Fetch base branch ref
if: ${{ github.event_name == 'pull_request' }}
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
# Ensure the base branch ref exists locally; without this git log origin/<base>..HEAD fails (exit 128)
git fetch --no-tags --depth=1 origin "$DEFAULT_BRANCH"
echo "Fetched base branch $DEFAULT_BRANCH for comparison"
- name: Detect ghcommon workflow ref
id: ghcommon-ref
run: |
if [ -f .github/ghcommon-ref.txt ]; then
ref="$(cat .github/ghcommon-ref.txt)"
else
ref="e73b80106099118143806b0ce58e0a73cbcfb27c"
fi
echo "ref=${ref}" >> "$GITHUB_OUTPUT"
- name: Checkout ghcommon workflow scripts
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# do not add submodules: recursive here — sparse-checkout can't lazy-fetch .gitmodules, causing a promisor-fetch 400
repository: falkcorp/github-common
ref: ${{ steps.ghcommon-ref.outputs.ref }}
path: .ghcommon
sparse-checkout: |
scripts/workflows/check_commit_overrides.py
sparse-checkout-cone-mode: false
- name: Check commit messages for override keywords
id: check
env:
EVENT_NAME: ${{ github.event_name }}
PULL_BASE_REF: ${{ github.event.pull_request.base.ref }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
python3 "$GITHUB_WORKSPACE/.ghcommon/scripts/workflows/check_commit_overrides.py"
# This job can be referenced by other workflows to conditionally skip steps
notify-overrides:
name: Notify Override Status
runs-on: ubuntu-latest
needs: check-overrides
if: needs.check-overrides.outputs.skip-ci != 'true'
steps:
- name: Display override status
env:
SKIP_TESTS: ${{ needs.check-overrides.outputs.skip-tests }}
SKIP_VALIDATION: ${{ needs.check-overrides.outputs.skip-validation }}
SKIP_BUILD: ${{ needs.check-overrides.outputs.skip-build }}
run: |
SUMMARY_FILE="${GITHUB_STEP_SUMMARY}"
{
echo "## 🎛️ CI Override Configuration"
echo ""
echo "The following overrides are active for this workflow:"
echo ""
} >> "${SUMMARY_FILE}"
if [ "$SKIP_TESTS" = "true" ]; then
echo "- 🚫 **Tests will be skipped**" >> "${SUMMARY_FILE}"
else
echo "- ✅ **Tests will run normally**" >> "${SUMMARY_FILE}"
fi
if [ "$SKIP_VALIDATION" = "true" ]; then
echo "- 🚫 **Validation/Linting will be skipped**" >> "${SUMMARY_FILE}"
else
echo "- ✅ **Validation/Linting will run normally**" >> "${SUMMARY_FILE}"
fi
if [ "$SKIP_BUILD" = "true" ]; then
echo "- 🚫 **Build steps will be skipped**" >> "${SUMMARY_FILE}"
else
echo "- ✅ **Build steps will run normally**" >> "${SUMMARY_FILE}"
fi
{
echo ""
echo "### Available Override Keywords"
echo ""
echo "Use these in your commit messages to control CI behavior:"
echo ""
echo "- **Skip Tests**: \`[skip tests]\`, \`[no tests]\`, \`SKIP TESTS\`"
echo "- **Skip Validation**: \`[skip validation]\`, \`[skip lint]\`, \`SKIP VALIDATION\`"
echo "- **Skip CI**: \`[skip ci]\`, \`[ci skip]\`, \`SKIP CI\`"
echo "- **Skip Build**: \`[skip build]\`, \`[no build]\`, \`SKIP BUILD\`"
} >> "${SUMMARY_FILE}"