Skip to content

Commit

Permalink
Update build workflow: Optimize caching (#46)
Browse files Browse the repository at this point in the history
separate cache save + restore action
  • Loading branch information
Slider0007 authored Jul 1, 2023
1 parent 0e79a93 commit 027b89e
Showing 1 changed file with 87 additions and 89 deletions.
176 changes: 87 additions & 89 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,42 @@ jobs:
with:
submodules: recursive

- name: Set Variables
- name: Set variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Cache PIP & PlatformIO Files
- name: Cache pip & platformIO cache files
uses: actions/cache@v3.3.1
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: platformio-${{ github.run_id }}
restore-keys: platformio # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
restore-keys: platformio # This matches above key as it is only used as a prefix. It restores the nearest cache

- name: Cache PIO Build Files
- name: Cache PIO build files
uses: actions/cache@v3.3.1
with:
path: ./code/.pio/
key: build-${{ github.run_id }}
restore-keys: build # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
restore-keys: build # This matches above key as it is only used as a prefix. It restores the nearest cache

- name: Cache Generated Files
uses: actions/cache@v3.3.1
with:
path: |
./code/sdkconfig.defaults
./code/sdkconfig.esp32cam
./code/.pio/build/esp32cam/firmware.bin
./code/.pio/build/esp32cam/firmware.elf
./code/.pio/build/esp32cam/partitions.bin
./code/.pio/build/esp32cam/bootloader.bin
./html/*
key: generated-files-${{ github.run_id }}
restore-keys: generated-files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache

- name: Setup Python Environment
- name: Setup python environment
uses: actions/setup-python@v4.6.1
with:
python-version: '3.10'

- name: Install PlatformIO Environment
- name: Install PlatformIO environment
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Build Firmware
- name: Build firmware
#run: echo "Testing... ${{ github.ref_name }}, ${{ steps.vars.outputs.sha_short }}" > ./sd-card/html/version.txt; mkdir -p ./code/.pio/build/esp32cam/; cd ./code/.pio/build/esp32cam/; echo "${{ steps.vars.outputs.sha_short }}" > firmware.bin; cp firmware.bin partitions.bin; cp firmware.bin bootloader.bin # Testing
run: cd code; platformio run --environment esp32cam

- name: Prepare WebUI (Generate Parameter Tooltips + Update Hashes)
- name: Prepare WebUI (Generate parameter tooltips + Update hash)
run: |
rm -rf ./html
mkdir html
Expand All @@ -85,7 +71,20 @@ jobs:
echo "Replacing variables..."
cd html; find . -type f -exec sed -i 's/$COMMIT_HASH/${{ steps.vars.outputs.sha_short }}/g' {} \;
- name: Save generated files
uses: actions/cache/save@v3.3.1
with:
path: |
./code/sdkconfig.defaults
./code/sdkconfig.esp32cam
./code/.pio/build/esp32cam/firmware.bin
./code/.pio/build/esp32cam/firmware.elf
./code/.pio/build/esp32cam/partitions.bin
./code/.pio/build/esp32cam/bootloader.bin
./html/*
key: generated-files-${{ github.run_id }}



#########################################################################################
## Pack for OTA-Update
Expand All @@ -103,8 +102,8 @@ jobs:
steps:
- uses: actions/checkout@v3.5.3

- name: Load generated-files cache
uses: actions/cache@v3.3.1
- name: Load generated-files
uses: actions/cache/restore@v3.3.1
with:
path: |
./code/sdkconfig.defaults
Expand All @@ -115,17 +114,9 @@ jobs:
./code/.pio/build/esp32cam/bootloader.bin
./html/*
key: generated-files-${{ github.run_id }}
restore-keys: generated-files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache

- if: startsWith(github.ref, 'refs/tags/')
name: Cache OTA-update Files For Release Creation
uses: actions/cache@v3.3.1
with:
path: update
key: update_files-${{ github.run_id }}
restore-keys: update_files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
restore-keys: generated-files # This matches above key as it is only used as a prefix. It restores the nearest cache

- name: Set Variables
- name: Set variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Expand All @@ -147,12 +138,20 @@ jobs:
cp ./sd-card/config/*.tfl ./update/config/ 2>/dev/null || true
cp ./sd-card/config/*.tflite ./update/config/ 2>/dev/null || true
- name: Upload as update.zip artifact (Firmware + Web UI + CNN)
- name: Upload update.zip artifact (Firmware + Web UI + CNN)
uses: actions/upload-artifact@v3.1.2
with:
name: "AI-on-the-edge-device__update__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
path: ./update

- if: startsWith(github.ref, 'refs/tags/')
name: Save OTA-update package for release creation
uses: actions/cache/save@v3.3.1
with:
path: update
key: update_files-${{ github.run_id }}
restore-keys: update_files # This matches above key as it is only used as a prefix. It restores the nearest cache



#########################################################################################
Expand All @@ -173,8 +172,8 @@ jobs:
steps:
- uses: actions/checkout@v3.5.3

- name: Load generated-files cache
uses: actions/cache@v3.3.1
- name: Load generated-files
uses: actions/cache/restore@v3.3.1
with:
path: |
./code/sdkconfig.defaults
Expand All @@ -185,17 +184,9 @@ jobs:
./code/.pio/build/esp32cam/bootloader.bin
./html/*
key: generated-files-${{ github.run_id }}
restore-keys: generated-files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache

- if: startsWith(github.ref, 'refs/tags/')
name: Cache manual_setup Files For Release Creation
uses: actions/cache@v3.3.1
with:
path: manual_setup
key: manual_setup-${{ github.run_id }}
restore-keys: manual_setup # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
restore-keys: generated-files # This matches above key as it is only used as a prefix. It restores the nearest cache

- name: Set Variables
- name: Set variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Expand All @@ -206,8 +197,6 @@ jobs:
rm -rf manual_setup
mkdir -p manual_setup
rm -rf manual_setup/*.zip
rm -rf manual_setup/debug/
mkdir -p manual_setup/debug/
# copy builds to manual_setup folder
cp -f "./code/.pio/build/esp32cam/firmware.bin" "manual_setup/firmware.bin"
cp -f "./code/.pio/build/esp32cam/bootloader.bin" "manual_setup/bootloader.bin"
Expand All @@ -221,6 +210,14 @@ jobs:
with:
name: "AI-on-the-edge-device__manual-setup__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
path: ./manual_setup

- if: startsWith(github.ref, 'refs/tags/')
name: Save manual_setup package for release creation
uses: actions/cache/save@v3.3.1
with:
path: manual_setup
key: manual_setup-${{ github.run_id }}
restore-keys: manual_setup # This matches above key as it is only used as a prefix. It restores the nearest cache



Expand All @@ -240,8 +237,8 @@ jobs:
steps:
- uses: actions/checkout@v3.5.3

- name: Load generated-files cache
uses: actions/cache@v3.3.1
- name: Load generated-files
uses: actions/cache/restore@v3.3.1
with:
path: |
./code/sdkconfig.defaults
Expand All @@ -252,17 +249,9 @@ jobs:
./code/.pio/build/esp32cam/bootloader.bin
./html/*
key: generated-files-${{ github.run_id }}
restore-keys: generated-files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
restore-keys: generated-files # This matches above key as it is only used as a prefix. It restores the nearest cache

- if: startsWith(github.ref, 'refs/tags/')
name: Cache remote_setup Files For Release Creation
uses: actions/cache@v3.3.1
with:
path: remote_setup
key: remote_setup-${{ github.run_id }}
restore-keys: remote_setup # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache

- name: Set Variables
- name: Set variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Expand All @@ -282,12 +271,20 @@ jobs:
mkdir -p ./remote_setup/config/
cp ./sd-card/config/* ./remote_setup/config/ 2>/dev/null || true
- name: Upload remote_setup as remote_setup.zip artifact (Firmware + Web UI + Config)
- name: Upload remote_setup.zip artifact (Firmware + Web UI + Config)
uses: actions/upload-artifact@v3.1.2
with:
name: "AI-on-the-edge-device__remote-setup__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
path: ./remote_setup

- if: startsWith(github.ref, 'refs/tags/')
name: Save remote_setup package for release creation
uses: actions/cache/save@v3.3.1
with:
path: remote_setup
key: remote_setup-${{ github.run_id }}
restore-keys: remote_setup # This matches above key as it is only used as a prefix. It restores the nearest cache



#########################################################################################
Expand All @@ -305,8 +302,8 @@ jobs:
steps:
- uses: actions/checkout@v3.5.3

- name: Load generated-files cache
uses: actions/cache@v3.3.1
- name: Load generated-files
uses: actions/cache/restore@v3.3.1
with:
path: |
./code/sdkconfig.defaults
Expand All @@ -317,17 +314,9 @@ jobs:
./code/.pio/build/esp32cam/bootloader.bin
./html/*
key: generated-files-${{ github.run_id }}
restore-keys: generated-files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache

- if: startsWith(github.ref, 'refs/tags/')
name: Cache debug-files for release creation
uses: actions/cache@v3.3.1
with:
path: debug
key: debug_files-${{ github.run_id }}
restore-keys: debug_files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
restore-keys: generated-files # This matches above key as it is only used as a prefix. It restores the nearest cache

- name: Set Variables
- name: Set variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Expand All @@ -348,7 +337,15 @@ jobs:
name: "AI-on-the-edge-device__debug-files__${{ steps.vars.outputs.branch }}_(${{ steps.vars.outputs.sha_short }})"
path: ./debug


- if: startsWith(github.ref, 'refs/tags/')
name: Save debug package for release creation
uses: actions/cache/save@v3.3.1
with:
path: debug
key: debug_files-${{ github.run_id }}
restore-keys: debug_files # This matches above key as it is only used as a prefix. It restores the nearest cache



#########################################################################################
## Prepare and create release
Expand All @@ -367,35 +364,36 @@ jobs:
steps:
- uses: actions/checkout@v3.53

- name: Load OTA-update Files
uses: actions/cache@v3.3.1
- name: Load OTA-update files
uses: actions/cache/restore@v3.3.1
with:
path: update
key: update_files-${{ github.run_id }}
restore-keys: update_files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
restore-keys: update_files # This matches above key as it is only used as a prefix. It restores the nearest cache

- name: Load manual_setup Files
uses: actions/cache@v3.2.3
- name: Load manual_setup files
uses: actions/cache/restore@v3.3.1

with:
path: manual_setup
key: manual_setup-${{ github.run_id }}
restore-keys: manual_setup # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
restore-keys: manual_setup # This matches above key as it is only used as a prefix. It restores the nearest cache

- name: Load remote_setup Files
uses: actions/cache@v3.2.3
- name: Load remote_setup files
uses: actions/cache/restore@v3.3.1
with:
path: remote_setup
key: remote_setup-${{ github.run_id }}
restore-keys: remote_setup # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
restore-keys: remote_setup # This matches above key as it is only used as a prefix. It restores the nearest cache

- name: Load debug_files Files
uses: actions/cache@v3.3.1
- name: Load debug files
uses: actions/cache/restore@v3.3.1
with:
path: debug
key: debug_files-${{ github.run_id }}
restore-keys: debug_files # This matches above key as it is only used as a prefix. it the restores the nearest cache, see https://github.com/restore-keys:/blob/main/tips-and-workarounds.md#update-a-cache
restore-keys: debug_files # This matches above key as it is only used as a prefix. It restores the nearest cache

- name: Set Variables
- name: Set variables
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Expand Down

0 comments on commit 027b89e

Please sign in to comment.