Skip to content

Fix #642. Show game meat on hunters returning with prey. #750

Fix #642. Show game meat on hunters returning with prey.

Fix #642. Show game meat on hunters returning with prey. #750

name: Akhenaten clang-format check
on:
push:
branches: [ "master" ]
pull_request_target:
branches: [ "master" ]
permissions:
pull-requests: write
contents: read
jobs:
clang-format:
name: run on linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: update-workspace
run: |
sudo apt -qq update
sudo apt install -y clang-format-20 wget
sudo cp .github/scripts/git-clang-format /usr/local/bin/
sudo chmod +x /usr/local/bin/git-clang-format
sudo ln -sf /usr/bin/clang-format-20 /usr/bin/clang-format
- name: check-format
id: check-formatting
env:
EVENT_NAME: ${{ github.event_name }}
BASE_BRANCH: ${{ github.event.pull_request.base.ref }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
EVENT_BEFORE: ${{ github.event.before }}
run: |
BASE_BRANCH="${BASE_BRANCH:-master}"
if [[ "$EVENT_NAME" == pull_request* ]]; then
git fetch origin "$BASE_BRANCH"
base_ref="origin/${BASE_BRANCH}"
head_ref="$HEAD_SHA"
if [ -z "$head_ref" ]; then
echo "head_sha is empty for PR event"
exit 1
fi
else
if [ -n "$EVENT_BEFORE" ] && git rev-parse --verify --quiet "$EVENT_BEFORE" >/dev/null; then
base_ref="$EVENT_BEFORE"
head_ref="HEAD"
else
base_ref="HEAD^1"
head_ref="HEAD"
fi
fi
set +e
output=$(git clang-format --diff "$base_ref" "$head_ref" --extensions cpp,cc,cxx,h,hpp 2>&1)
exit_code=$?
set -e
echo "clang-format output:"
echo "$output"
if [ $exit_code -eq 0 ]; then
echo "clang-format passed."
else
echo "diff<<EOF" >> $GITHUB_OUTPUT
echo "$output" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "clang-format failed."
exit 1
fi
- name: post-comment-on-pull-request
if: failure() && github.event_name == 'pull_request_target'
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const templatePath = '.github/COMMENT_TEMPLATE/code_format_failure.md';
let template;
try {
template = fs.readFileSync(templatePath, 'utf8');
} catch (err) {
console.error('Failed to read template:', err);
template = '## Code formatting issues found\n\nPlease format the code locally to fix these issues.\n\n```diff\n{{DIFF}}\n```';
}
const contributingUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/blob/master/CONTRIBUTING.md`;
const diff = `${{ steps.check-formatting.outputs.diff }}`;
const body = template
.replace(/{{CONTRIBUTING_URL}}/g, contributingUrl)
.replace(/{{DIFF}}/g, diff);
const prNumber = ${{ github.event.pull_request.number }};
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body
});