|
1 | 1 | name: Test
|
2 | 2 |
|
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 * * *' |
4 | 14 |
|
5 | 15 | jobs:
|
6 | 16 | test:
|
| 17 | + name: Test compiler |
7 | 18 | runs-on: ${{ matrix.os }}
|
8 | 19 | strategy:
|
9 | 20 | fail-fast: false
|
10 | 21 | 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] |
12 | 23 | compiler: [gcc]
|
13 |
| - version: [11, 10, 9, 8] |
14 |
| - |
| 24 | + version: [12, 11, 10, 9, 8, 7, 6, 5] |
15 | 25 | steps:
|
| 26 | + |
16 | 27 | - name: Checkout repository
|
17 |
| - uses: actions/checkout@v2 |
| 28 | + uses: actions/checkout@v3 |
18 | 29 |
|
19 | 30 | - name: Setup Fortran
|
| 31 | + continue-on-error: true |
20 | 32 | id: setup-fortran
|
21 | 33 | uses: ./
|
22 | 34 | with:
|
23 | 35 | compiler: ${{ matrix.compiler }}
|
24 | 36 | version: ${{ matrix.version }}
|
25 | 37 |
|
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 }} |
27 | 44 | 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' |
30 | 59 | shell: bash
|
31 | 60 | env:
|
32 | 61 | FC: ${{ steps.setup-fortran.outputs.fc }}
|
33 | 62 | 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 |
0 commit comments