Skip to content

greenc-FNAL fixing CMake format #1675

greenc-FNAL fixing CMake format

greenc-FNAL fixing CMake format #1675

name: CMake Format Fix
run-name: "${{ github.actor }} fixing CMake format"
"on":
issue_comment:
types:
- created
workflow_dispatch:
inputs:
ref:
description:
"The branch name to checkout and push fixes to (must be a branch, not a commit SHA). Defaults to the
repository's default branch."
required: false
type: string
workflow_call:
inputs:
checkout-path:
description: "Path to check out code to"
required: false
type: string
ref:
description: "The branch name to checkout and push fixes to (must be a branch, not a commit SHA)"
required: true
type: string
repo:
description: "The repository to checkout from"
required: true
type: string
skip-comment:
description: "Skip posting PR comments"
required: false
type: boolean
default: false
outputs:
changes:
description: "Whether any fixes were applied"
value: ${{ jobs.apply_cmake_formatting.outputs.changes }}
pushed:
description: "Whether the fixes were pushed to the remote branch"
value: ${{ jobs.apply_cmake_formatting.outputs.pushed }}
commit_sha:
description: "The full commit SHA of the applied fixes"
value: ${{ jobs.apply_cmake_formatting.outputs.commit_sha }}
commit_sha_short:
description: "The short commit SHA of the applied fixes"
value: ${{ jobs.apply_cmake_formatting.outputs.commit_sha_short }}
patch_name:
description: "Name of the patch file if fixes could not be pushed"
value: ${{ jobs.apply_cmake_formatting.outputs.patch_name }}
permissions:
pull-requests: write
contents: write
issues: write
jobs:
setup:
runs-on: ubuntu-latest
name: Parse command
if: >
inputs.ref != '' || github.event_name == 'workflow_dispatch' || (
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
contains(fromJSON('["OWNER", "COLLABORATOR", "MEMBER"]'), github.event.comment.author_association) &&
startsWith(github.event.comment.body, format('@{0}bot cmake-fix', github.event.repository.name))
)
outputs:
ref: ${{ steps.setup.outputs.ref }}
repo: ${{ steps.setup.outputs.repo }}
checkout_path: ${{ steps.setup.outputs.checkout_path }}
steps:
- name: Workflow setup
id: setup
uses: Framework-R-D/action-workflow-setup@f73307dd8c13cb66c2565c9ace32571517b1cea8 # v1
with:
mode: fix
ref: ${{ inputs.ref }}
repo: ${{ inputs.repo }}
checkout-path: ${{ inputs.checkout-path }}
apply_cmake_formatting:
runs-on: ubuntu-latest
name: Apply CMake formatting
needs: setup
if: needs.setup.result == 'success'
outputs:
changes: ${{ steps.handle_commit.outputs.changes }}
pushed: ${{ steps.handle_commit.outputs.pushed }}
commit_sha: ${{ steps.handle_commit.outputs.commit_sha }}
commit_sha_short: ${{ steps.handle_commit.outputs.commit_sha_short }}
patch_name: ${{ steps.handle_commit.outputs.patch_name }}
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: ${{ needs.setup.outputs.checkout_path }}
ref: ${{ needs.setup.outputs.ref }}
repository: ${{ needs.setup.outputs.repo }}
token: ${{ secrets.WORKFLOW_PAT }}
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
- name: Install gersemi
run: uv tool install gersemi
- name: Apply CMake formatting
working-directory: ${{ needs.setup.outputs.checkout_path }}
run: |
echo "Applying CMake formatting..."
gersemi -i .
- name: Handle fix commit
id: handle_commit
uses: Framework-R-D/action-handle-fix-commit@c01368081dd06cbe5ef47b4a085dc6359a657a7f # v2
with:
tool: cmake-format
working-directory: ${{ needs.setup.outputs.checkout_path }}
token: ${{ secrets.WORKFLOW_PAT }}
pr-info-ref: ${{ needs.setup.outputs.ref }}
pr-info-repo: ${{ needs.setup.outputs.repo }}
skip-comment: ${{ inputs.skip-comment }}
- name: Update PR comment reactions
if: always() && github.event_name == 'issue_comment' && !inputs.skip-comment
uses: Framework-R-D/action-complete-pr-comment@5d16749c32fbb7b15503f264dde6e3c98b90b4fb # v2
with:
status: ${{ job.status }}