Skip to content

Commit 8cc9bcf

Browse files
authored
Test/document version support, miscellanous (#3)
* 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 8cc9bcf

File tree

6 files changed

+386
-55
lines changed

6 files changed

+386
-55
lines changed

.github/workflows/test.yml

Lines changed: 218 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,243 @@
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+
permissions:
143+
contents: write
144+
pull-requests: write
145+
steps:
146+
147+
- name: Checkout repository
148+
uses: actions/checkout@v3
149+
150+
- name: Setup Python
151+
uses: actions/setup-python@v4
152+
with:
153+
python-version: 3.9
154+
155+
- name: Install packages
156+
run: |
157+
pip install tabulate pandas
158+
159+
- name: Download reports
160+
uses: actions/download-artifact@v3
161+
with:
162+
name: compat
163+
path: compat
164+
165+
- name: Concatenate reports
166+
run: |
167+
echo "runner,compiler,version,support" > compat_long.csv
168+
cat compat/*.csv >> compat_long.csv
169+
170+
- name: Make wide CSV and MD table
171+
id: merge-reports
172+
shell: python
173+
run: |
174+
import pandas as pd
175+
df = pd.read_csv("compat_long.csv")
176+
df = pd.pivot(df, index="runner", columns="version", values="support")
177+
df = df.sort_values(by=["runner"])
178+
df.to_csv("compat.csv")
179+
with open("compat.md", "w") as file:
180+
file.write(df.to_markdown().replace("nan", ""))
181+
182+
- name: Upload artifacts
183+
uses: actions/upload-artifact@v3
184+
with:
185+
name: compat
186+
path: |
187+
compat.csv
188+
compat.md
189+
190+
- name: Check for changes
191+
id: diff
192+
run: |
193+
if ! [ -f compat.csv ]; then
194+
echo "diff=false" >> $GITHUB_OUTPUT
195+
exit 0
196+
fi
197+
198+
diff=$(git diff compat.csv)
199+
if [[ $diff == "" ]]; then
200+
echo "No changes found"
201+
echo "diff=false" >> $GITHUB_OUTPUT
202+
else
203+
echo "Changes found:"
204+
echo "$diff"
205+
echo "diff=true" >> $GITHUB_OUTPUT
206+
fi
207+
208+
- name: Update README
209+
if: steps.diff.outputs.diff == 'true' && github.event_name == 'push'
210+
shell: python
211+
run: |
212+
import re
213+
from pathlib import Path
214+
readme_path = Path("README.md")
215+
readme = readme_path.open().read()
216+
with open("compat.md", "r") as compat:
217+
table = ''.join(compat.readlines())
218+
r = re.compile(r'<!\-\- compat starts \-\->.*<!\-\- compat ends \-\->', re.DOTALL)
219+
chunk = '<!-- compat starts -->{}<!-- compat ends -->'.format('\n{}\n'.format(table))
220+
readme_path.open('w').write(r.sub(chunk, readme))
221+
222+
- name: Print README diff
223+
if: steps.diff.outputs.diff == 'true' && github.event_name == 'push'
224+
run: |
225+
git diff README.md
226+
227+
- name: Create pull request
228+
if: steps.diff.outputs.diff == 'true' && github.event_name == 'push'
229+
env:
230+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
231+
run: |
232+
git config user.name "github-actions[bot]"
233+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
234+
235+
now=$(date +'%Y-%m-%dT%H-%M-%S')
236+
updated_branch="compat_$now"
237+
default_branch="${{ github.event.repository.default_branch }}"
238+
239+
git switch -c "$updated_branch"
240+
git add compat.csv README.md
241+
git commit -m "Update compatibility matrix"
242+
git push -u origin "$updated_branch"
243+
gh pr create -B "$default_branch" -H "$updated_branch" --title "Update compatibility matrix" --body-file compat.md

README.md

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
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.
6+
7+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
8+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
9+
10+
- [Usage](#usage)
11+
- [Options](#options)
12+
- [Outputs](#outputs)
13+
- [Environment variables](#environment-variables)
14+
- [Runner compatibility](#runner-compatibility)
15+
- [License](#license)
16+
17+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
418

519

620
## Usage
721

8-
This action allows to setup Fortran compilers on all Ubuntu, MacOS and Windows.
22+
This action sets up a Fortran compiler on Ubuntu, MacOS and Windows runners.
923

1024
```yaml
1125
jobs:
@@ -31,11 +45,46 @@ jobs:
3145
3246
## Options
3347
34-
- *compiler*: Compiler toolchain to setup,
35-
available options are *gcc*.
48+
- *compiler*: Compiler toolchain to setup, available options are *gcc*
49+
- *version*: Version of the compiler toolchain, available options for *gcc* are *5-12*
50+
51+
52+
## Outputs
53+
54+
The action sets the following outputs:
55+
56+
- `cc`: C compiler executable, e.g. `gcc`
57+
- `fc`: Fortran compiler executable, e.g. `gfortran`
58+
59+
60+
## Environment variables
61+
62+
The same values are also set as environment variables:
63+
64+
- `CC`
65+
- `FC`
66+
67+
These are made available to subsequent workflow steps via the [`GITHUB_ENV` environment file mechanism](https://docs.github.com/en/actions/learn-github-actions/environment-variables#passing-values-between-steps-and-jobs-in-a-workflow).
68+
69+
70+
## Runner compatibility
71+
72+
Support for the GCC toolchain varies across GitHub-hosted runner images.
73+
74+
<!-- compat starts -->
75+
76+
| | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
77+
|-------------------------------|---------|---------|---------|---------|---------|---------|---------|---------|
78+
| ubuntu-22.04 | | | | | &check; | &check; | &check; | &check; |
79+
| ubuntu-20.04 (ubuntu-latest) | | | &check; | &check; | &check; | &check; | &check; | |
80+
| ubuntu-18.04 | &check; | &check; | &check; | &check; | &check; | &check; | &check; | |
81+
| macos-12 | | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
82+
| macos-11 (macos-latest) | | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
83+
| macos-10.15 | | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
84+
| windows-2022 (windows-latest) | | | | &check; | &check; | &check; | &check; | &check; |
85+
| windows-2019 | | | | &check; | &check; | &check; | &check; | &check; |
3686

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)
87+
<!-- compat ends -->
3988

4089

4190
## 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)