Skip to content

test(latest): improve tests for latest version alias #748

test(latest): improve tests for latest version alias

test(latest): improve tests for latest version alias #748

Workflow file for this run

name: Test
# Workflow has two modes: assert and report
# Push and pull request run in assert mode.
# Schedule and dispatch run in report mode.
on:
push:
paths-ignore:
- '**.md'
tags-ignore:
- v**
pull_request:
branches:
- main
- develop*
paths-ignore:
- '**.md'
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
jobs:
options:
name: Set options
runs-on: ubuntu-latest
outputs:
mode: ${{ steps.mode.outputs.mode }}
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set mode
id: mode
run: |
trigger=${{ github.event_name }}
if [[ "$trigger" == "schedule" ]] || [[ "$trigger" == "workflow_dispatch" ]]; then
echo "mode=report" >> "$GITHUB_OUTPUT"
else
echo "mode=assert" >> "$GITHUB_OUTPUT"
fi
- name: Set matrix
working-directory: .github/compat
id: matrix
run: |
mode=${{ steps.mode.outputs.mode }}
if [[ "$mode" == "report" ]]; then
yq -o json matrix.yml > matrix.json
else
python matrix_json_from_csv.py "long_compat.csv" "matrix.json"
fi
matrix=$(cat matrix.json | jq -r tostring)
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
# debugging
- name: Show matrix
run: echo "${{ toJSON(fromJSON(steps.matrix.outputs.matrix)) }}"
test:
name: Test
needs: options
runs-on: ${{ matrix.os }}
continue-on-error: ${{ needs.options.outputs.mode == 'report' }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.options.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Fortran
id: setup-fortran
continue-on-error: ${{ needs.options.outputs.mode == 'report' }}
uses: ./
with:
compiler: ${{ matrix.toolchain.compiler }}
version: ${{ matrix.toolchain.version }}
# - name: Debug with tmate
# uses: mxschmitt/action-tmate@v3
- name: Test Fortran compiler
if: steps.setup-fortran.outcome == 'success'
uses: ./.github/actions/test-fc
with:
compiler: ${{ matrix.toolchain.compiler }}
version: ${{ matrix.toolchain.version }}
- name: Test C compiler
continue-on-error: true
if: needs.options.outputs.mode == 'report' && steps.setup-fortran.outcome == 'success'
uses: ./.github/actions/test-cc
with:
compiler: ${{ matrix.toolchain.compiler }}
version: ${{ matrix.toolchain.version }}
- name: Test C++ compiler
continue-on-error: true
if: needs.options.outputs.mode == 'report' && steps.setup-fortran.outcome == 'success'
uses: ./.github/actions/test-cxx
with:
compiler: ${{ matrix.toolchain.compiler }}
version: ${{ matrix.toolchain.version }}
- name: Create compatibility report
if: needs.options.outputs.mode == 'report'
shell: bash
run: |
mkdir -p compat
support=$([ "${{ steps.setup-fortran.outcome }}" == "success" ] && echo "✓" || echo "")
prefix="${{ matrix.os }},${{ matrix.toolchain.compiler }},${{ matrix.toolchain.version }}"
report="compat/${prefix//,/_}.csv"
echo "$prefix,$support" >> "$report"
cat "$report"
- name: Upload compatibility report
if: needs.options.outputs.mode == 'report'
uses: actions/upload-artifact@v6
with:
name: compat-${{ matrix.os }}-${{ matrix.toolchain.compiler }}-${{ matrix.toolchain.version }}
path: compat/*.csv
test-latest:
name: Test version latest resolution
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
compiler: gcc
- os: ubuntu-22.04
compiler: gcc
- os: windows-2025
compiler: gcc
- os: macos-15
compiler: gcc
- os: ubuntu-24.04
compiler: lfortran
- os: ubuntu-24.04
compiler: intel
- os: ubuntu-24.04
compiler: intel-classic
- os: ubuntu-22.04
compiler: nvidia-hpc
- os: ubuntu-24.04
compiler: nvidia-hpc
- os: ubuntu-24.04
compiler: aocc
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Fortran with version latest
id: setup-fortran
uses: ./
with:
compiler: ${{ matrix.compiler }}
version: latest
- name: Verify installed version matches expected
shell: bash
run: |
source ./setup-fortran.sh
# Detect platform (same as main.sh)
platform=$(uname -s | tr '[:upper:]' '[:lower:]')
# Get actual installed version
case "${{ matrix.compiler }}" in
gcc)
actual_version=$(gfortran --version | head -n1 | grep -oE '[0-9]+\.[0-9]+' | head -n1 | cut -d. -f1)
;;
lfortran)
actual_version=$(lfortran --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)
;;
aocc)
actual_version=$($FC --version 2>&1 | grep -oE 'AOCC[_ ][0-9]+\.[0-9]+\.[0-9]+' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)
;;
intel|intel-classic)
actual_version=$($FC --version | head -n1 | grep -woE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)
;;
nvidia-hpc)
actual_version=$(nvfortran --version 2>&1 | awk '/nvfortran/ {print $2}' | cut -d'-' -f1)
;;
*)
echo "Unknown compiler: ${{ matrix.compiler }}"
exit 1
;;
esac
echo "Actual version: $actual_version"
# For compilers that resolve 'latest' to a pinned version via latest-versions.sh,
# verify the installed version matches. For compilers that install an unversioned
# package (intel, intel-classic, nvidia-hpc), just confirm the compiler is functional.
case "${{ matrix.compiler }}" in
gcc|lfortran|aocc)
expected_version=$(resolve_latest_version "${{ matrix.compiler }}" "$platform")
echo "Expected version: $expected_version"
if [[ "$actual_version" == "$expected_version" ]]; then
echo "Version matches expected"
else
echo "Version mismatch: expected $expected_version, got $actual_version"
exit 1
fi
;;
*)
if [[ -n "$actual_version" ]]; then
echo "Compiler is functional (version: $actual_version)"
else
echo "Could not determine installed version"
exit 1
fi
;;
esac
- name: Test compiler works (compile hello world)
shell: bash
run: |
cat > hello.f90 <<EOF
program hello
print *, "Hello from Fortran!"
end program hello
EOF
${{ env.FC }} hello.f90 -o hello
./hello
compat:
name: Report compatibility
needs:
- options
- test
if: needs.options.outputs.mode == 'report'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: 3.9
- name: Install packages
run: pip install -r requirements.txt
- name: Download reports
uses: actions/download-artifact@v7
with:
pattern: compat-*
path: compat
merge-multiple: true
- name: Concatenate reports
run: |
echo "runner,compiler,version,support" > .github/compat/long_compat.csv
cat compat/*.csv >> .github/compat/long_compat.csv
- name: Make wide reports
working-directory: .github/compat
run: |
python wide_compat_reports.py "long_compat.csv" "compat.csv"
cat compat.md
- name: Upload artifacts
uses: actions/upload-artifact@v6
with:
name: compat
path: |
.github/compat/long_compat.csv
.github/compat/compat.csv
.github/compat/compat.md
- name: Check for changes
working-directory: .github/compat
id: diff
run: |
if ! [ -f compat.csv ]; then
echo "diff=false" >> $GITHUB_OUTPUT
exit 0
fi
diff=$(git diff compat.csv)
if [[ $diff == "" ]]; then
echo "No changes found"
echo "diff=false" >> $GITHUB_OUTPUT
else
echo "Changes found:"
echo "$diff"
echo "diff=true" >> $GITHUB_OUTPUT
fi
- name: Update README
if: ${{ steps.diff.outputs.diff == 'true' }}
run: python .github/compat/update_compat_table.py ".github/compat/compat.md" "README.md"
- name: Generate latest versions lookup table
if: ${{ steps.diff.outputs.diff == 'true' }}
run: python .github/compat/update_latest_versions.py ".github/compat/compat.csv" ".github/compat/latest-versions.sh"
- name: Print README diff
if: ${{ steps.diff.outputs.diff == 'true' }}
run: git diff README.md
- name: Print latest-versions.sh diff
if: ${{ steps.diff.outputs.diff == 'true' }}
run: git diff .github/compat/latest-versions.sh
- name: Create pull request
if: ${{ steps.diff.outputs.diff == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
now=$(date +'%Y-%m-%dT%H-%M-%S')
updated_branch="compat_$now"
default_branch="${{ github.event.repository.default_branch }}"
git switch -c "$updated_branch"
git add .github/compat/ README.md
git commit -m "Update compatibility matrix"
git push -u origin "$updated_branch"
gh pr create -B "$default_branch" -H "$updated_branch" --title "Update compatibility matrix" --body-file .github/compat/compat.md