Skip to content

Commit f63c37e

Browse files
committed
version compatibility updates
* expand test matrix * add version compatibility table to README * replace set-output with GITHUB_OUTPUT file (pending deprecation) * add tests for pwsh, powershell and cmd on Windows * add cases for uname on Windows: msys* and cygwin* * use Chocolatey to install mingw on Windows * link to libgfortran-5.dll on Windows * link to older version lib paths on Mac * store runner compatibility in CSV file * autodetect runner compatiblity changes * autocreate PR to update README on compat changes
1 parent e6d2a1f commit f63c37e

File tree

6 files changed

+351
-55
lines changed

6 files changed

+351
-55
lines changed

.github/workflows/test.yml

Lines changed: 215 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,240 @@
11
name: Test
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop*
8+
pull_request:
9+
branches:
10+
- main
11+
- develop*
12+
schedule:
13+
- cron: '0 6 * * *'
414

515
jobs:
616
test:
17+
name: Test compiler
718
runs-on: ${{ matrix.os }}
819
strategy:
920
fail-fast: false
1021
matrix:
11-
os: [ubuntu-latest, macos-latest, windows-latest]
22+
os: [ubuntu-22.04, ubuntu-20.04, ubuntu-18.04, macos-12, macos-11, windows-2022, windows-2019]
1223
compiler: [gcc]
13-
version: [11, 10, 9, 8]
14-
24+
version: [12, 11, 10, 9, 8, 7, 6, 5]
1525
steps:
26+
1627
- name: Checkout repository
17-
uses: actions/checkout@v2
28+
uses: actions/checkout@v3
1829

1930
- name: Setup Fortran
31+
continue-on-error: true
2032
id: setup-fortran
2133
uses: ./
2234
with:
2335
compiler: ${{ matrix.compiler }}
2436
version: ${{ matrix.version }}
2537

