-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (45 loc) · 1.76 KB
/
main.yml
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
name: Clean Commit Message
on:
push:
branches:
- main # Adjust to your branch name if different
jobs:
clean-commit-message:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch full history to make amends
- name: Get latest commit message
id: get_commit
run: |
# Get the latest commit hash and message
$commitHash = git log -1 --format=%H
$commitMessage = git log -1 --pretty=%B
echo "Commit hash: $commitHash"
echo "Commit message: $commitMessage"
echo "COMMIT_MESSAGE=$commitMessage" >> $env:GITHUB_ENV
- name: Amend commit message to remove '- LeetSync' variants
run: |
# Retrieve the commit message from the environment variable
$commitMessage = $env:COMMIT_MESSAGE
# Pattern to match '-LeetSync', '- LeetSync', or '-LeetSync' (with optional space after '-')
$pattern = "\s?-?LeetSync\b"
# Check if the commit message contains any of these variants
if ($commitMessage -match $pattern) {
# Remove the variants from the commit message
$newCommitMessage = $commitMessage -replace $pattern, ""
Write-Output "Updated commit message: $newCommitMessage"
# Amend the commit message
git commit --amend -m $newCommitMessage
# Force push the amended commit
git push origin main --force
} else {
Write-Output "No '-LeetSync' variants in commit message, no changes made."
}
env:
GIT_AUTHOR_NAME: GitHub Actions
GIT_AUTHOR_EMAIL: [email protected]
GIT_COMMITTER_NAME: GitHub Actions
GIT_COMMITTER_EMAIL: [email protected]