Skip to content

Commit bbdf4f6

Browse files
committed
Add nightly releases
Add build workflow action Add release workflow action Separate unit test runs from build process Update ubuntu runner to 22.04 Move pre-commit checks to prek Pin workflow actions to commits Remove non-master push builds Add path changed whitelist for builds workflow Update ubuntu builds to use GCC 13
1 parent 3f43c2c commit bbdf4f6

9 files changed

Lines changed: 976 additions & 110 deletions

File tree

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Build OpenVic-Simulation
2+
description: Setup and Build OpenVic-Simulation with the provided options
3+
4+
inputs:
5+
identifier:
6+
description: Identifier of this build
7+
type: string
8+
target:
9+
description: Target type to build for
10+
type: choice
11+
options: [template_release, template_debug, editor]
12+
platform:
13+
description: Platform to build for
14+
type: choice
15+
options: [windows, linux, macos]
16+
arch:
17+
description: Architecture to build for
18+
type: choice
19+
options: [x86_64, universal]
20+
scons-flags:
21+
description: Additional flags to send to SCons
22+
required: false
23+
default: 'build_ovsim_benchmarks=yes'
24+
type: string
25+
build-library:
26+
description: Whether to build the library file
27+
default: true
28+
type: boolean
29+
cache-base-branch:
30+
description: |
31+
Branch to base the cache upon
32+
required: false
33+
default: 'master'
34+
type: string
35+
disable-cache:
36+
description: Whether to disable the build cache
37+
default: false
38+
type: boolean
39+
40+
runs:
41+
using: composite
42+
steps:
43+
- name: Setup build cache
44+
uses: OpenVicProject/openvic-cache@master
45+
if: ${{ !inputs.disable-cache }}
46+
with:
47+
cache-name: ${{ inputs.identifier }}
48+
base-branch: ${{ inputs.cache-base-branch }}
49+
continue-on-error: true
50+
51+
- name: Set up Python
52+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
53+
with:
54+
python-version: "3.x"
55+
56+
- name: Set up SCons
57+
shell: bash
58+
run: |
59+
python -c "import sys; print(sys.version)"
60+
python -m pip install scons
61+
scons --version
62+
63+
- name: Install APT dependencies
64+
if: ${{ inputs.platform == 'linux' }}
65+
uses: awalsh128/cache-apt-pkgs-action@acb598e5ddbc6f68a970c5da0688d2f3a9f04d05 # v1.6.0
66+
with:
67+
packages: build-essential pkg-config libtbb-dev
68+
69+
- name: Install and Set g++ to version 13
70+
if: ${{ inputs.platform == 'linux' }}
71+
shell: sh
72+
run: |
73+
g++ --version
74+
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
75+
sudo apt update -y
76+
sudo apt install g++-13
77+
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 13
78+
sudo update-alternatives --set g++ /usr/bin/g++-13
79+
g++ --version
80+
81+
- name: Compile with SCons
82+
uses: OpenVicProject/openvic-build@master
83+
with:
84+
platform: ${{ inputs.platform }}
85+
target: ${{ inputs.target }}
86+
sconsflags: arch=${{ inputs.arch }} ${{ inputs.build-library && 'build_ovsim_library=yes' }} ${{ inputs.scons-flags }}
87+
88+
- name: Delete compilation files
89+
if: ${{ inputs.platform == 'windows' }}
90+
shell: pwsh
91+
run: |
92+
Remove-Item bin/* -Include *.exp,*.pdb -Force
93+
94+
- name: Upload library artifact
95+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
96+
with:
97+
name: ${{ github.event.repository.name }}-${{ inputs.identifier }}-library
98+
path: |
99+
${{ github.workspace }}/bin/libopenvic-simulation.*
100+
101+
- name: Upload executable artifact
102+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
103+
with:
104+
name: ${{ github.event.repository.name }}-${{ inputs.identifier }}-executable
105+
path: |
106+
${{ github.workspace }}/bin/openvic-simulation.headless.*
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
name: Release OpenVic-Simulation
2+
description: Setup, Build, and Release OpenVic-Simulation
3+
4+
inputs:
5+
tag-name:
6+
description: 'Name to assign to the tag (default: github.ref)'
7+
default: ${{ github.ref }}
8+
type: string
9+
target-repo:
10+
description: Repository to publish this release to
11+
default: 'OpenVic-Simulation'
12+
type: string
13+
to-ref:
14+
description: 'Tag/Commit to publish this release to (default: github.ref)'
15+
default: ${{ github.ref }}
16+
type: string
17+
from-ref:
18+
description: Tag/Commit to source the release notes from
19+
type: string
20+
required: true
21+
from-tag:
22+
description: 'Tag name being sourced from (default: from-ref)'
23+
default: ''
24+
type: string
25+
nightly-release:
26+
description: Whether the release is a nightly build
27+
type: boolean
28+
default: false
29+
snapshot-release:
30+
description: Whether the release is a snapshot release
31+
type: boolean
32+
default: false
33+
latest:
34+
description: Latest
35+
type: boolean
36+
default: false
37+
prerelease:
38+
description: Pre-release
39+
type: boolean
40+
required: true
41+
src-token:
42+
description: Github token for source repository
43+
required: true
44+
target-token:
45+
description: Github token for target repository
46+
required: false
47+
default: ''
48+
49+
runs:
50+
using: composite
51+
steps:
52+
- name: Copy src-token to env.TARGET_TOKEN
53+
if: inputs.target-repo == 'OpenVic-Simulation'
54+
shell: bash
55+
env:
56+
INPUTS_SRC_TOKEN: ${{ inputs.src-token }}
57+
run: echo "TARGET_TOKEN=$INPUTS_SRC_TOKEN" >> $GITHUB_ENV
58+
59+
- name: Copy target-token to env.TARGET_TOKEN
60+
if: inputs.target-repo != 'OpenVic-Simulation'
61+
shell: bash
62+
env:
63+
INPUTS_TARGET_TOKEN: ${{ inputs.target-token }}
64+
run: |
65+
if [[ -z $INPUTS_TARGET_TOKEN ]]; then
66+
echo "::error file=.github/actions/openvic-sim-release/action.yml,line=66,endLine=66::target-repo was set to a different repository and the target-token was not set."
67+
exit 1
68+
fi
69+
echo "TARGET_TOKEN=$INPUTS_TARGET_TOKEN" >> $GITHUB_ENV
70+
71+
- name: Set TO_TAG from to-ref
72+
if: inputs.tag-name == github.ref && !contains(inputs.to-ref, 'refs/tags')
73+
shell: bash
74+
env:
75+
INPUTS_TO_REF: ${{ inputs.to-ref }}
76+
run: echo "TO_TAG=$INPUTS_TO_REF" >> $GITHUB_ENV
77+
78+
- name: Remove refs/tags from to-ref and set as TO_TAG
79+
if: inputs.tag-name == github.ref && contains(inputs.to-ref, 'refs/tags')
80+
shell: bash
81+
env:
82+
INPUTS_TO_REF: ${{ inputs.to-ref }}
83+
run: echo "TO_TAG=$(T='$INPUTS_TO_REF'; T=${T#"refs/tags/"}; echo $T)" >> $GITHUB_ENV
84+
85+
- name: Set TO_TAG from tag-name
86+
if: inputs.tag-name != github.ref
87+
shell: bash
88+
env:
89+
INPUTS_TAG_NAME: ${{ inputs.tag-name }}
90+
run: echo "TO_TAG=$INPUTS_TAG_NAME" >> $GITHUB_ENV
91+
92+
- name: Build Release Notes
93+
if: inputs.snapshot-release == 'false' && inputs.nightly-release == 'false'
94+
uses: mikepenz/release-changelog-builder-action@348e88fab4c37338b1e803ceb2d4a7a5db6c0833 # v6.2.2
95+
env:
96+
GITHUB_TOKEN: ${{ inputs.src-token }}
97+
with:
98+
configuration: ".github/actions/openvic-sim-release/release-notes-configuration.json"
99+
toTag: ${{ contains(inputs.to-ref, 'refs/tags') && inputs.tag-name == github.ref && env.TO_TAG || inputs.to-ref }}
100+
fromTag: ${{ inputs.from-ref }}
101+
outputFile: release-notes.md
102+
103+
- name: Build Snapshot Release Notes
104+
if: inputs.snapshot-release == 'true' && inputs.nightly-release == 'false'
105+
uses: mikepenz/release-changelog-builder-action@348e88fab4c37338b1e803ceb2d4a7a5db6c0833 # v6.2.2
106+
env:
107+
GITHUB_TOKEN: ${{ inputs.src-token }}
108+
with:
109+
configuration: ".github/actions/openvic-sim-release/snapshot-release-notes-configuration.json"
110+
toTag: ${{ contains(inputs.to-ref, 'refs/tags') && inputs.tag-name == github.ref && env.TO_TAG || inputs.to-ref }}
111+
fromTag: ${{ inputs.from-ref }}
112+
outputFile: release-notes.md
113+
114+
- name: Build Nightly Release Notes
115+
if: inputs.nightly-release == 'true' && inputs.snapshot-release == 'false'
116+
uses: mikepenz/release-changelog-builder-action@348e88fab4c37338b1e803ceb2d4a7a5db6c0833 # v6.2.2
117+
env:
118+
GITHUB_TOKEN: ${{ inputs.src-token }}
119+
with:
120+
configuration: ".github/actions/openvic-sim-release/nightly-release-notes-configuration.json"
121+
toTag: ${{ contains(inputs.to-ref, 'refs/tags') && inputs.tag-name == github.ref && env.TO_TAG || inputs.to-ref }}
122+
fromTag: ${{ inputs.from-ref }}
123+
outputFile: release-notes.md
124+
125+
- name: Create release tag and name and set release name in release-notes.md
126+
if: inputs.tag-name != github.ref
127+
shell: bash
128+
env:
129+
INPUTS_TAG_NAME: ${{ inputs.tag-name }}
130+
run: |
131+
# Sets major, minor, patch, prerelease_type, prerelease_version, year, month, day, dev, and hash values in bash environment
132+
declare $(awk '
133+
split($0, sections, /[-+]?/) split(sections[1], version, /\./) split(sections[2], prerelease, /\./) {
134+
year=""
135+
month=""
136+
day=""
137+
prerelease_version=""
138+
dev=""
139+
if (prerelease[1] == "snapshot" && prerelease[2] == "dev")
140+
dev="dev"
141+
if (prerelease[1] == "nightly") {
142+
year=prerelease[2]
143+
month=prerelease[3]
144+
day=prerelease[4]
145+
} else {
146+
prerelease_version=prerelease[2]
147+
}
148+
} END {
149+
version_core=version[1]"."version[2]
150+
if (version[3] != "") {
151+
version_core=version_core"."version[3]
152+
}
153+
154+
prerelease_name=prerelease[1]
155+
if (prerelease[1] == "rc") {
156+
prerelease_name="Release Candidate"
157+
}
158+
sub(".", substr(toupper(prerelease_name), 1,1) , prerelease_name)
159+
if (dev != "") {
160+
prerelease_name=dev" "prerelease_name
161+
}
162+
sub(".", substr(toupper(prerelease_name), 1,1) , prerelease_name)
163+
164+
prerelease_date_or_version=prerelease_version
165+
if (prerelease[1] == "nightly") {
166+
prerelease_date_or_version=year"."month"."day
167+
}
168+
169+
dotted_dev=""
170+
if (dev == "dev") {
171+
dotted_dev=".dev"
172+
}
173+
174+
print "version_core="version_core, "prerelease_type="prerelease[1] dotted_dev, "prerelease_version="prerelease_version, "prerelease_name="prerelease_name, "prerelease_date_or_version="prerelease_date_or_version, "hash="sections[3]
175+
}' <<< "$INPUTS_TAG_NAME")
176+
177+
# Keep up to date with .github/actions/openvic-sim-release/nightly-release-notes-configuration.json
178+
sed -i "s/<<RELEASE_NAME_REPLACEMENT>>/$version_core $prerelease_name $prerelease_date_or_version/g" release-notes.md
179+
sed -i "s/<<FROM_TAG_NAME_REPLACEMENT>>/${{ inputs.from-tag || inputs.from-ref }}/g" release-notes.md
180+
181+
- name: Replace <<REPO>> in release-notes.md
182+
shell: bash
183+
run: sed -i "s/<<REPO>>/$(sed 's;\/;\\\/;g' <<< "${{ github.repository }}")/g" release-notes.md
184+
185+
- name: Replace <<REPO_NAME>> in release-notes.md
186+
shell: bash
187+
run: sed -i "s/<<REPO_NAME>>/$(basename ${{ github.repository }})/g" release-notes.md
188+
189+
- name: Capitalize everything in <<capitalize:>> in release-notes.md
190+
shell: bash
191+
run: sed -i 's/<<capitalize:\([^>]*\)*>>/\u\1/g' release-notes.md
192+
193+
- name: Handle <<optional:>> in release-notes.md
194+
shell: bash
195+
run: |
196+
# Trim whitespace around of <<optional:contents>>
197+
# Add space to both sides of contents
198+
# Replace empty double space <<optional: >> tag (representing empty optional) with single space
199+
# Replace <<optional:contents>> tag with contents
200+
# strip <<trim-right: and >>
201+
sed -i 's/[ ]*<<optional:\([^>]*\)*>>[ ]*/<<optional: \1 >>/g; s/<<optional: >>/ /g; s/<<optional:\([^>]*\)*>>/\1/g' release-notes.md
202+
203+
- name: Retrieve RELEASE_NAME from release-notes.md
204+
shell: bash
205+
run: echo "RELEASE_NAME=$(grep -oP '^##\s*Release Notes for\s+\K.*' release-notes.md | head -n1)" >> $GITHUB_ENV
206+
207+
- name: Make library directory
208+
shell: sh
209+
run: mkdir "${{ github.workspace }}/library/"
210+
211+
- name: Download library assets
212+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
213+
with:
214+
path: "${{ github.workspace }}/library"
215+
pattern: ${{ github.event.repository.name }}-*-library
216+
merge-multiple: true
217+
218+
- name: Download executable assets
219+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
220+
with:
221+
pattern: ${{ github.event.repository.name }}-*-executable
222+
merge-multiple: true
223+
224+
- name: Zip library assets
225+
uses: thedoctor0/zip-release@b57d897cb5d60cb78b51a507f63fa184cfe35554 # v0.7.6
226+
with:
227+
type: "zip"
228+
filename: libopenvic-simulation.zip
229+
path: library
230+
231+
- name: Create and upload asset
232+
uses: ncipollo/release-action@339a81892b84b4eeb0f6e744e4574d79d0d9b8dd # v1.21.0
233+
with:
234+
allowUpdates: true
235+
artifacts: "libopenvic-simulation.zip,openvic-simulation.headless.**"
236+
omitNameDuringUpdate: true
237+
omitBodyDuringUpdate: true
238+
name: "${{ env.RELEASE_NAME || '' }}"
239+
tag: "${{ env.TO_TAG || '' }}"
240+
commit: "${{ format('{0}/{1}', github.repository_owner, inputs.target-repo) == github.repository && !contains(inputs.to-ref, '.') && inputs.to-ref || '' }}"
241+
bodyFile: "release-notes.md"
242+
makeLatest: ${{ inputs.latest }}
243+
prerelease: ${{ inputs.prerelease }}
244+
draft: ${{ inputs.snapshot-release == 'false' && inputs.nightly-release == 'false' }}
245+
repo: "${{ inputs.target-repo }}"
246+
token: ${{ env.TARGET_TOKEN }}

0 commit comments

Comments
 (0)