-
Notifications
You must be signed in to change notification settings - Fork 8
201 lines (175 loc) · 5.9 KB
/
release.yml
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
name: Release MODFLOW executables
on:
schedule:
- cron: '0 3 * * 3' # run at 3 AM UTC every Wednesday
push:
branches:
- master
- develop
workflow_dispatch:
env:
DIST: dist
jobs:
build:
name: Build distribution
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, macos-latest, windows-2019]
defaults:
run:
shell: bash
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Setup Intel fortran
uses: fortran-lang/setup-fortran@v1
with:
compiler: intel-classic
version: 2021.7
- uses: oprypin/find-latest-tag@v1
id: tag
with:
repository: ${{ github.repository }}
releases-only: true
- name: Set environment variables
run: |
echo "${{ github.repository }} version ${{ steps.tag.outputs.tag }}"
echo "RELEASE_VERSION=${{ steps.tag.outputs.tag }}" >> $GITHUB_ENV
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip list
- name: Build executables
run: python scripts/build_executables.py
- name: Upload distribution archive
uses: actions/upload-artifact@v3
with:
name: ${{ env.DIST }}
path: ./*.zip
- name: Upload distribution metadata
if: runner.os == 'Linux'
uses: actions/upload-artifact@v3
with:
name: ${{ env.DIST }}
path: |
./code.json
./code.md
# make the release if previous job was successful
release:
name: Make release
needs: build
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install https://github.com/modflowpy/pymake/zipball/master
- name: Get last release tag
id: last-tag
uses: oprypin/find-latest-tag@v1
with:
repository: ${{ github.repository }}
releases-only: true
- name: Get next release tag
id: next-tag
run: |
current="${{ steps.last-tag.outputs.tag }}"
next=$(echo "${{ steps.last-tag.outputs.tag }} + 1.0" | bc)
echo "RELEASE_VERSION=$current" >> $GITHUB_ENV
echo "tag=$next" >> $GITHUB_OUTPUT
repo="${{ github.repository }}"
echo "$repo current version is $current"
echo "$repo next version is $next"
- name: Download distribution
uses: actions/download-artifact@v3
with:
name: ${{ env.DIST }}
path: ${{ env.DIST }}
- name: List distribution files
run: ls -l ${{ env.DIST }}
- name: Create release body header
shell: python
run: |
import os
next_version = os.getenv('NEXT_VERSION')
line = "The programs, version numbers, and the date "
line += "stamp on the downloaded file used to create the "
line += f"executables for version {next_version} are\n\n"
with open('Header.md', "w") as file:
file.write(line)
- name: Build release body
run: |
cat Header.md ${{ env.DIST }}/code.md > BodyFile.md
cat BodyFile.md
# interactive debugging
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
# with:
# limit-access-to-actor: true
- name: Update readme
id: update-readme
run: |
# update readme from metadata
cp ${{ env.DIST }}/code.md code.md
cp ${{ env.DIST }}/code.json code.json
python scripts/update_readme.py
# determine whether changes need to be committed
if [[ `git status --porcelain --untracked-files=no` ]]; then
echo "Changes to README.md:"
git diff README.md
changes="true"
else
echo "No changes to README.md"
changes="false"
fi
echo "changes=$changes" >> $GITHUB_OUTPUT
# open PR if manual trigger
- name: Draft pull request
if: github.event_name == 'workflow_dispatch' && steps.update-readme.outputs.changes == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
# commit and push
branch="update-readme-${{ steps.next-tag.outputs.tag }}"
git config core.sharedRepository true
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add README.md
git status
git switch -c $branch
git commit -m "ci(release): update readme"
git push -u origin "$branch"
# create PR
body='
# MODFLOW executables release '${{ steps.next-tag.outputs.tag }}'
This PR updates `README.md` with the latest release information.
'
gh pr create -B "master" -H "$branch" --title "Release ${{ steps.next-tag.outputs.tag }}" --draft --body "$body"
# create new release if manual trigger
- name: Create release
if: github.event_name == 'workflow_dispatch'
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.next-tag.outputs.tag }}
name: "MODFLOW and related programs binary executables"
bodyFile: "./BodyFile.md"
artifacts: "${{ env.DIST }}/*"
draft: false
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}