Skip to content

Commit 136a69b

Browse files
committed
miscellaneous updates
* expand CI test matrix and add version compatibility matrix to README * replace soon-deprecated set-output mechanism with GITHUB_OUTPUT * add MSYS platform case * link to previous gcc lib paths on Mac * use Chocolatey on Windows * inline setup step and source platform-specific functions from setup.sh * add badge to README * add tests for pwsh and cmd on Windows
1 parent e6d2a1f commit 136a69b

File tree

5 files changed

+203
-50
lines changed

5 files changed

+203
-50
lines changed

.github/workflows/test.yml

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
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 * * *' # run at 6 AM UTC every day
414

515
jobs:
616
test:
717
runs-on: ${{ matrix.os }}
18+
continue-on-error: true
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
2031
id: setup-fortran
@@ -23,11 +34,56 @@ jobs:
2334
compiler: ${{ matrix.compiler }}
2435
version: ${{ matrix.version }}
2536

26-
- name: Check Fortran compiler
27-
run: |
28-
${{ env.FC }} --version
29-
${{ env.CC }} --version
37+
- name: Check compiler version
3038
shell: bash
3139
env:
3240
FC: ${{ steps.setup-fortran.outputs.fc }}
3341
CC: ${{ steps.setup-fortran.outputs.cc }}
42+
run: |
43+
fcv=$(${{ env.FC }} --version | head -n 1)
44+
ccv=$(${{ env.CC }} --version | head -n 1)
45+
46+
echo $fcv
47+
echo $ccv
48+
49+
fcv=${fcv##* }
50+
ccv=${ccv##* }
51+
52+
[[ $fcv == ${{ matrix.version }}* ]] || (echo "unexpected Fortran compiler version: $fcv"; exit 1)
53+
[[ $ccv == ${{ matrix.version }}* ]] || (echo "unexpected C compiler version: $ccv"; exit 1)
54+
55+
- name: Test compile program (bash)
56+
continue-on-error: true
57+
shell: bash
58+
run: |
59+
gfortran -o hw test/hw.f90
60+
output=$(./hw '2>&1')
61+
[[ "$output" == *"hello world"* ]] && echo "$output" || (echo "Unexpected output: $output"; exit 1)
62+
63+
- name: Test compile program (pwsh)
64+
if: runner.os == 'Windows'
65+
shell: pwsh
66+
run: |
67+
rm hw.exe
68+
gfortran -o hw.exe test\hw.f90
69+
$output=$(& ".\hw.exe")
70+
if ($output -match "hello world") {
71+
write-output $output
72+
} else {
73+
write-output "unexpected output: $output"
74+
exit 1
75+
}
76+
77+
- name: Test compile program (cmd)
78+
if: runner.os == 'Windows'
79+
shell: cmd
80+
run: |
81+
del hw.exe
82+
gfortran -o hw.exe test\hw.f90
83+
for /f "tokens=* usebackq" %%f in (`.\hw.exe`) do @set "OUTPUT=%%f"
84+
if "%OUTPUT%"=="hello world" (
85+
exit 0
86+
) else (
87+
echo "unexpected output: %OUTPUT%"
88+
exit 1
89+
)

README.md

Lines changed: 16 additions & 3 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:
@@ -35,7 +37,18 @@ jobs:
3537
available options are *gcc*.
3638
3739
- *version*: Version of the compiler toolchain,
38-
available options for *gcc* are 11, 10, 9, 8, 7 (Ubuntu and MacOS), 6 (MacOS), 5 (MacOS)
40+
available options for *gcc* are:
41+
42+
| | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
43+
|-------------------------------|---------|---------|---------|---------|---------|---------|---------|---------|
44+
| ubuntu-22.04 | | | | | ✓ | ✓ | ✓ | ✓ |
45+
| ubuntu-20.04 (ubuntu-latest) | | | ✓ | ✓ | ✓ | ✓ | ✓ | |
46+
| ubuntu-18.04 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
47+
| macos-12 | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
48+
| macos-11 (macos-latest) | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
49+
| macos-10.15 | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
50+
| windows-2022 (windows-latest) | | | | ✓ | ✓ | ✓ | ✓ | ✓ |
51+
| windows-2019 | | | | ✓ | ✓ | ✓ | ✓ | ✓ |
3952
4053
4154
## License

action.yml

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,60 @@ 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)
33+
34+
echo "detected C compiler $compiler"
35+
echo "detected platform $platform"
36+
37+
case $compiler in
38+
gcc)
39+
version=${VERSION:-9}
40+
;;
41+
*)
42+
exit 1
43+
;;
44+
esac
45+
46+
case $platform in
47+
Linux*)
48+
install_gcc_apt
49+
;;
50+
Darwin*)
51+
install_gcc_brew
52+
;;
53+
MINGW*)
54+
install_gcc_choco
55+
;;
56+
MSYS*)
57+
install_gcc_choco
58+
;;
59+
*)
60+
exit 1
61+
;;
62+
esac
63+
64+
which "${FC}"
65+
which "${CC}"
66+
67+
echo "fc=${FC}" >> $GITHUB_OUTPUT
68+
echo "cc=${CC}" >> $GITHUB_OUTPUT
69+
70+
- name: Link mingw DLL (Windows)
71+
if: runner.os == 'Windows'
72+
shell: bash
73+
run: |
74+
FCDIR=/c/ProgramData/Chocolatey/bin
75+
LNDIR=/c/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin
76+
if [ -d "$FCDIR" ] && [ -f "$LNDIR/libgfortran-5.dll" ] && [ ! -f "$FCDIR/libgfortran-5.dll" ]; then
77+
ln -s "$LNDIR/libgfortran-5.dll" "$FCDIR/libgfortran-5.dll"
78+
fi

