aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/CI.yml
blob: d57e02ab5df807bafba4c03a0672df1c0e3f9515 (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
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:
  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: ""
          BOOTSTRAP_FILE: "/home/runner/.local/bin/fpm"
          XSUFFIX: ""
          CHECK_VERSION_CMD: grep $(echo ${{ github.ref }} | cut -dv -f2)
          RELEASE_CMD: "fpm run --flag --static --flag -g --flag -fbacktrace --flag -O3 --runner cp"
        - os: macos-latest
          STACK_CACHE: |
           /Users/runner/.stack/snapshots
           /Users/runner/.stack/setup-exe-src
          STACK_CACHE_VERSION: "v2"
          BOOTSTRAP_FILE: "/Users/runner/.local/bin/fpm"
          XSUFFIX: ""
          CHECK_VERSION_CMD: grep $(echo ${{ github.ref }} | cut -dv -f2)
          RELEASE_CMD: "fpm run --flag -g --flag -fbacktrace --flag -O3 --runner cp"
        - os: windows-latest
          STACK_CACHE: |
           C:\Users\runneradmin\AppData\Roaming\stack
           C:\Users\runneradmin\AppData\Local\Programs\stack
          STACK_CACHE_VERSION: "v2"
          BOOTSTRAP_FILE: C:\Users\runneradmin\AppData\Roaming\local\bin\fpm.exe
          XSUFFIX: ".exe"
          CHECK_VERSION_CMD: Select-String -Pattern Version | Where-Object { if ($_ -like -join("*",("${{ github.ref }}" -Split "v")[1],"*")) {echo $_} else {Throw} }
          RELEASE_CMD: "fpm run --flag --static --flag -g --flag -fbacktrace --flag -O3 --runner copy"

    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: |
        cd bootstrap
        stack build
        stack install

    - 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: |
        cd bootstrap
        stack test

    - name: Build and run Fortran fpm (Linux / macOS)
      if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'macos')
      run: |
        ci/run_tests.sh

    - name: Build and run Fortran fpm (Windows)
      if: contains(matrix.os, 'windows')
      run: |
        ci\run_tests.bat

    # ----- Upload binaries if creating a release -----
    - name: Check that fpm --version matches release tag
      if: github.event_name == 'release'
      run: |
        cd fpm
        fpm run -- "--version" | ${{ matrix.CHECK_VERSION_CMD }}

    - name: Stage release files for upload
      if: github.event_name == 'release'
      run: |
        cd fpm
        ${{ matrix.RELEASE_CMD }} -- fpm-${{ matrix.os }}-x86_64
         
    - name: Upload fpm binary
      if: github.event_name == 'release'
      uses: svenstaro/upload-release-action@v2
      with:
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        file: fpm/fpm-${{ matrix.os }}-x86_64
        asset_name: fpm-${{ matrix.os }}-x86_64${{ matrix.XSUFFIX }}
        tag: ${{ github.ref }}
        overwrite: true
        prerelease: true

    - name: Upload bootstrap fpm binary
      if: github.event_name == 'release'
      uses: svenstaro/upload-release-action@v2
      with:
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        file: ${{ matrix.BOOTSTRAP_FILE }}
        asset_name: fpm-bootstrap-${{ matrix.os }}-x86_64${{ matrix.XSUFFIX }}
        tag: ${{ github.ref }}
        overwrite: true
        prerelease: true