Skip to content

Commit eab55e0

Browse files
committed
Add .github/workflows/fortran-formatting.yaml
1 parent da63617 commit eab55e0

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Codee format Fortran
2+
3+
on:
4+
pull_request:
5+
branches: [develop]
6+
types: [opened, synchronize, labeled, unlabeled]
7+
8+
env:
9+
CODEE_VERSION: 2025.4.5
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
format:
17+
name: Check and fix Fortran formatting
18+
runs-on: ubuntu-22.04
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Get modified Fortran files
27+
#id: modified-files
28+
run: |
29+
git remote -v show
30+
git fetch origin ${{ github.base_ref }}
31+
MODIFIED_FILES=$(git diff --name-only --diff-filter=d origin/${{ github.base_ref }}...HEAD -- '*.f90' '*.F90' '*.f' '*.F')
32+
echo "MODIFIED_FILES=$MODIFIED_FILES" >> $GITHUB_ENV
33+
34+
- name: Install Codee
35+
if: env.MODIFIED_FILES != ''
36+
run: |
37+
echo "Installing Codee ${CODEE_VERSION} ..."
38+
wget https://codee.com/release/codee-${CODEE_VERSION}-linux-x86_64.tar.gz
39+
tar -xf codee-${CODEE_VERSION}-linux-x86_64.tar.gz
40+
41+
- name: Run `codee format` on modified files
42+
if: env.MODIFIED_FILES != ''
43+
run: |
44+
export PATH="${PWD}/codee-${CODEE_VERSION}-linux-x86_64/bin:${PATH}"
45+
codee format --accept-eula --verbose $MODIFIED_FILES
46+
47+
- name: Fail if there are uncommitted changes and the `fix-fortran-format` label is not present
48+
if: ${{ env.MODIFIED_FILES != '' && !contains(github.event.pull_request.labels.*.name, 'fix-fortran-format') }}
49+
run: |
50+
git diff --quiet || (echo "Formatting issues detected. Run 'codee format' locally or attach label 'fix-fortran-format' to this PR." && exit 1)
51+
52+
# - name: Fix formatting if label 'fix-fortran-format; is present
53+
# if: ${{ env.MODIFIED_FILES != '' && contains(github.event.pull_request.labels.*.name, 'fix-fortran-format') }}
54+
# run: |
55+
# export PATH="${PWD}/codee-${CODEE_VERSION}-linux-x86_64/bin:${PATH}"
56+
# git codee-format --diff origin/${{ github.base_ref }} HEAD
57+
# git diff
58+
59+
- name: Commit changes if the `fix-fortran-format` label is not present
60+
if: ${{ env.MODIFIED_FILES != '' && contains(github.event.pull_request.labels.*.name, 'fix-fortran-format') }}
61+
run: |
62+
if ! git diff --quiet; then
63+
# Push with the github-actions user. More information at:
64+
# https://github.com/actions/checkout?tab=readme-ov-file#push-a-commit-using-the-built-in-token
65+
git commit -c user.name="github-actions[bot]" -c user.email="41898282+github-actions[bot]@users.noreply.github.com" -am "Apply codee format formatting fixes"
66+
echo "DH DEBUG: 'git push --set-upstream origin ${{ github.head_ref }}'"
67+
git push --set-upstream origin ${{ github.head_ref }}
68+
else
69+
echo "No changes detected."
70+
exit 0
71+
fi

0 commit comments

Comments
 (0)