Aj/docs (#143) #29
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: Build and Upload to S3 | |
on: | |
push: | |
branches: | |
- master | |
- release | |
- aj/development | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
check_changes: | |
runs-on: ubuntu-latest | |
outputs: | |
software_changed: ${{ steps.check_software.outputs.changed }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Check for Software directory changes | |
id: check_software | |
run: | | |
git diff --name-only HEAD^ HEAD > changes.txt | |
echo "changed=$(grep -q "^Software/" changes.txt && echo 'true' || echo 'false')" >> "$GITHUB_OUTPUT" | |
build: | |
needs: check_changes | |
if: needs.check_changes.outputs.software_changed == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set Build Env based on Branch | |
id: set_filename | |
run: | | |
if [ "${{ github.ref_name }}" = "release" ]; then | |
echo "build_env=production" >> "$GITHUB_ENV" | |
echo "bubble_version=live" >> "$GITHUB_ENV" | |
elif [ "${{ github.ref_name }}" = "master" ]; then | |
echo "build_env=production" >> "$GITHUB_ENV" | |
echo "bubble_version=live" >> "$GITHUB_ENV" | |
else | |
echo "build_env=development" >> "$GITHUB_ENV" | |
echo "bubble_version=test" >> "$GITHUB_ENV" | |
fi | |
- name: Increment Build Number | |
if: github.ref_name == 'master' || github.ref_name == 'release' | |
run: | | |
response=$( | |
curl --location --request POST 'https://app.researchanddesire.com/version-${{ env.bubble_version }}/api/1.1/wf/increment-sw-version-ossm' \ | |
--header 'Content-Type: application/json' \ | |
--header 'Authorization: Bearer ${{ secrets.BUBBLE_API_KEY }}') | |
echo "SW_VERSION=$response" >> $GITHUB_ENV | |
echo "SW_VERSION=$response" | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Install PlatformIO Core | |
run: pip install --upgrade platformio | |
- name: Build PlatformIO Project | |
run: | | |
cd Software | |
export SW_VERSION="${{ env.SW_VERSION }}" && pio run -e ${{ env.build_env }} | |
- name: Upload Build Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: firmware-artifact # Ensure this name is unique and correctly referenced | |
path: ./Software/.pio/build/${{ env.build_env }}/firmware.bin | |
- name: Cleanup on failure | |
if: failure() && (github.ref_name == 'master' || github.ref_name == 'release') | |
run: | | |
curl --location --request POST 'https://app.researchanddesire.com/version-${{ env.bubble_version }}/api/1.1/wf/decrement-sw-version-ossm' \ | |
--header 'Content-Type: application/json' \ | |
--header 'Authorization: Bearer ${{ secrets.BUBBLE_API_KEY }}' | |
upload: | |
needs: [check_changes, build] | |
if: needs.check_changes.outputs.software_changed == 'true' | |
runs-on: ubuntu-latest | |
outputs: | |
firmware_filename: ${{ steps.set_filename.outputs.firmware_filename }} | |
steps: | |
- name: Download Build Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: firmware-artifact | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Set Filename based on Branch | |
id: set_filename | |
run: | | |
if [ "${{ github.ref_name }}" = "release" ]; then | |
echo "firmware_filename=firmware.bin" >> "$GITHUB_ENV" | |
elif [ "${{ github.ref_name }}" = "master" ]; then | |
echo "firmware_filename=firmware.bin" >> "$GITHUB_ENV" | |
else | |
echo "firmware_filename=firmware-alpha.bin" >> "$GITHUB_ENV" | |
fi | |
- name: Upload Binary to S3 | |
run: aws s3 cp ./firmware.bin s3://${{ secrets.AWS_S3_BUCKET_NAME }}/$firmware_filename --acl public-read | |
pass_check: | |
needs: check_changes | |
if: needs.check_changes.outputs.software_changed == 'false' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Skip build | |
run: echo "No changes in Software directory, skipping build" |