Merge branch 'main' of https://github.com/LArkema/dctransistor-projec… #483
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |