Skip to content

Commit 2e4471f

Browse files
committed
ci: various refactoring
* factor out actions for compiler tests * remove branch filters from push trigger * mention no guaranteed c/c++ compatibility * don't reinstall already-installed versions
1 parent a0955bb commit 2e4471f

File tree

7 files changed

+295
-321
lines changed

7 files changed

+295
-321
lines changed

.github/actions/test-cc/action.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test CC
2+
description: Test C compiler compatibility
3+
inputs:
4+
compiler:
5+
description: "Toolchain or compiler to install"
6+
required: true
7+
version:
8+
description: "Version of toolchain or compiler"
9+
required: true
10+
runs:
11+
using: "composite"
12+
steps:
13+
14+
- name: Check compiler version
15+
shell: bash
16+
run: |
17+
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]]); then
18+
# only last line of output captured by command substitution, write to temp file instead
19+
${{ env.CC }} //QV > "$RUNNER_TEMP/${{ env.CC }}.ver" 2>&1
20+
ccv=$(cat "$RUNNER_TEMP/${{ env.CC }}.ver" | head -n 1)
21+
ccv=${ccv#*Version }
22+
ccv=${ccv%% Build*}
23+
else
24+
ccv=$(${{ env.CC }} --version | head -n 1)
25+
ccv=$(echo "$ccv" | grep -woE '[0123456789.]+' | head -n 1)
26+
fi
27+
[[ "$ccv" == ${{ inputs.version }}* ]] && (echo "found ${{ env.CC }} version: $ccv") || (echo "unexpected ${{ env.CC }} version: $ccv"; exit 1)
28+
29+
- name: Test compile (bash)
30+
shell: bash
31+
run: |
32+
${{ env.CC }} -o hw hw.c
33+
output=$(./hw '2>&1')
34+
[[ "$output" == *"hello world"* ]] && echo "$output" || (echo "Unexpected C program output: $output"; exit 1)
35+
rm hw
36+

.github/actions/test-cxx/action.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test CXX
2+
description: Test CXX compiler compatibility
3+
inputs:
4+
compiler:
5+
description: "Toolchain or compiler to install"
6+
required: true
7+
version:
8+
description: "Version of toolchain or compiler"
9+
required: true
10+
runs:
11+
using: "composite"
12+
steps:
13+
14+
- name: Check compiler version
15+
shell: bash
16+
run: |
17+
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ matrix.toolchain.compiler }}" =~ "intel" ]]); then
18+
# only last line of output captured by command substitution, write to temp file instead
19+
${{ env.CXX }} //QV > "$RUNNER_TEMP/${{ env.CXX }}.ver" 2>&1
20+
cxxv=$(cat "$RUNNER_TEMP/${{ env.CXX }}.ver" | head -n 1)
21+
cxxv=${cxxv#*Version }
22+
cxxv=${cxxv%% Build*}
23+
else
24+
cxxv=$(${{ env.CXX }} --version | head -n 1)
25+
cxxv=$(echo "$cxxv" | grep -woE '[0123456789.]+' | head -n 1)
26+
fi
27+
[[ "$cxxv" == ${{ matrix.toolchain.version }}* ]] && (echo "found ${{ env.CXX }} version: $cxxv") || (echo "unexpected ${{ env.CXX }} version: $cxxv"; exit 1)
28+
29+
- name: Test compile (bash)
30+
shell: bash
31+
run: |
32+
${{ env.CXX }} -o hw hw.cpp
33+
output=$(./hw '2>&1')
34+
[[ "$output" == *"hello world"* ]] && echo "$output" || (echo "Unexpected C++ program output: $output"; exit 1)
35+
rm hw
36+

.github/actions/test-fc/action.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Test FC
2+
description: Test Fortran compiler compatibility
3+
inputs:
4+
compiler:
5+
description: "Toolchain or compiler to install"
6+
required: true
7+
version:
8+
description: "Version of toolchain or compiler"
9+
required: true
10+
runs:
11+
using: "composite"
12+
steps:
13+
14+
- name: Check compiler version
15+
shell: bash
16+
run: |
17+
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]]); then
18+
# only last line of output captured by command substitution, write to temp file instead
19+
${{ env.FC }} //QV > "$RUNNER_TEMP/${{ env.FC }}.ver" 2>&1
20+
fcv=$(cat "$RUNNER_TEMP/${{ env.FC }}.ver" | head -n 1)
21+
fcv=${fcv#*Version }
22+
fcv=${fcv%% Build*}
23+
else
24+
fcv=$(${{ env.FC }} --version | head -n 1)
25+
fcv=$(echo "$fcv" | grep -woE '[0123456789.]+' | head -n 1)
26+
fi
27+
[[ "$fcv" == ${{ inputs.version }}* ]] && (echo "found ${{ env.FC }} version: $fcv") || (echo "unexpected ${{ env.FC }} version: $fcv"; exit 1)
28+
29+
- name: Test compile (bash)
30+
shell: bash
31+
run: |
32+
# macos-13/gfortran 7-9 compatibility workaround
33+
args=""
34+
if [ "$RUNNER_OS" == "macOS" ]; then
35+
if [[ $(sw_vers -productVersion) == 13* ]] && \
36+
[[ ${{ inputs.compiler }} == "gcc" ]] && \
37+
[[ ${{ inputs.version }} =~ ^(7|8|9)$ ]]
38+
then
39+
args="-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
40+
fi
41+
fi
42+
43+
${{ env.FC }} $args -o hw hw.f90
44+
output=$(./hw '2>&1')
45+
[[ "$output" == *"hello world"* ]] && echo "$output" || (echo "Unexpected Fortran program output: $output"; exit 1)
46+
rm hw
47+
48+
- name: Test compile Fortran (pwsh)
49+
if: ${{ (success() || failure()) && runner.os == 'Windows' }}
50+
shell: pwsh
51+
run: |
52+
${{ env.FC }} -o hw.exe hw.f90
53+
$output=$(& ".\hw.exe")
54+
if ($output -match "hello world") {
55+
write-output $output
56+
} else {
57+
write-output "unexpected output: $output"
58+
exit 1
59+
}
60+
rm hw.exe
61+
62+
- name: Test compile Fortran (powershell)
63+
if: ${{ (success() || failure()) && runner.os == 'Windows' }}
64+
shell: powershell
65+
run: |
66+
${{ env.FC }} -o hw.exe hw.f90
67+
$output=$(& ".\hw.exe")
68+
if ($output -match "hello world") {
69+
write-output $output
70+
} else {
71+
write-output "unexpected output: $output"
72+
exit 1
73+
}
74+
rm hw.exe
75+
76+
- name: Test compile Fortran (cmd)
77+
if: ${{ (success() || failure()) && runner.os == 'Windows' }}
78+
shell: cmd
79+
run: |
80+
${{ env.FC }} -o hw.exe hw.f90
81+
for /f "tokens=* usebackq" %%f in (`.\hw.exe`) do @set "OUTPUT=%%f"
82+
if "%OUTPUT%"=="hello world" (
83+
echo %OUTPUT%
84+
) else (
85+
echo unexpected output: %OUTPUT%
86+
exit 1
87+
)
88+
del hw.exe
89+

0 commit comments

Comments
 (0)