github action #15
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: ESP Environment Sensor | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: read | |
id-token: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Install Arduino CLI | |
uses: arduino/setup-arduino-cli@v2 | |
- name: Install platform | |
run: | | |
arduino-cli config init | |
arduino-cli config add board_manager.additional_urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json | |
arduino-cli core update-index | |
arduino-cli core install esp32:esp32 | |
- name: Install Arduino Libraries | |
run: | | |
arduino-cli lib install "ArduinoJson" | |
arduino-cli lib install "Adafruit GFX Library" | |
arduino-cli lib install "Adafruit ST7735 and ST7789 Library" | |
# - name: Compile | |
# uses: arduino/compile-sketches@v1 | |
# with: | |
# fqbn: "esp32:esp32:lolin32" | |
# sketch-paths: | | |
# - ./arduino_projects/esp-environment-sensor/esp-environment-sensor | |
# verbose: true | |
# libraries: | | |
# - name: "ArduinoJson" | |
# - name: "Adafruit GFX Library" | |
# - name: "Adafruit ST7735 and ST7789 Library" | |
- name: Compile Sketch | |
run: | | |
arduino-cli compile --fqbn esp32:esp32:lolin32 --verbose --output-dir output ./arduino_projects/esp-environment-sensor/esp-environment-sensor | |
echo "Compiled firmware location:" | |
find ./arduino_projects/esp-environment-sensor/ -type f | |
find ./ -type f -name "esp-environment-sensor.ino.merged.bin" 2>/dev/null | |
ls output | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
aws-region: ${{ secrets.AWS_REGION }} | |
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.ROLE_NAME }} | |
role-session-name: "github-actions-session" | |
mask-aws-account-id: true | |
- name: Upload Firmware | |
run: | | |
aws s3 cp ./output/esp-environment-sensor.ino.merged.bin s3://${{ secrets.OTA_S3_BUCKET }}/firmware.bin | |
upload: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Create AWS IoT Job | |
run: | | |
JOB_ID="esp32-ota-job-${{ github.run_number }}" | |
aws iot create-job \ | |
--job-id $JOB_ID \ | |
--targets "arn:aws:iot:${{ secrets.AWS_REGION }}:${{ secrets.AWS_ACCOUNT_ID }}:thinggroup/environment-sensors" \ | |
--document-source s3://your-s3-bucket-name/ota-job-document.json \ | |
--job-executions-rollout-config '{"maximumPerMinute":5}' \ | |
--abort-config '{"criteriaList":[{"failureType":"FAILED","action":"CANCEL","thresholdPercentage":50.0,"minNumberOfExecutedThings":1}]}' |