forked from open-algebra/Oasis
-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (46 loc) · 1.88 KB
/
format-cmake.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# ##############################################################################
# OASIS: Open Algebra Software for Inferring Solutions
#
# format-cmake.yml
# ##############################################################################
name: Format CMake
on:
pull_request:
branches: [ "master" ]
workflow_dispatch:
jobs:
format:
runs-on: ubuntu-latest
steps:
# Checks out the repository.
- name: Checkout repository
uses: actions/checkout@v4
# Installs cmakelang.
- name: Install cmakelang
run: pip install cmakelang
# Runs cmake-format on all CMakeLists.txt files.
- name: Run cmake-format
run: find . -name CMakeLists.txt -type f -execdir bash -c "cmake-format -i {}" \;
# Checks for modified files.
- name: Check for modified files
id: check-file-modified
shell: bash
run: echo "files-modified=$(git diff --name-only | wc -l)" >> "$GITHUB_OUTPUT"
# Commits and pushes changes.
- name: Commit and push
if: |
github.event_name == 'workflow_dispatch' &&
steps.check-file-modified.outputs.files-modified != 0
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git commit -am "[Actions] Format CMakeLists.txt"
git push
# Fails if the workflow hasn't been run in the contributor's fork.
- name: Reject on edits
if: |
github.event_name == 'pull_request' &&
steps.check-file-modified.outputs.files-modified != 0
uses: actions/github-script@v6
with:
script: core.setFailed('The workflow must be run on your fork before merging a PR.')