Skip to content

Time: 0 ms (100.00%) | Memory: 41.9 MB (52.40%) - LeetSync #42

Time: 0 ms (100.00%) | Memory: 41.9 MB (52.40%) - LeetSync

Time: 0 ms (100.00%) | Memory: 41.9 MB (52.40%) - LeetSync #42

Workflow file for this run

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]