26-
- name: Check Fortran compiler
38+
- name: Check compiler version
39+
if: steps.setup-fortran.outcome == 'success'
40+
shell: bash
41+
env:
42+
FC: ${{ steps.setup-fortran.outputs.fc }}
43+
CC: ${{ steps.setup-fortran.outputs.cc }}
2744
run: |
28-
${{ env.FC }} --version
29-
${{ env.CC }} --version
45+
fcv=$(${{ env.FC }} --version | head -n 1)
46+
ccv=$(${{ env.CC }} --version | head -n 1)
47+
48+
echo $fcv
49+
echo $ccv
50+
51+
fcv=$(echo "${fcv##*)}" | xargs)
52+
ccv=$(echo "${ccv##*)}" | xargs)
53+
54+
[[ $fcv == ${{ matrix.version }}* ]] || (echo "unexpected Fortran compiler version: $fcv"; exit 1)
55+
[[ $ccv == ${{ matrix.version }}* ]] || (echo "unexpected C compiler version: $ccv"; exit 1)
56+
57+
- name: Test compile program (bash)
58+
if: steps.setup-fortran.outcome == 'success'
3059
shell: bash
3160
env:
3261
FC: ${{ steps.setup-fortran.outputs.fc }}
3362
CC: ${{ steps.setup-fortran.outputs.cc }}
63+
run: |
64+
${{ env.FC }} -o hw hw.f90
65+
output=$(./hw '2>&1')
66+
[[ "$output" == *"hello world"* ]] && echo "$output" || (echo "Unexpected output: $output"; exit 1)
67+
68+
- name: Test compile program (Powershell Core)
69+
if: steps.setup-fortran.outcome == 'success' && runner.os == 'Windows'
70+
shell: pwsh
71+
env:
72+
FC: ${{ steps.setup-fortran.outputs.fc }}
73+
CC: ${{ steps.setup-fortran.outputs.cc }}
74+
run: |
75+
rm hw.exe
76+
${{ env.FC }} -o hw.exe hw.f90
77+
$output=$(& ".\hw.exe")
78+
if ($output -match "hello world") {
79+
write-output $output
80+
} else {
81+
write-output "unexpected output: $output"
82+
exit 1
83+
}
84+
85+
- name: Test compile program (Powershell Desktop)
86+
if: steps.setup-fortran.outcome == 'success' && runner.os == 'Windows'
87+
shell: powershell
88+
env:
89+
FC: ${{ steps.setup-fortran.outputs.fc }}
90+
CC: ${{ steps.setup-fortran.outputs.cc }}
91+
run: |
92+
rm hw.exe
93+
${{ env.FC }} -o hw.exe hw.f90
94+
$output=$(& ".\hw.exe")
95+
if ($output -match "hello world") {
96+
write-output $output
97+
} else {
98+
write-output "unexpected output: $output"
99+
exit 1
100+
}
101+
102+
- name: Test compile program (cmd)
103+
if: steps.setup-fortran.outcome == 'success' && runner.os == 'Windows'
104+
shell: cmd
105+
env:
106+
FC: ${{ steps.setup-fortran.outputs.fc }}
107+
CC: ${{ steps.setup-fortran.outputs.cc }}
108+
run: |
109+
del hw.exe
110+
${{ env.FC }} -o hw.exe hw.f90
111+
for /f "tokens=* usebackq" %%f in (`.\hw.exe`) do @set "OUTPUT=%%f"
112+
if "%OUTPUT%"=="hello world" (
113+
echo %OUTPUT%
114+
) else (
115+
echo unexpected output: %OUTPUT%
116+
exit 1
117+
)
118+
119+
- name: Create compatibility report
120+
shell: bash
121+
run: |
122+
if [[ "${{ steps.setup-fortran.outcome }}" == "success" ]]; then
123+
support="✓"
124+
else
125+
support=""
126+
fi
127+
128+
mkdir compat
129+
prefix="${{ matrix.os }},${{ matrix.compiler }},${{ matrix.version }}"
130+
echo "$prefix,$support" >> "compat/${prefix//,/_}.csv"
131+
132+
- name: Upload compatibility report
133+
uses: actions/upload-artifact@v3
134+
with:
135+
name: compat
136+
path: compat/*.csv
137+
138+
compat:
139+
name: Report compatibility
140+
needs: test
141+
runs-on: ubuntu-latest
142+
steps:
143+
144+
- name: Checkout repository
145+
uses: actions/checkout@v3
146+
147+
- name: Setup Python
148+
uses: actions/setup-python@v4
149+
with:
150+
python-version: 3.9
151+
152+
- name: Install packages
153+
run: |
154+
pip install tabulate pandas
155+
156+
- name: Download reports
157+
uses: actions/download-artifact@v3
158+
with:
159+
name: compat
160+
path: compat
161+
162+
- name: Concatenate reports
163+
run: |
164+
echo "runner,compiler,version,support" > compat_long.csv
165+
cat compat/*.csv >> compat_long.csv
166+
167+
- name: Make wide CSV and MD table
168+
id: merge-reports
169+
shell: python
170+
run: |
171+
import pandas as pd
172+
df = pd.read_csv("compat_long.csv")
173+
df = pd.pivot(df, index="runner", columns="version", values="support")
174+
df = df.sort_values(by=["runner"])
175+
df.to_csv("compat.csv")
176+
with open("compat.md", "w") as file:
177+
file.write(df.to_markdown().replace("nan", ""))
178+
179+
- name: Upload artifacts
180+
uses: actions/upload-artifact@v3
181+
with:
182+
name: compat
183+
path: |
184+
compat.csv
185+
compat.md
186+
187+
- name: Check for changes
188+
id: diff
189+
run: |
190+
if ! [ -f compat.csv ]; then
191+
echo "diff=false" >> $GITHUB_OUTPUT
192+
exit 0
193+
fi
194+
195+
diff=$(git diff compat.csv)
196+
if [[ $diff == "" ]]; then
197+
echo "No changes found"
198+
echo "diff=false" >> $GITHUB_OUTPUT
199+
else
200+
echo "Changes found:"
201+
echo "$diff"
202+
echo "diff=true" >> $GITHUB_OUTPUT
203+
fi
204+
205+
- name: Update README
206+
if: steps.diff.outputs.diff == 'true'
207+
shell: python
208+
run: |
209+
import re
210+
from pathlib import Path
211+
readme_path = Path("README.md")
212+
readme = readme_path.open().read()
213+
with open("compat.md", "r") as compat:
214+
table = ''.join(compat.readlines())
215+
r = re.compile(r'<!\-\- compat starts \-\->.*<!\-\- compat ends \-\->', re.DOTALL)
216+
chunk = '<!-- compat starts -->{}<!-- compat ends -->'.format('\n{}\n'.format(table))
217+
readme_path.open('w').write(r.sub(chunk, readme))
218+
219+
- name: Print README diff
220+
if: steps.diff.outputs.diff == 'true'
221+
run: |
222+
git diff README.md
223+
224+
- name: Create pull request
225+
if: steps.diff.outputs.diff == 'true'
226+
env:
227+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
228+
run: |
229+
git config user.name "github-actions[bot]"
230+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
231+
232+
now=$(date +'%Y-%m-%dT%H-%M-%S')
233+
updated_branch="compat_$now"
234+
default_branch="${{ github.event.repository.default_branch }}"
235+
236+
git switch -c "$updated_branch"
237+
git add compat.csv README.md
238+
git commit -m "Update compatibility matrix"
239+
git push -u origin "$updated_branch"
240+
gh pr create -B "$default_branch" -H "$updated_branch" --title "Update compatibility matrix" --body-file compat.md

README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Setup Fortran
22

3-
GitHub action to setup a Fortran compiler on the supported runners.
3+
[![Test](https://github.com/awvwgk/setup-fortran/actions/workflows/test.yml/badge.svg)](https://github.com/awvwgk/setup-fortran/actions/workflows/test.yml)
4+
5+
Action to setup a Fortran compiler.
46

57

68
## Usage
79

8-
This action allows to setup Fortran compilers on all Ubuntu, MacOS and Windows.
10+
This action allows setting up Fortran compilers on Ubuntu, MacOS and Windows runners.
911

1012
```yaml
1113
jobs:
@@ -31,11 +33,26 @@ jobs:
3133
3234
## Options
3335
34-
- *compiler*: Compiler toolchain to setup,
35-
available options are *gcc*.
36+
- *compiler*: Compiler toolchain to setup, available options are *gcc*
37+
- *version*: Version of the compiler toolchain, available options for *gcc* are *5-12*
38+
39+
40+
## Runner compatibility
41+
42+
<!-- compat starts -->
43+
44+
| | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
45+
|-------------------------------|---------|---------|---------|---------|---------|---------|---------|---------|
46+
| ubuntu-22.04 | | | | | &check; | &check; | &check; | &check; |
47+
| ubuntu-20.04 (ubuntu-latest) | | | &check; | &check; | &check; | &check; | &check; | |
48+
| ubuntu-18.04 | &check; | &check; | &check; | &check; | &check; | &check; | &check; | |
49+
| macos-12 | | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
50+
| macos-11 (macos-latest) | | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
51+
| macos-10.15 | | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
52+
| windows-2022 (windows-latest) | | | | &check; | &check; | &check; | &check; | &check; |
53+
| windows-2019 | | | | &check; | &check; | &check; | &check; | &check; |
3654
37-
- *version*: Version of the compiler toolchain,
38-
available options for *gcc* are 11, 10, 9, 8, 7 (Ubuntu and MacOS), 6 (MacOS), 5 (MacOS)
55+
<!-- compat ends -->
3956
4057
4158
## License

action.yml

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,56 @@ runs:
1919
using: "composite"
2020
steps:
2121
- id: setup
22-
run: |
23-
action_path=$(echo '/${{ github.action_path }}' | sed -e 's/\\/\//g' -e 's/://')
24-
"$action_path/setup-fortran.sh"
22+
name: Setup toolchain
2523
shell: bash
2624
env:
2725
COMPILER: ${{ inputs.compiler }}
2826
VERSION: ${{ inputs.version }}
27+
run: |
28+
action_path=$(echo '/${{ github.action_path }}' | sed -e 's/\\/\//g' -e 's/://')
29+
source "$action_path/setup-fortran.sh"
30+
31+
compiler=${COMPILER:-gcc}
32+
platform=$(uname -s | tr '[:upper:]' '[:lower:]')
33+
34+
case $compiler in
35+
gcc)
36+
version=${VERSION:-11}
37+
;;
38+
*)
39+
exit 1
40+
;;
41+
esac
42+
43+
case $platform in
44+
linux*)
45+
install_gcc_apt
46+
;;
47+
darwin*)
48+
install_gcc_brew
49+
;;
50+
mingw*)
51+
install_gcc_choco
52+
;;
53+
msys*)
54+
install_gcc_choco
55+
;;
56+
cygwin*)
57+
install_gcc_choco
58+
;;
59+
*)
60+
echo "Unsupported platform: $platform"
61+
exit 1
62+
;;
63+
esac
64+
65+
which "${FC}"
66+
which "${CC}"
67+
68+
# set outputs
69+
echo "fc=${FC}" >> $GITHUB_OUTPUT
70+
echo "cc=${CC}" >> $GITHUB_OUTPUT
71+
72+
# persist environment variables
73+
echo "FC=${FC}" >> $GITHUB_ENV
74+
echo "CC=${CC}" >> $GITHUB_ENV

compat.csv

Whitespace-only changes.

hw.f90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
program hello
2+
print *, "hello world"
3+
end program hello

0 commit comments

Comments
 (0)