Skip to content

Commit bceb362

Browse files
committed
various fixes/updates
* add test for Powershell Desktop ('powershell') on Windows * fix test steps to use setup step's outputs (FC & CC) * store runner/toolchain version compatibility in CSV * add CI to create PR updating compat.csv and README if compatibility change detected (skipped if compat.csv doesn't exist) * fix continue-on-error CI configuration
1 parent 136a69b commit bceb362

File tree

6 files changed

+192
-53
lines changed

6 files changed

+192
-53
lines changed

.github/workflows/test.yml

Lines changed: 166 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ on:
44
push:
55
branches:
66
- main
7-
- develop
7+
- develop*
88
pull_request:
99
branches:
1010
- main
11-
- develop
11+
- develop*
1212
schedule:
13-
- cron: '0 6 * * *' # run at 6 AM UTC every day
13+
- cron: '0 6 * * *'
1414

1515
jobs:
1616
test:
17+
name: Test compiler
1718
runs-on: ${{ matrix.os }}
18-
continue-on-error: true
1919
strategy:
2020
fail-fast: false
2121
matrix:
@@ -28,13 +28,15 @@ jobs:
2828
uses: actions/checkout@v3
2929

3030
- name: Setup Fortran
31+
continue-on-error: true
3132
id: setup-fortran
3233
uses: ./
3334
with:
3435
compiler: ${{ matrix.compiler }}
3536
version: ${{ matrix.version }}
3637

3738
- name: Check compiler version
39+
if: steps.setup-fortran.outcome == 'success'
3840
shell: bash
3941
env:
4042
FC: ${{ steps.setup-fortran.outputs.fc }}
@@ -46,26 +48,49 @@ jobs:
4648
echo $fcv
4749
echo $ccv
4850
49-
fcv=${fcv##* }
50-
ccv=${ccv##* }
51+
fcv=$(echo "${fcv##*)}" | xargs)
52+
ccv=$(echo "${ccv##*)}" | xargs)
5153
5254
[[ $fcv == ${{ matrix.version }}* ]] || (echo "unexpected Fortran compiler version: $fcv"; exit 1)
5355
[[ $ccv == ${{ matrix.version }}* ]] || (echo "unexpected C compiler version: $ccv"; exit 1)
5456
5557
- name: Test compile program (bash)
56-
continue-on-error: true
58+
if: steps.setup-fortran.outcome == 'success'
5759
shell: bash
60+
env:
61+
FC: ${{ steps.setup-fortran.outputs.fc }}
62+
CC: ${{ steps.setup-fortran.outputs.cc }}
5863
run: |
59-
gfortran -o hw test/hw.f90
64+
${{ env.FC }} -o hw hw.f90
6065
output=$(./hw '2>&1')
6166
[[ "$output" == *"hello world"* ]] && echo "$output" || (echo "Unexpected output: $output"; exit 1)
6267
63-
- name: Test compile program (pwsh)
64-
if: runner.os == 'Windows'
68+
- name: Test compile program (Powershell Core)
69+
if: steps.setup-fortran.outcome == 'success' && runner.os == 'Windows'
6570
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 }}
6691
run: |
6792
rm hw.exe
68-
gfortran -o hw.exe test\hw.f90
93+
${{ env.FC }} -o hw.exe hw.f90
6994
$output=$(& ".\hw.exe")
7095
if ($output -match "hello world") {
7196
write-output $output
@@ -75,15 +100,141 @@ jobs:
75100
}
76101
77102
- name: Test compile program (cmd)
78-
if: runner.os == 'Windows'
103+
if: steps.setup-fortran.outcome == 'success' && runner.os == 'Windows'
79104
shell: cmd
105+
env:
106+
FC: ${{ steps.setup-fortran.outputs.fc }}
107+
CC: ${{ steps.setup-fortran.outputs.cc }}
80108
run: |
81109
del hw.exe
82-
gfortran -o hw.exe test\hw.f90
110+
${{ env.FC }} -o hw.exe hw.f90
83111
for /f "tokens=* usebackq" %%f in (`.\hw.exe`) do @set "OUTPUT=%%f"
84112
if "%OUTPUT%"=="hello world" (
85-
exit 0
113+
echo %OUTPUT%
86114
) else (
87-
echo "unexpected output: %OUTPUT%"
115+
echo unexpected output: %OUTPUT%
88116
exit 1
89117
)
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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ jobs:
3333
3434
## Options
3535
36-
- *compiler*: Compiler toolchain to setup,
37-
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*
3838
39-
- *version*: Version of the compiler toolchain,
40-
available options for *gcc* are:
39+
40+
## Runner compatibility
41+
42+
<!-- compat starts -->
4143
4244
| | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
4345
|-------------------------------|---------|---------|---------|---------|---------|---------|---------|---------|
@@ -50,6 +52,8 @@ jobs:
5052
| windows-2022 (windows-latest) | | | | &check; | &check; | &check; | &check; | &check; |
5153
| windows-2019 | | | | &check; | &check; | &check; | &check; | &check; |
5254
55+
<!-- compat ends -->
56+
5357
5458
## License
5559

