Skip to content

Commit d74b868

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

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)