aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/release.yml
blob: a3c5259ffc98e0f16ffaa9b7c7638308ad1e09dd (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
name: Release

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

jobs:
  source-archive:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        format: [zip]
    env:
      FORMAT: ${{ matrix.format }}
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
      with:
        fetch-depth: 0

    - name: Get version number
      run: |
        VERSION=$(git describe --tags --match 'v*' --always | tr -d 'v')
        echo "VERSION=${VERSION}" >> $GITHUB_ENV

    - name: Create archive
      run: |
        echo "OUTPUT=${{ env.OUTPUT }}" >> $GITHUB_ENV
        git archive --prefix ${{ env.PREFIX }} --format ${{ env.FORMAT }} HEAD > ${{ env.OUTPUT }}
      env:
        OUTPUT: fpm-${{ env.VERSION }}.${{ env.FORMAT }}
        PREFIX: fpm-${{ env.VERSION }}/

    - name: Upload artifact
      uses: actions/upload-artifact@v2
      with:
        name: ${{ env.OUTPUT }}
        path: ${{ env.OUTPUT }}

  source-single-file:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v2
      with:
        fetch-depth: 0

    - name: Get version number
      run: |
        VERSION=$(git describe --tags --match 'v*' --always | tr -d 'v')
        echo "VERSION=${VERSION}" >> $GITHUB_ENV

    # Note: this step is meant to remove the test targets from the package manifest,
    #       a change in the package manifest might require to regenerate the patch file.
    - name: Remove tests
      run: |
        patch -p1 < ./ci/single-file.patch

    - name: Install fpm
      uses: fortran-lang/setup-fpm@v3
      with:
        fpm-version: 'v0.4.0'

    - name: Create single file version
      run: |
        echo "OUTPUT=${{ env.OUTPUT }}" >> $GITHUB_ENV
        echo "#define FPM_BOOTSTRAP" > fpm-${{ env.VERSION }}.F90
        fpm build --compiler ./ci/single-file-gfortran.sh
      env:
        OUTPUT: fpm-${{ env.VERSION }}.F90
        OMP_NUM_THREADS: 1

    # Building the bootstrap version from the single source version is the most expensive
    # step in this workflow, since we have to compile several thousand lines of source.
    - name: Build single source version
      run: |
        echo "EXE=${{ env.BUILD_DIR }}/fpm" >> $GITHUB_ENV
        mkdir ${{ env.BUILD_DIR }}
        gfortran ${{ env.OUTPUT }} -J ${{ env.BUILD_DIR }} -o ${{ env.BUILD_DIR }}/fpm
      env:
        BUILD_DIR: build/bootstrap

    - name: Undo patch
      run: |
        patch -p1 -R < ./ci/single-file.patch

    - name: Build fpm with bootstrap version
      run: |
        ${{ env.EXE }} build

    - name: Upload artifact
      uses: actions/upload-artifact@v2
      with:
        name: ${{ env.OUTPUT }}
        path: ${{ env.OUTPUT }}

  upload-artifacts:
    if: github.event_name == 'release'
    runs-on: ubuntu-latest
    needs:
      - source-archive
      - source-single-file

    steps:
    - name: Download Artifacts
      uses: actions/download-artifact@v2
      with:
        path: ${{ github.workspace }} # This will download all files

    - name: Create SHA256 checksums
      run: |
        for output in fpm-*/fpm-*; do
          pushd $(dirname "$output")
          sha256sum $(basename "$output") | tee $(basename "$output").sha256
          popd
        done

    - 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