-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (120 loc) · 5.18 KB
/
compile-sketches.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
name: Compile and Release Binary
# Compile binary and create release only in response to a pull request or a call from an auto-update workflow.
on:
push:
pull_request:
workflow_call:
inputs:
auto-update:
required: false
type: boolean
default: false
env:
CONFIG_FILE: ./DCTransistor/config.h
BI_CONFIG_FILE: ./DCTransistor-Bidirectional/config.h
BOM_FILE: bom.json
BIN_NAME: dctransistor.bin
BI_BIN_NAME: dctransistor-bidirectional.bin
jobs:
compile-sketches:
runs-on: ubuntu-latest
outputs:
release-version: ${{ steps.set-version.outputs.version }}
env:
COMPILE_OUT_DIR: /tmp/
COMPILE_OUT_NAME: DCTransistor.ino.bin
COMPILE_OUT_BI_NAME: DCTransistor-Bidirectional.ino.bin
steps:
- name: Checkout
uses: actions/[email protected]
- name: Install tools
run: sudo apt-get install -y gzip
- name: Real Checkout
run: git pull origin main
- name: Set release version
id: set-version
run: |
code_version=$(grep "#define VERSION" ${CONFIG_FILE} | cut -d '"' -f 2)
# If updating release b/c of upstream update, auto-increment minor version.
# Else, version must be changed in code upload
if [[ "${{ inputs.auto-update }}" == true ]]; then
code_minor_version=$(echo ${code_version} | cut -d '.' -f 3)
let "new_minor_version=code_minor_version+1"
next_version=$(echo -n ${code_version} | awk -F. '{printf("%s.%s", $1, $2)}'; echo -n ".${new_minor_version}")
sed -i -e "/define VERSION /s/${code_version}/${next_version}/" ${CONFIG_FILE}
sed -i -e "/define VERSION /s/${code_version}/${next_version}/" ${BI_CONFIG_FILE}
else
next_version=$code_version
fi
# Update version in BOM with version in code and release
old_ver=$(cat ${{ env.BOM_FILE }} | jq '.metadata.component.version' | cut -d '"' -f 2)
sed -i -e "/dctransistor-/s/${old_ver}/${next_version}/" ${{ env.BOM_FILE }}
sed -i -e "/version/s/${old_ver}/${next_version}/" ${{ env.BOM_FILE }}
echo "version=$next_version" >> $GITHUB_OUTPUT
- name: Inject API Key
run: |
sed -i -E "/SECRET_WMATA_API_KEY/s/[0-9a-f]{32}/${{ secrets.WMATA_API_KEY }}/" ${CONFIG_FILE}
sed -i -E "/SECRET_WMATA_API_KEY/s/[0-9a-f]{32}/${{ secrets.WMATA_API_KEY }}/" ${BI_CONFIG_FILE}
- name: Install Arduino Cli
uses: arduino/[email protected]
- name: Install boards and libraries
run: |
arduino-cli core update-index --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json
arduino-cli core install esp8266:esp8266 --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json
arduino-cli lib install ArduinoJson
arduino-cli lib install "Adafruit NeoPixel"
arduino-cli lib install WiFiManager
- name: Compile sketches
run: |
arduino-cli compile --fqbn esp8266:esp8266:nodemcuv2 --export-binaries --output-dir ${COMPILE_OUT_DIR} ./DCTransistor/
arduino-cli compile --fqbn esp8266:esp8266:nodemcuv2 --export-binaries --output-dir ${COMPILE_OUT_DIR} ./DCTransistor-Bidirectional/
- name: Move and GZip binaries
run: |
mv ${COMPILE_OUT_DIR}${COMPILE_OUT_NAME} ${BIN_NAME}
mv ${COMPILE_OUT_DIR}${COMPILE_OUT_BI_NAME} ${BI_BIN_NAME}
gzip -k -f ${BIN_NAME}
gzip -k -f ${BI_BIN_NAME}
- name: Remove WMATA API Key
run: |
sed -i "s/${{ secrets.WMATA_API_KEY }}/0123456789abcdef0123456789abcdef/" ${CONFIG_FILE}
sed -i "s/${{ secrets.WMATA_API_KEY }}/0123456789abcdef0123456789abcdef/" ${BI_CONFIG_FILE}
- name: Commit changes to repo
run: |
if [[ $(git status) != *"nothing to commit, working tree clean"* ]]; then
git config user.email "<>"
git config user.name "Binary Update Bot"
git add .
git commit -m "Update Binaries"
git push origin main
else
echo "No updates!"
fi
- name: Upload Binary Artifacts
uses: actions/upload-artifact@v3
with:
name: Binary Artifact Uploads
path: dctransistor*.bin
- name: Upload GZIP Artifacts
uses: actions/upload-artifact@v3
with:
name: GZIP Artifact Uploads
path: dctransistor*.gz
build-release:
needs: compile-sketches
runs-on: ubuntu-latest
steps:
- name: Download Binary Artifact
uses: actions/[email protected]
with:
name: Binary Artifact Uploads
- name: Download GZIP Artifact
uses: actions/[email protected]
with:
name: GZIP Artifact Uploads
- name: create-release
uses: ncipollo/[email protected]
id: create-release
with:
artifacts: "${{ env.BIN_NAME }},${{ env.BIN_NAME }}.gz,${{ env.BI_BIN_NAME }},${{ env.BI_BIN_NAME }}.gz"
tag: ${{ needs.compile-sketches.outputs.release-version }}
body: "Automated pipeline release of dctransistor binaries"