Debian Codegraph @

.github/workflows/release.yml

raw
1 name: Release
2
3 on:
4 push:
5 pull_request:
6 release:
7 types: [published]
8
9 jobs:
10 source-archive:
11 runs-on: ubuntu-latest
12 strategy:
13 fail-fast: false
14 matrix:
15 format: [zip]
16 env:
17 FORMAT: ${{ matrix.format }}
18 steps:
19 - name: Checkout code
20 uses: actions/checkout@v6
21 with:
22 fetch-depth: 0
23
24 - name: Get version number
25 run: |
26 VERSION=$(git describe --tags --match 'v*' --always | tr -d 'v')
27 echo "VERSION=${VERSION}" >> $GITHUB_ENV
28
29 - name: Create archive
30 run: |
31 echo "OUTPUT=${{ env.OUTPUT }}" >> $GITHUB_ENV
32 git archive --prefix ${{ env.PREFIX }} --format ${{ env.FORMAT }} HEAD > ${{ env.OUTPUT }}
33 env:
34 OUTPUT: fpm-${{ env.VERSION }}.${{ env.FORMAT }}
35 PREFIX: fpm-${{ env.VERSION }}/
36
37 - name: Upload artifact
38 uses: actions/upload-artifact@v6
39 with:
40 name: ${{ env.OUTPUT }}
41 path: ${{ env.OUTPUT }}
42
43 source-single-file:
44 runs-on: ubuntu-latest
45 steps:
46 - name: Checkout code
47 uses: actions/checkout@v6
48 with:
49 fetch-depth: 0
50
51 - name: Get version number
52 run: |
53 VERSION=$(git describe --tags --match 'v*' --always | tr -d 'v')
54 echo "VERSION=${VERSION}" >> $GITHUB_ENV
55 echo ${{ env.VERSION }}
56
57 - name: Get manifest version
58 run: |
59 MANIFEST_VERSION=$(grep version fpm.toml | head -1 | tr -d ' ' | tr -d 'version=')
60 echo "MANIFEST_VERSION=${MANIFEST_VERSION}" >> $GITHUB_ENV
61 echo ${{ env.MANIFEST_VERSION }}
62
63 # Note: this step is meant to remove the test targets from the package manifest,
64 # a change in the package manifest might require to regenerate the patch file.
65 - name: Remove tests
66 run: |
67 patch -p1 < ./ci/single-file.patch
68
69 - name: Install fpm
70 uses: fortran-lang/setup-fpm@v9
71 with:
72 fpm-version: 'v0.8.0'
73
74 - name: Create single file version
75 run: |
76 echo "OUTPUT=${{ env.OUTPUT }}" >> $GITHUB_ENV
77 echo "#define FPM_BOOTSTRAP" > fpm-${{ env.VERSION }}.F90
78 # We need to pass the exact version string that a fpm build command would send
79 echo "#define FPM_RELEASE_VERSION ${{ env.MANIFEST_VERSION }}" >> fpm-${{ env.VERSION }}.F90
80 # Intel compiler predefines "linux" and "unix" which causes inadvertent substitutions
81 echo "#undef linux" >> fpm-${{ env.VERSION }}.F90
82 echo "#undef unix" >> fpm-${{ env.VERSION }}.F90
83 fpm build --compiler ./ci/single-file-gfortran.sh
84 env:
85 OUTPUT: fpm-${{ env.VERSION }}.F90
86 OMP_NUM_THREADS: 1
87
88 # Building the bootstrap version from the single source version is the most expensive
89 # step in this workflow, since we have to compile several thousand lines of source.
90 - name: Build single source version
91 run: |
92 echo "EXE=${{ env.BUILD_DIR }}/fpm" >> $GITHUB_ENV
93 mkdir ${{ env.BUILD_DIR }}
94 gfortran ${{ env.OUTPUT }} -J ${{ env.BUILD_DIR }} -o ${{ env.BUILD_DIR }}/fpm
95 env:
96 BUILD_DIR: build/bootstrap
97
98 - name: Undo patch
99 run: |
100 patch -p1 -R < ./ci/single-file.patch
101
102 - name: Build fpm with bootstrap version
103 run: |
104 ${{ env.EXE }} build
105
106 - name: Upload artifact
107 uses: actions/upload-artifact@v6
108 with:
109 name: ${{ env.OUTPUT }}
110 path: ${{ env.OUTPUT }}
111
112 upload-artifacts:
113 if: ${{ github.event_name == 'release' && contains(github.ref, 'v') || github.event_name == 'push' }}
114 runs-on: ubuntu-latest
115 needs:
116 - source-archive
117 - source-single-file
118
119 steps:
120 - id: deploy-on-push
121 if: ${{ github.event_name == 'push' }}
122 run:
123 echo "::set-output name=result::${{ env.DEPLOY_BRANCH }}"
124 env:
125 DEPLOY_BRANCH: ${{ secrets.DEPLOY_BRANCH && contains(github.ref, secrets.DEPLOY_BRANCH) && 1 || 0 }}
126
127 - uses: actions/checkout@v6
128 if: ${{ github.event_name == 'push' }}
129
130 - name: Download Artifacts
131 uses: actions/download-artifact@v7
132 with:
133 path: fpm-cd-artifacts
134 merge-multiple: true
135
136 - name: Normalize file names for continuous delivery
137 if: ${{ github.event_name == 'push' }}
138 run: |
139 cd fpm-cd-artifacts
140 for output in fpm-*; do
141 mv -v $(basename $output) $(basename $output | sed -E '${{ env.replace }}')
142 done
143 env:
144 replace: 's/-([0-9]+\.[0-9]+\.[0-9]+-[0-9]+-g)?[0-9a-f]+//'
145
146 - name: Create SHA256 checksums
147 run: |
148 cd fpm-cd-artifacts
149 for output in fpm-*; do
150 sha256sum $(basename "$output") | tee $(basename "$output").sha256
151 done
152
153 - name: Move/Create continuous tag
154 if: ${{ github.event_name == 'push' && steps.deploy-on-push.outputs.result != 0 }}
155 run: |
156 git tag --force 'current' ${{ github.sha }}
157 git push --tags --force
158
159 - name: Upload assets
160 if: ${{ github.event_name == 'release' || steps.deploy-on-push.outputs.result != 0 }}
161 uses: svenstaro/upload-release-action@v2
162 with:
163 repo_token: ${{ secrets.GITHUB_TOKEN }}
164 file: fpm-cd-artifacts/*
165 file_glob: true
166 tag: ${{ github.event_name == 'release' && github.ref || 'current'}}
167 overwrite: true