action.yml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ runs:
3131
compiler=${COMPILER:-gcc}
3232
platform=$(uname -s)
3333
34-
echo "detected C compiler $compiler"
35-
echo "detected platform $platform"
36-
3734
case $compiler in
3835
gcc)
39-
version=${VERSION:-9}
36+
version=${VERSION:-11}
4037
;;
4138
*)
4239
exit 1
@@ -63,16 +60,11 @@ runs:
6360
6461
which "${FC}"
6562
which "${CC}"
66-
63+
64+
# set outputs
6765
echo "fc=${FC}" >> $GITHUB_OUTPUT
6866
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
67+
68+
# persist environment variables
69+
echo "FC=${FC}" >> $GITHUB_ENV
70+
echo "CC=${CC}" >> $GITHUB_ENV

compat.csv

Whitespace-only changes.
File renamed without changes.

setup-fortran.sh

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ install_gcc_brew()
99
ln -fs /usr/local/bin/gcc-${version} /usr/local/bin/gcc
1010
ln -fs /usr/local/bin/g++-${version} /usr/local/bin/g++
1111

12+
# link lib dir for previous GCC versions to avoid missing .dylib issues
1213
for (( i=12; i>4; i-- ))
1314
do
1415
gcc_lib_path="/usr/local/opt/gcc/lib/gcc/$i"
@@ -69,6 +70,13 @@ install_gcc_choco()
6970
export FC="gfortran"
7071
export CC="gcc"
7172
export CXX="g++"
73+
74+
# missing DLL can cause successfully compiled executables to fail at runtime
75+
FCDIR=/c/ProgramData/Chocolatey/bin
76+
LNDIR=/c/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin
77+
if [ -d "$FCDIR" ] && [ -f "$LNDIR/libgfortran-5.dll" ] && [ ! -f "$FCDIR/libgfortran-5.dll" ]; then
78+
ln -s "$LNDIR/libgfortran-5.dll" "$FCDIR/libgfortran-5.dll"
79+
fi
7280
}
7381

7482
install_gcc_winlibs()
@@ -104,33 +112,17 @@ install_gcc_winlibs()
104112
if command -v curl > /dev/null 2>&1; then
105113
fetch="curl -L"
106114
elif command -v wget > /dev/null 2>&1; then
107-
FETCH="wget -O -"
115+
fetch="wget -O -"
108116
else
109117
echo "No download mechanism found. Install curl or wget first."
110118
exit 1
111119
fi
112120

113-
$fetch "$repo/$tag/$zip" > winlibs_mingw.zip
121+
$fetch "$repo/$tag/$zip" > gcc.zip
114122

115-
unzip -qo winlibs_mingw.zip "mingw64/bin/*" -d /
123+
unzip -qo gcc.zip "mingw64/bin/*" -d /
116124

117125
export FC="gfortran"
118126
export CC="gcc"
119127
export CXX="g++"
120-
121-
default_gfc="/c/ProgramData/Chocolatey/bin/gfortran"
122-
default_gcc="/c/ProgramData/Chocolatey/bin/gcc"
123-
default_gcx="/c/ProgramData/Chocolatey/bin/g++"
124-
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++"
128-
129-
default_gfc="/c/Strawberry/c/bin/gfortran"
130-
default_gcc="/c/Strawberry/c/bin/gcc"
131-
default_gcx="/c/Strawberry/c/bin/g++"
132-
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++"
136128
}

0 commit comments

Comments
 (0)