setup-fortran.sh

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,22 @@ set -ex
55
install_gcc_brew()
66
{
77
brew install gcc@${version}
8-
ln -s /usr/local/bin/gfortran-${version} /usr/local/bin/gfortran
9-
ln -s /usr/local/bin/gcc-${version} /usr/local/bin/gcc
10-
ln -s /usr/local/bin/g++-${version} /usr/local/bin/g++
8+
ln -fs /usr/local/bin/gfortran-${version} /usr/local/bin/gfortran
9+
ln -fs /usr/local/bin/gcc-${version} /usr/local/bin/gcc
10+
ln -fs /usr/local/bin/g++-${version} /usr/local/bin/g++
11+
12+
for (( i=12; i>4; i-- ))
13+
do
14+
gcc_lib_path="/usr/local/opt/gcc/lib/gcc/$i"
15+
if [ -d $gcc_lib_path ]; then
16+
echo "found $gcc_lib_path"
17+
for (( j=$i; j>4; j-- ))
18+
do
19+
ln -fs /usr/local/opt/gcc/lib/gcc/$i /usr/local/opt/gcc/lib/gcc/$j
20+
done
21+
break
22+
fi
23+
done
1124

1225
export FC="gfortran"
1326
export CC="gcc"
@@ -29,10 +42,43 @@ install_gcc_apt()
2942
export CXX="g++"
3043
}
3144

45+
install_gcc_choco()
46+
{
47+
case $version in
48+
12)
49+
choco install mingw --version 12.2.0 --force
50+
;;
51+
11)
52+
choco install mingw --version 11.2.0 --force
53+
;;
54+
10)
55+
choco install mingw --version 10.3.0 --force
56+
;;
57+
9)
58+
choco install mingw --version 9.4.0 --force
59+
;;
60+
8)
61+
choco install mingw --version 8.5.0 --force
62+
;;
63+
*)
64+
echo "Unsupported version: $version (choose 8-12)"
65+
exit 1
66+
;;
67+
esac
68+
69+
export FC="gfortran"
70+
export CC="gcc"
71+
export CXX="g++"
72+
}
73+
3274
install_gcc_winlibs()
3375
{
3476
repo="https://github.com/brechtsanders/winlibs_mingw/releases/download"
3577
case $version in
78+
12)
79+
tag="12.2.0-14.0.6-10.0.0-ucrt-r2"
80+
zip="winlibs-x86_64-posix-seh-gcc-12.2.0-mingw-w64ucrt-10.0.0-r2.zip"
81+
;;
3682
11)
3783
tag="11.2.0-12.0.1-9.0.0-r1"
3884
zip="winlibs-x86_64-posix-seh-gcc-11.2.0-mingw-w64-9.0.0-r1.zip"
@@ -50,6 +96,7 @@ install_gcc_winlibs()
5096
zip="winlibs-x86_64-posix-seh-gcc-8.5.0-mingw-w64-9.0.0-r1.zip"
5197
;;
5298
*)
99+
echo "Unsupported version: $version (choose 8-12)"
53100
exit 1
54101
;;
55102
esac
@@ -63,43 +110,27 @@ install_gcc_winlibs()
63110
exit 1
64111
fi
65112

66-
$fetch "$repo/$tag/$zip" > gcc.zip
67-
unzip -qo gcc.zip -d /
113+
$fetch "$repo/$tag/$zip" > winlibs_mingw.zip
114+
115+
unzip -qo winlibs_mingw.zip "mingw64/bin/*" -d /
68116

69117
export FC="gfortran"
70118
export CC="gcc"
71119
export CXX="g++"
72-
}
73120

74-
compiler=${COMPILER:-gcc}
75-
platform=$(uname -s)
121+
default_gfc="/c/ProgramData/Chocolatey/bin/gfortran"
122+
default_gcc="/c/ProgramData/Chocolatey/bin/gcc"
123+
default_gcx="/c/ProgramData/Chocolatey/bin/g++"
76124

77-
case $compiler in
78-
gcc)
79-
version=${VERSION:-9}
80-
;;
81-
*)
82-
exit 1
83-
;;
84-
esac
85-
86-
case $platform in
87-
Linux*)
88-
install_gcc_apt
89-
;;
90-
Darwin*)
91-
install_gcc_brew
92-
;;
93-
MINGW*)
94-
install_gcc_winlibs
95-
;;
96-
*)
97-
exit 1
98-
;;
99-
esac
125+
[ -f $default_gfc ] && mv $default_gfc "$RUNNER_TEMP/gfortran"
126+
[ -f $default_gcc ] && mv $default_gcc "$RUNNER_TEMP/gcc"
127+
[ -f $default_gcx ] && mv $default_gcx "$RUNNER_TEMP/g++"
100128

101-
which "${FC}"
102-
which "${CC}"
129+
default_gfc="/c/Strawberry/c/bin/gfortran"
130+
default_gcc="/c/Strawberry/c/bin/gcc"
131+
default_gcx="/c/Strawberry/c/bin/g++"
103132

104-
echo "::set-output name=fc::${FC}"
105-
echo "::set-output name=cc::${CC}"
133+
[ -f $default_gfc ] && mv $default_gfc "$RUNNER_TEMP/gfortran"
134+
[ -f $default_gcc ] && mv $default_gcc "$RUNNER_TEMP/gcc"
135+
[ -f $default_gcx ] && mv $default_gcx "$RUNNER_TEMP/g++"
136+
}

test/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)