Skip to content

Commit

Permalink
ci: various refactoring (#49)
Browse files Browse the repository at this point in the history
* don't reinstall already-installed versions
* factor out actions for compiler tests
* remove branch filters from push trigger
* warn c/c++ compatibility not guaranteed
  • Loading branch information
wpbonelli authored Nov 11, 2023
1 parent a0955bb commit 627cbd0
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 321 deletions.
36 changes: 36 additions & 0 deletions .github/actions/test-cc/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test CC
description: Test C compiler compatibility
inputs:
compiler:
description: "Toolchain or compiler to install"
required: true
version:
description: "Version of toolchain or compiler"
required: true
runs:
using: "composite"
steps:

- name: Check compiler version
shell: bash
run: |
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]]); then
# only last line of output captured by command substitution, write to temp file instead
${{ env.CC }} //QV > "$RUNNER_TEMP/${{ env.CC }}.ver" 2>&1
ccv=$(cat "$RUNNER_TEMP/${{ env.CC }}.ver" | head -n 1)
ccv=${ccv#*Version }
ccv=${ccv%% Build*}
else
ccv=$(${{ env.CC }} --version | head -n 1)
ccv=$(echo "$ccv" | grep -woE '[0123456789.]+' | head -n 1)
fi
[[ "$ccv" == ${{ inputs.version }}* ]] && (echo "found ${{ env.CC }} version: $ccv") || (echo "unexpected ${{ env.CC }} version: $ccv"; exit 1)
- name: Test compile (bash)
shell: bash
run: |
${{ env.CC }} -o hw hw.c
output=$(./hw '2>&1')
[[ "$output" == *"hello world"* ]] && echo "$output" || (echo "Unexpected C program output: $output"; exit 1)
rm hw
36 changes: 36 additions & 0 deletions .github/actions/test-cxx/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test CXX
description: Test CXX compiler compatibility
inputs:
compiler:
description: "Toolchain or compiler to install"
required: true
version:
description: "Version of toolchain or compiler"
required: true
runs:
using: "composite"
steps:

- name: Check compiler version
shell: bash
run: |
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ matrix.toolchain.compiler }}" =~ "intel" ]]); then
# only last line of output captured by command substitution, write to temp file instead
${{ env.CXX }} //QV > "$RUNNER_TEMP/${{ env.CXX }}.ver" 2>&1
cxxv=$(cat "$RUNNER_TEMP/${{ env.CXX }}.ver" | head -n 1)
cxxv=${cxxv#*Version }
cxxv=${cxxv%% Build*}
else
cxxv=$(${{ env.CXX }} --version | head -n 1)
cxxv=$(echo "$cxxv" | grep -woE '[0123456789.]+' | head -n 1)
fi
[[ "$cxxv" == ${{ matrix.toolchain.version }}* ]] && (echo "found ${{ env.CXX }} version: $cxxv") || (echo "unexpected ${{ env.CXX }} version: $cxxv"; exit 1)
- name: Test compile (bash)
shell: bash
run: |
${{ env.CXX }} -o hw hw.cpp
output=$(./hw '2>&1')
[[ "$output" == *"hello world"* ]] && echo "$output" || (echo "Unexpected C++ program output: $output"; exit 1)
rm hw
89 changes: 89 additions & 0 deletions .github/actions/test-fc/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Test FC
description: Test Fortran compiler compatibility
inputs:
compiler:
description: "Toolchain or compiler to install"
required: true
version:
description: "Version of toolchain or compiler"
required: true
runs:
using: "composite"
steps:

- name: Check compiler version
shell: bash
run: |
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]]); then
# only last line of output captured by command substitution, write to temp file instead
${{ env.FC }} //QV > "$RUNNER_TEMP/${{ env.FC }}.ver" 2>&1
fcv=$(cat "$RUNNER_TEMP/${{ env.FC }}.ver" | head -n 1)
fcv=${fcv#*Version }
fcv=${fcv%% Build*}
else
fcv=$(${{ env.FC }} --version | head -n 1)
fcv=$(echo "$fcv" | grep -woE '[0123456789.]+' | head -n 1)
fi
[[ "$fcv" == ${{ inputs.version }}* ]] && (echo "found ${{ env.FC }} version: $fcv") || (echo "unexpected ${{ env.FC }} version: $fcv"; exit 1)
- name: Test compile (bash)
shell: bash
run: |
# macos-13/gfortran 7-9 compatibility workaround
args=""
if [ "$RUNNER_OS" == "macOS" ]; then
if [[ $(sw_vers -productVersion) == 13* ]] && \
[[ ${{ inputs.compiler }} == "gcc" ]] && \
[[ ${{ inputs.version }} =~ ^(7|8|9)$ ]]
then
args="-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
fi
fi
${{ env.FC }} $args -o hw hw.f90
output=$(./hw '2>&1')
[[ "$output" == *"hello world"* ]] && echo "$output" || (echo "Unexpected Fortran program output: $output"; exit 1)
rm hw
- name: Test compile Fortran (pwsh)
if: ${{ (success() || failure()) && runner.os == 'Windows' }}
shell: pwsh
run: |
${{ env.FC }} -o hw.exe hw.f90
$output=$(& ".\hw.exe")
if ($output -match "hello world") {
write-output $output
} else {
write-output "unexpected output: $output"
exit 1
}
rm hw.exe
- name: Test compile Fortran (powershell)
if: ${{ (success() || failure()) && runner.os == 'Windows' }}
shell: powershell
run: |
${{ env.FC }} -o hw.exe hw.f90
$output=$(& ".\hw.exe")
if ($output -match "hello world") {
write-output $output
} else {
write-output "unexpected output: $output"
exit 1
}
rm hw.exe
- name: Test compile Fortran (cmd)
if: ${{ (success() || failure()) && runner.os == 'Windows' }}
shell: cmd
run: |
${{ env.FC }} -o hw.exe hw.f90
for /f "tokens=* usebackq" %%f in (`.\hw.exe`) do @set "OUTPUT=%%f"
if "%OUTPUT%"=="hello world" (
echo %OUTPUT%
) else (
echo unexpected output: %OUTPUT%
exit 1
)
del hw.exe
Loading

0 comments on commit 627cbd0

Please sign in to comment.