[Vcpkg] clean PR clutters commit #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Clean PR Commit Messages | |
on: | |
pull_request: | |
types: [opened, synchronize] | |
jobs: | |
clean-commit-message: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Extract PR commits | |
id: extract_pr_commits | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const commits = await github.rest.pulls.listCommits({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.payload.pull_request.number | |
}); | |
return { | |
commits: commits.data.map(commit => commit.sha).join('\n') | |
}; | |
- name: Clean commit messages | |
run: | | |
commit_shas=$(echo "${{ steps.extract_pr_commits.outputs.commits }}" | tr '\n' ' ') | |
cleaned_messages="" | |
for sha in $commit_shas; do | |
message=$(git log --format=%B -n 1 $sha) | |
cleaned_message=$(echo "$message" | sed 's/<!--.*-->//g' | sed '/^$/d') | |
cleaned_messages+="$cleaned_message"$'\n' | |
done | |
git reset --soft HEAD~$(echo $commit_shas | wc -w) | |
IFS=$'\n' | |
for cleaned_message in ${cleaned_messages}; do | |
git commit -m "${cleaned_message}" | |
done | |
- name: Push cleaned commit messages | |
run: | | |
git push --force-with-lease | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |