Skip to content

Bump actions/configure-pages from 3 to 4 (#101) #55

Bump actions/configure-pages from 3 to 4 (#101)

Bump actions/configure-pages from 3 to 4 (#101) #55

on:
push:
branches:
- "master"
pull_request:
branches:
- "master"
workflow_dispatch:
jobs:
get-envs:
name: Get environments
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install PlatformIO
run: pip install platformio
- name: Get default environments
id: envs
run: |
json=$(pio project config --json-output)
echo "environments=$( echo $json | jq -cr '[.. | arrays | select(.[0] | tostring | startswith("env:")) | .[0][4:]] | unique' )" >> $GITHUB_OUTPUT
echo "web_flasher_names=$( echo $json | jq -cr '[.. | arrays | select(.[0] == "custom_web_flasher_name") | .[1]] | unique' )" >> $GITHUB_OUTPUT
echo "tag=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/tags" | jq -r '.[0].name')" >> $GITHUB_OUTPUT
outputs:
environments: ${{ steps.envs.outputs.environments }}
web_flasher_names: ${{ steps.envs.outputs.web_flasher_names}}
tag: ${{ steps.envs.outputs.tag}}
build-binaries:
name: build ${{ matrix.environment }}
needs: get-envs
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
environment: ${{ fromJSON(needs.get-envs.outputs.environments) }}
steps:
- uses: actions/checkout@v4
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip
- name: Cache PlatformIO
uses: actions/cache@v3
with:
path: |
~/.platformio
./pio
key: ${{ runner.os }}-pio-${{ matrix.environment }}-${{ hashFiles('**/platformio.ini') }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install PlatformIO
run: pip install -r requirements.txt
- name: Build firmware
env:
PUBLISH: true
VERSION: ${{ needs.get-envs.outputs.tag }}
PLATFORMIO_BUILD_FLAGS: -DVERSION='"${{ needs.get-envs.outputs.tag }}"'
run: pio run -e ${{ matrix.environment }}
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.environment }}
path: publish/${{ matrix.environment }}
build-gh-pages:
name: Build gh pages
needs: [ get-envs, build-binaries ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: List environments for gh-pages
working-directory: ./gh-pages
run: |
mkdir -p ./_data
mkdir -p ./_site
echo '${{ needs.get-envs.outputs.web_flasher_names }}' | jq '[.[] | {name: ., path: ("publish/" + sub("(\\s)"; "_"; "g") + "_manifest.json")}]' > ./_data/manifests.json
- uses: actions/configure-pages@v4
- uses: actions/jekyll-build-pages@v1
with:
source: ./gh-pages
destination: ./gh-pages/_site
- uses: actions/download-artifact@v3
with:
path: ./gh-pages/_site/publish
- name: merge manifests
working-directory: ./gh-pages
run: |
echo "$(echo '${{ needs.get-envs.outputs.web_flasher_names }}' | jq -r '.[]')" | while read -r name; do
sanitized_name=$(echo \"$name\" | jq -r 'sub("(\\s)"; "_"; "g")')
jq -s --arg name "$name" '[.[] | select(.name == $name)] | (.[0] | with_entries(select(.key != "builds"))) + {builds: map(.builds) | add}' ./_site/publish/*/manifest.json > ./_site/publish/${sanitized_name}_manifest.json
done
- uses: actions/upload-pages-artifact@v2
with:
path: ./gh-pages/_site
deploy:
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
runs-on: ubuntu-latest
needs: build-gh-pages
permissions:
pages: write
id-token: write
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v3
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}