Skip to content

Workflow file for this run

name: Generate code, check format and push to generated processes repo
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
generate-and-check:
runs-on: ubuntu-latest
steps:
- name: Checkout codegen repo
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Run code generator
run: |
if [ ! -e MG5aMC/mg5amcnlo/PLUGIN/CUDACPP_SA_OUTPUT ] ; then pushd MG5aMC/mg5amcnlo/PLUGIN/ && ln -s ../../../epochX/cudacpp/CODEGEN/PLUGIN/CUDACPP_SA_OUTPUT && popd ; fi
./MG5aMC/mg5amcnlo/bin/mg5_aMC test/processes/pp_ttx/output.mg5
- name: Check code format with clang-format
id: clang-format-check
run: |
chmod +x .github/workflows/check-formatting.sh
cd PROC_pp_ttx
$GITHUB_WORKSPACE/.github/workflows/check-formatting.sh
files2format=$(cat files2format)
echo "files2format=$files2format" >> $GITHUB_OUTPUT
if [ "$files2format" -eq 0 ]; then
echo "✅ clang-format check passed."
else
echo "❌ clang-format check failed."
fi
- name: Commit to target repository
if: ${{ steps.clang-format-check.outputs.files2format == '0' }}
env:
TARGET_REPO: roiser/madgraph4gpu-generated-processes
GH_TOKEN: ${{ secrets.MG4GPU_GEN_PAT }}
run: |
# Configure git
git config --global user.name "github-actions"
git config --global user.email "github-actions@users.noreply.github.com"
# Clone target repo
git clone https://x-access-token:${GH_TOKEN}@github.com/${TARGET_REPO}.git
cd madgraph4gpu-generated-processes
# Create branch based on PR number
BRANCH_NAME="codegen-pr-${{ github.event.pull_request.number }}"
git checkout -b ${BRANCH_NAME}
# Copy generated files (adjust paths as needed)
cp -r ${GITHUB_WORKSPACE}/PROC_pp_ttx .
# Commit and push
git add .
git commit -m "Code generated from PR #${{ github.event.pull_request.number }}" \
-m "Source PR: ${{ github.event.pull_request.html_url }}"
git push -f origin ${BRANCH_NAME}
echo "✅ Pushed to ${TARGET_REPO} on branch ${BRANCH_NAME}"
- name: Read patch file
if: ${{ steps.clang-format-check.outputs.files2format != '0' }}
run: |
{
echo "patch_file_content<<EOF"
cat PROC_pp_ttx/format-changes.patch
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Comment on PR with format issues
if: ${{ steps.clang-format-check.outputs.files2format != '0' }}
uses: actions/github-script@v7
with:
script: |
const filesToFormat = parseInt(process.env.FILES2FORMAT);
const patchContent = process.env.PATCH_FILE_CONTENT;
const comment = `## ❌ Code Format Check Failed
The generated code does not conform to clang-format rules.
Please update your code generator to produce properly formatted code.
${filesToFormat} files need formatting.
See attached patch for details:`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `${comment} \n ${patchContent}`
});
env:
FILES2FORMAT: ${{ steps.clang-format-check.outputs.files2format }}
PATCH_FILE_CONTENT: ${{ steps.read-patch-file.outputs.patch_file_content }}
- name: Fail if format check failed
if: ${{ steps.clang-format-check.outputs.files2format != '0' }}
run: exit 1