Skip to content

Commit faa0f6d

Browse files
committed
Add .github/workflows/fortran-formatting.yaml
1 parent 1891310 commit faa0f6d

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
24+
- name: Get modified Fortran files
25+
#id: modified-files
26+
run: |
27+
MODIFIED_FILES=$(git diff --name-only --diff-filter=d origin/${{ github.base_ref }}...HEAD -- '*.f90' '*.F90' '*.f' '*.F')
28+
echo "MODIFIED_FILES=$MODIFIED_FILES" >> $GITHUB_ENV
29+
30+
- name: Install Codee
31+
if: env.MODIFIED_FILES != ''
32+
run: |
33+
echo "Installing Codee ${CODEE_VERSION} ..."
34+
wget https://codee.com/release/codee-${CODEE_VERSION}-linux-x86_64.tar.gz
35+
tar -xf codee-${CODEE_VERSION}-linux-x86_64.tar.gz
36+
37+
- name: Run `codee format` on modified files
38+
if: env.MODIFIED_FILES != ''
39+
run: |
40+
export PATH="${PWD}/codee-${CODEE_VERSION}-linux-x86_64/bin:${PATH}"
41+
codee format --accept-eula --verbose $MODIFIED_FILES
42+
43+
- name: Fail if there are uncommitted changes and the `fix-format` label is not present
44+
if: !contains(github.event.pull_request.labels.*.name, 'fix-format')
45+
run: git diff --quiet || (echo "Formatting issues detected. Run 'codee format' locally or attach label 'fix-format' to this PR." && exit 1)
46+
47+
#if: contains(github.event.pull_request.labels.*.name, 'fix-format')
48+
# - name: Run `codee format` on modified files
49+
# if: env.MODIFIED_FILES != ''
50+
# run: |
51+
# export PATH="${PWD}/codee-${CODEE_VERSION}-linux-x86_64/bin:${PATH}"
52+
# git codee-format --diff ${{ github.base_ref }} HEAD
53+
# git diff
54+
55+
# - name: Commit changes
56+
# if: env.MODIFIED_FILES != ''
57+
# run: |
58+
# if ! git diff --quiet; then
59+
# # Push with the github-actions user. More information at:
60+
# # https://github.com/actions/checkout?tab=readme-ov-file#push-a-commit-using-the-built-in-token
61+
# 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"
62+
# git push --set-upstream origin ${{ github.head_ref }}
63+
# else
64+
# echo "No changes detected."
65+
# exit 0
66+
# fi

0 commit comments

Comments
 (0)