aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/CI.yml
blob: 9fc7918a7b492b8a491823608f839350ab8f37b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
name: CI

on:
  push:
  pull_request:
  release:
    types: [published]

env:
  CI: "ON" # We can detect this in the build system and other vendors implement it
  HOMEBREW_NO_ANALYTICS: "ON" # Make Homebrew installation a little quicker
  HOMEBREW_NO_AUTO_UPDATE: "ON"
  HOMEBREW_NO_BOTTLE_SOURCE_FALLBACK: "ON"
  HOMEBREW_NO_GITHUB_API: "ON"
  HOMEBREW_NO_INSTALL_CLEANUP: "ON"
  RUST_BACKTRACE: "full" # Make Rust print full backtrace on error

jobs:
  stack-build:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        gcc_v: [9] # Version of GFortran we want to use.
        include:
        - os: ubuntu-latest
          STACK_CACHE: "/home/runner/.stack/"
          STACK_CACHE_VERSION: ""
          TEST_SCRIPT: ci/run_tests.sh
          GET_VERSION_CMD: echo ${{ github.ref }} | cut -dv -f2
          CHECK_VERSION_CMD: grep $(cat fpm_version)
          RELEASE_CMD: "cp -- fpm-$(cat fpm_version)-linux-x86_64"
          BOOTSTRAP_RELEASE_CMD: cp /home/runner/.local/bin/fpm fpm-haskell-$(cat fpm_version)-linux-x86_64
          HASH_CMD: ls fpm-*|xargs -i{} sh -c 'sha256sum $1 > $1.sha256' -- {}
          RELEASE_FLAGS: --flag --static --flag -g --flag -fbacktrace --flag -O3

        - os: macos-latest
          STACK_CACHE: |
           /Users/runner/.stack/snapshots
           /Users/runner/.stack/setup-exe-src
          STACK_CACHE_VERSION: "v2"
          TEST_SCRIPT: ci/run_tests.sh
          GET_VERSION_CMD: echo ${{ github.ref }} | cut -dv -f2
          CHECK_VERSION_CMD: grep $(cat fpm_version)
          RELEASE_CMD: "cp -- fpm-$(cat fpm_version)-macos-x86_64"
          BOOTSTRAP_RELEASE_CMD: cp /Users/runner/.local/bin/fpm fpm-haskell-$(cat fpm_version)-macos-x86_64
          HASH_CMD: ls fpm-*|xargs -I{} sh -c 'shasum -a 256 $1 > $1.sha256' -- {}
          RELEASE_FLAGS: --flag -g --flag -fbacktrace --flag -O3

        - os: windows-latest
          STACK_CACHE: |
           C:\Users\runneradmin\AppData\Roaming\stack
           C:\Users\runneradmin\AppData\Local\Programs\stack
          STACK_CACHE_VERSION: "v2"
          TEST_SCRIPT: ci\run_tests.bat
          GET_VERSION_CMD: ("${{ github.ref }}" -Split "v")[1]
          CHECK_VERSION_CMD: Select-String -Pattern Version | Where-Object { if ($_ -like -join("*",(Get-Content fpm_version),"*")) {echo $_} else {Throw} }
          RELEASE_CMD: copy -- (-join("fpm-",(Get-Content fpm_version),"-windows-x86_64.exe"))
          BOOTSTRAP_RELEASE_CMD: copy C:\Users\runneradmin\AppData\Roaming\local\bin\fpm.exe (-join("fpm-haskell-",(Get-Content fpm_version),"-windows-x86_64.exe"))
          HASH_CMD: Get-ChildItem -File -Filter "fpm-*" | Foreach-Object {echo (Get-FileHash -Algorithm SHA256 $PSItem | Select-Object hash | Format-Table -HideTableHeaders | Out-String) > (-join($PSItem,".sha256"))}
          RELEASE_FLAGS: --flag --static --flag -g --flag -fbacktrace --flag -O3

    env:
      FC: gfortran
      GCC_V: ${{ matrix.gcc_v }}

    steps:
    - name: Checkout code
      uses: actions/checkout@v1

    - name: Install GFortran macOS
      if: contains(matrix.os, 'macos')
      run: |
          ln -s /usr/local/bin/gfortran-${GCC_V} /usr/local/bin/gfortran
          which gfortran-${GCC_V}
          which gfortran

    - name: Install GFortran Linux
      if: contains(matrix.os, 'ubuntu')
      run: |
        sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_V} 100 \
        --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${GCC_V} \
        --slave /usr/bingcov gcov /usr/bin/gcov-${GCC_V}

    - name: Get Time
      id: time
      uses: nanzm/get-time-action@v1.0
      with:
        format: 'YYYY-MM'

    - name: Setup github actions cache
      id: cache
      uses: actions/cache@v2
      with:
        path: ${{matrix.STACK_CACHE}}
        key: ${{ runner.os }}-${{ steps.time.outputs.time }}${{matrix.STACK_CACHE_VERSION}}

    - name: Build Haskell fpm
      run: |
        stack build
        stack install
      working-directory: bootstrap

    - name: put fpm to PATH (macOS)
      if: contains(matrix.os, 'macos')
      run: |
          cp /Users/runner/.local/bin/fpm /usr/local/bin

    - name: put fpm to PATH (Windows)
      if: contains(matrix.os, 'windows')
      run: |
          copy "C:\Users\runneradmin\AppData\Roaming\local\bin\fpm.exe" "C:\Program Files\Git\usr\bin"

    - name: put fpm to PATH (Linux)
      if: contains(matrix.os, 'ubuntu')
      run: |
          sudo cp /home/runner/.local/bin/fpm /usr/local/bin

    - name: Run tests on Haskell fpm
      run: |
        stack test
      working-directory: bootstrap

    # ----- Upload binaries if creating a release -----
    - name: Check that fpm --version matches release tag
      if: github.event_name == 'release'
      run: |
        ${{ matrix.GET_VERSION_CMD }} > fpm_version
      working-directory: fpm

    - name: Stage release files for upload
      if: github.event_name == 'release'
      run: |
        ${{ matrix.BOOTSTRAP_RELEASE_CMD }}
        ${{ matrix.HASH_CMD }}
      working-directory: fpm

    - name: Upload assets
      if: github.event_name == 'release'
      uses: svenstaro/upload-release-action@v2
      with:
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        file: fpm/fpm-*
        file_glob: true
        tag: ${{ github.ref }}
        overwrite: true

  build:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        gcc_v: [9] # Version of GFortran we want to use.
        include:
        - os: ubuntu-latest
          os-arch: linux-x86_64
          release-flags: --flag '--static -g -fbacktrace -O3'
          sha256sum: sha256sum

        - os: macos-latest
          os-arch: macos-x86_64
          release-flags: --flag '-g -fbacktrace -O3'
          sha256sum: shasum -a 256

        - os: windows-latest
          os-arch: windows-x86_64
          release-flags: --flag '--static -g -fbacktrace -O3'
          exe: .exe
          sha256sum: sha256sum

    env:
      FC: gfortran
      GCC_V: ${{ matrix.gcc_v }}

    steps:
    - name: Checkout code
      uses: actions/checkout@v1

    - name: Install GFortran macOS
      if: contains(matrix.os, 'macos')
      run: |
        ln -s /usr/local/bin/gfortran-${GCC_V} /usr/local/bin/gfortran
        which gfortran-${GCC_V}
        which gfortran

    - name: Install GFortran Linux
      if: contains(matrix.os, 'ubuntu')
      run: |
        sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_V} 100 \
        --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${GCC_V} \
        --slave /usr/bin/gcov gcov /usr/bin/gcov-${GCC_V}

    # Phase 1: Bootstrap fpm with existing version
    - name: Install fpm
      uses: fortran-lang/setup-fpm@v3
      with:
        fpm-version: 'v0.2.0'

    - name: Remove fpm from path
      shell: bash
      run: |
        mv $(which fpm) fpm-bootstrap${{ matrix.exe }}
        echo "BOOTSTRAP=$PWD/fpm-bootstrap" | cat >> $GITHUB_ENV

    - name: Build Fortran fpm (bootstrap)
      shell: bash
      run: |
        ${{ env.BOOTSTRAP }} build
      working-directory: fpm

    - name: Run Fortran fpm (bootstrap)
      shell: bash
      run: |
        ${{ env.BOOTSTRAP }} run
        ${{ env.BOOTSTRAP }} run -- --version
        ${{ env.BOOTSTRAP }} run -- --help
      working-directory: fpm

    - name: Test Fortran fpm (bootstrap)
      shell: bash
      run: |
        ${{ env.BOOTSTRAP }} test
      working-directory: fpm

    - name: Install Fortran fpm (bootstrap)
      shell: bash
      run: |
        ${{ env.BOOTSTRAP }} install
      working-directory: fpm

    # Phase 2: Bootstrap fpm with itself
    - name: Replace bootstrapping version
      shell: bash
      run: |
        ${{ env.BOOTSTRAP }} run --runner cp -- fpm-debug${{ matrix.exe }}
        rm -v ${{ env.BOOTSTRAP }}
        echo "FPM=$PWD/fpm-debug" | cat >> $GITHUB_ENV
      working-directory: fpm

    - name: Get version (normal)
      if: github.event_name != 'release'
      shell: bash
      run: |
        VERSION=$(git rev-parse --short HEAD)
        echo "VERSION=$VERSION" | cat >> $GITHUB_ENV

    - name: Get version (release)
      if: github.event_name == 'release'
      shell: bash
      run: |
        VERSION=$(echo ${{ github.ref }} | cut -dv -f2)
        echo "VERSION=$VERSION" | cat >> $GITHUB_ENV
        FPM_VERSION=$(${{ env.FPM }} --version | grep -o '${{ env.REGEX }}')
        [ "$VERSION" = "$FPM_VERSION" ]
      env:
        REGEX: '[0-9]\{1,4\}\.[0-9]\{1,4\}\.[0-9]\{1,4\}'

    - name: Build example packages
      shell: bash
      run: |
        ci/run_tests.sh "${{ env.FPM }}"

    - name: Build Fortran fpm
      shell: bash
      run: |
        ${{ env.FPM }} build ${{ matrix.release-flags }}
      working-directory: fpm

    - name: Run Fortran fpm
      shell: bash
      run: |
        ${{ env.FPM }} run ${{ matrix.release-flags }}
        ${{ env.FPM }} run ${{ matrix.release-flags }} -- --version
        ${{ env.FPM }} run ${{ matrix.release-flags }} -- --help
      working-directory: fpm

    - name: Test Fortran fpm
      shell: bash
      run: |
        ${{ env.FPM }} test ${{ matrix.release-flags }}
      working-directory: fpm

    - name: Install Fortran fpm
      shell: bash
      run: |
        ${{ env.FPM }} install ${{ matrix.release-flags }}
      working-directory: fpm

    - name: Package release version
      shell: bash
      run: |
        ${{ env.FPM }} run ${{ matrix.release-flags }} --runner cp -- ${{ env.EXE }}
        rm -v ${{ env.FPM }}
        echo "FPM_RELEASE=$PWD/${{ env.EXE }}" | cat >> $GITHUB_ENV
      working-directory: fpm
      env:
        EXE: fpm-${{ env.VERSION }}-${{ matrix.os-arch }}${{ matrix.exe }}

    - name: Run release version
      shell: bash
      run: |
        ci/run_tests.sh "${{ env.FPM_RELEASE }}"

    - name: Stage release files for upload
      if: github.event_name == 'release'
      shell: bash
      run: |
        ${{ matrix.sha256sum }} ${{ env.FPM_RELEASE }} > ${{ env.FPM_RELEASE }}.sha256
      working-directory: fpm

    - name: Upload assets
      if: github.event_name == 'release'
      uses: svenstaro/upload-release-action@v2
      with:
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        file: fpm/fpm-*
        file_glob: true
        tag: ${{ github.ref }}
        overwrite: true