Skip to content

Commit df8c9b4

Browse files
authored
Add workflow to create source releases (#563)
- add release workflow to generate source archives - add workflow and script to automatically create single source file
1 parent 6bbb307 commit df8c9b4

File tree

3 files changed

+169
-0
lines changed

3 files changed

+169
-0
lines changed

.github/workflows/release.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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@v2
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@v2
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@v2
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+
56+
# Note: this step is meant to remove the test targets from the package manifest,
57+
# a change in the package manifest might require to regenerate the patch file.
58+
- name: Remove tests
59+
run: |
60+
patch -p1 < ./ci/single-file.patch
61+
62+
- name: Install fpm
63+
uses: fortran-lang/setup-fpm@v3
64+
with:
65+
fpm-version: 'v0.4.0'
66+
67+
- name: Create single file version
68+
run: |
69+
echo "OUTPUT=${{ env.OUTPUT }}" >> $GITHUB_ENV
70+
echo "#define FPM_BOOTSTRAP" > fpm-${{ env.VERSION }}.F90
71+
fpm build --compiler ./ci/single-file-gfortran.sh
72+
env:
73+
OUTPUT: fpm-${{ env.VERSION }}.F90
74+
OMP_NUM_THREADS: 1
75+
76+
# Building the bootstrap version from the single source version is the most expensive
77+
# step in this workflow, since we have to compile several thousand lines of source.
78+
- name: Build single source version
79+
run: |
80+
echo "EXE=${{ env.BUILD_DIR }}/fpm" >> $GITHUB_ENV
81+
mkdir ${{ env.BUILD_DIR }}
82+
gfortran ${{ env.OUTPUT }} -J ${{ env.BUILD_DIR }} -o ${{ env.BUILD_DIR }}/fpm
83+
env:
84+
BUILD_DIR: build/bootstrap
85+
86+
- name: Undo patch
87+
run: |
88+
patch -p1 -R < ./ci/single-file.patch
89+
90+
- name: Build fpm with bootstrap version
91+
run: |
92+
${{ env.EXE }} build
93+
94+
- name: Upload artifact
95+
uses: actions/upload-artifact@v2
96+
with:
97+
name: ${{ env.OUTPUT }}
98+
path: ${{ env.OUTPUT }}
99+
100+
upload-artifacts:
101+
if: github.event_name == 'release'
102+
runs-on: ubuntu-latest
103+
needs:
104+
- source-archive
105+
- source-single-file
106+
107+
steps:
108+
- name: Download Artifacts
109+
uses: actions/download-artifact@v2
110+
with:
111+
path: ${{ github.workspace }} # This will download all files
112+
113+
- name: Create SHA256 checksums
114+
run: |
115+
for output in fpm-*/fpm-*; do
116+
pushd $(dirname "$output")
117+
sha256sum $(basename "$output") | tee $(basename "$output").sha256
118+
popd
119+
done
120+
121+
- name: Upload assets
122+
if: ${{ github.event_name == 'release' }}
123+
uses: svenstaro/upload-release-action@v2
124+
with:
125+
repo_token: ${{ secrets.GITHUB_TOKEN }}
126+
file: fpm-*/fpm-*
127+
file_glob: true
128+
tag: ${{ github.ref }}
129+
overwrite: true

ci/single-file-gfortran.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
output="${OUTPUT:-fpm-single-file.F90}"
4+
5+
args=("$@")
6+
file=$(printf "%s\n" "${args[@]}" | grep -P '^.+\.[fF]90$')
7+
if [ $? = 0 ]; then
8+
echo " + Appending source file '$file' to '${output}'"
9+
cat $file >> "${output}"
10+
fi
11+
exec gfortran "${args[@]}"

ci/single-file.patch

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
diff --git a/fpm.toml b/fpm.toml
2+
index 12ec05aa..20425dfd 100644
3+
--- a/fpm.toml
4+
+++ b/fpm.toml
5+
@@ -14,22 +14,5 @@ rev = "2f5eaba864ff630ba0c3791126a3f811b6e437f3"
6+
git = "https://github.com/urbanjost/M_CLI2.git"
7+
rev = "ea6bbffc1c2fb0885e994d37ccf0029c99b19f24"
8+
9+
-[[test]]
10+
-name = "cli-test"
11+
-source-dir = "test/cli_test"
12+
-main = "cli_test.f90"
13+
-
14+
-[[test]]
15+
-name = "new-test"
16+
-source-dir = "test/new_test"
17+
-main = "new_test.f90"
18+
-
19+
-[[test]]
20+
-name = "fpm-test"
21+
-source-dir = "test/fpm_test"
22+
-main = "main.f90"
23+
-
24+
-[[test]]
25+
-name = "help-test"
26+
-source-dir = "test/help_test"
27+
-main = "help_test.f90"
28+
+[build]
29+
+auto-tests = false

0 commit comments

Comments
 (0)