Skip to content

Commit 1c49281

Browse files
authored
Versioning support (#27)
1 parent 2904768 commit 1c49281

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

.github/workflows/firmware.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ jobs:
1010
build:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
14+
- name: Set FIRMWARE_VERSION variable
15+
run: |
16+
FIRMWARE_VER=$(cat VERSION)
17+
echo "FIRMWARE_VERSION=$FIRMWARE_VER" >> $GITHUB_ENV
18+
- name: Set FIRMWARE_COMMIT_HASH variable
19+
run: echo "FIRMWARE_COMMIT_SHA=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
1420
- name: Set up Python
15-
uses: actions/setup-python@v2
21+
uses: actions/setup-python@v3
1622
with:
1723
python-version: 3.8
1824
- name: Install dependencies
@@ -21,7 +27,9 @@ jobs:
2127
pip install platformio
2228
- name: Build
2329
run: pio run
24-
- uses: actions/upload-artifact@v2
30+
- name: Rename firmware
31+
run: mv .pio/build/rpipicow/firmware.uf2 .pio/build/rpipicow/xrp-wpilib-firmware-${{ env.FIRMWARE_VERSION }}-${{ env.FIRMWARE_COMMIT_SHA }}.uf2
32+
- uses: actions/upload-artifact@v3
2533
with:
26-
name: xrp-wpilib-firmware.uf2
27-
path: .pio/build/rpipicow/firmware.uf2
34+
name: xrp-wpilib-firmware-${{ env.FIRMWARE_VERSION }}-${{ env.FIRMWARE_COMMIT_SHA }}
35+
path: .pio/build/rpipicow/xrp-wpilib-firmware-*.uf2

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.5.1

extra_script.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
resBuildDir = os.path.join(env.subst("$BUILD_DIR"), "resources", "build")
1010
resDir = os.path.join(env.subst("$PROJECT_DIR"), "resources")
1111
minifiedJsDir = os.path.join(env.subst("$BUILD_DIR"), "resources", "minifiedjs")
12+
versionReplaceDir = os.path.join(env.subst("$BUILD_DIR"), "resources", "versionReplace")
13+
14+
# open the VERSION file
15+
versionFile = os.path.join(env.subst("$PROJECT_DIR"), "VERSION")
16+
version = "UNK"
17+
with open(versionFile, "r") as f:
18+
version = f.read().strip()
19+
print("Version Info: ", version)
1220

1321
print("Resource Dir: ", resDir)
1422

@@ -24,6 +32,10 @@
2432
shutil.rmtree(minifiedJsDir)
2533
os.makedirs(minifiedJsDir)
2634

35+
if os.path.exists(versionReplaceDir):
36+
shutil.rmtree(versionReplaceDir)
37+
os.makedirs(versionReplaceDir)
38+
2739
def genResource(inputFile):
2840
with open(inputFile, "rb") as f:
2941
data = f.read()
@@ -54,6 +66,21 @@ def minifyJs(inputFile):
5466

5567
return outputFile
5668

69+
def versionReplace(inputFile):
70+
with open(inputFile, "r") as f:
71+
data = f.read()
72+
73+
inputBase = os.path.basename(inputFile)
74+
outputFile = os.path.join(versionReplaceDir, inputBase)
75+
76+
# find replacement
77+
data = data.replace("%%%VERSION_REPLACE%%%", version)
78+
79+
with open(outputFile, "w") as f:
80+
print(data, file=f)
81+
82+
return outputFile
83+
5784

5885
# Loop through everything in the resources folder
5986
# For each item, generate the resource cpp file
@@ -65,6 +92,8 @@ def minifyJs(inputFile):
6592
# minify JS files
6693
if len(fileExt) > 1 and (fileExt[-1]).lower() == ".js":
6794
genResource(minifyJs(f))
95+
elif filename == "index.html":
96+
genResource(versionReplace(f))
6897
else:
6998
genResource(f)
7099

resources/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ <h4>XRP Configuration</h4>
2323
<input class="button-primary" id="saveButton" type="submit" value="Save">
2424
</form>
2525
</div>
26+
<div class="row">
27+
Firmware Version: %%%VERSION_REPLACE%%%
28+
</div>
2629
</body>
2730
</html>

0 commit comments

Comments
 (0)