Analog rewrite #215
This file contains hidden or 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
| # Based heavily on the docker build action from immich (https://github.com/immich-app/immich/) | |
| name: Build CI and Release | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [master] | |
| pull_request: | |
| branches: [master] | |
| release: | |
| types: [published] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build-pio: | |
| name: Build PlatformIO | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/pip | |
| ~/.platformio/.cache | |
| key: ${{ runner.os }}-pio | |
| # - uses: actions/setup-python@v5 | |
| # with: | |
| # python-version: '3.13' | |
| - name: Install python | |
| run: sudo apt-get install python3 python3-pip | |
| - name: Install PlatformIO Core | |
| run: pip install --upgrade platformio | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' # Or any recent LTS version | |
| - name: Install html-minifier-terser | |
| run: npm install html-minifier-terser | |
| - name: Build PlatformIO Project | |
| run: pio run --environment os3x_esp8266 | |
| - name: Move and rename firmware | |
| run: mv .pio/build/os3x_esp8266/firmware.bin ./firmware_os_esp8266.bin | |
| - name: Upload firmware | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: firmware | |
| path: ./firmware_os_esp8266.bin | |
| build-demo: | |
| name: Build Demo | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Build Script | |
| run: sudo ./build.sh -s demo | |
| - name: Build Script | |
| run: sudo ./build.sh -s demo | |
| build-docker: | |
| name: Build Docker | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - id: lower-repo | |
| name: Repository to lowercase | |
| run: | | |
| REPO=${{ github.event.repository.name }} | |
| echo "repository=${REPO@L}" >> $GITHUB_OUTPUT | |
| - id: lower-owner | |
| name: Owner to lowercase | |
| run: | | |
| echo "owner=${GITHUB_REPOSITORY_OWNER@L}" >> $GITHUB_OUTPUT | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| # Skip when PR from a fork | |
| if: ${{ !github.event.pull_request.head.repo.fork }} | |
| with: | |
| registry: ghcr.io | |
| username: ${{ env.ACT && github.actor || steps.lower-owner.outputs.owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Determine build cache output | |
| id: cache-target | |
| run: | | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| # Essentially just ignore the cache output (PR can't write to registry cache) | |
| echo "cache-to=type=local,dest=/tmp/discard,ignore-error=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "cache-to=type=registry,mode=max,ref=ghcr.io/${{ steps.lower-owner.outputs.owner }}/opensprinkler-build-cache:ospi" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Generate docker image tags | |
| id: metadata | |
| uses: docker/metadata-action@v5 | |
| with: | |
| flavor: | | |
| latest=auto | |
| images: | | |
| name=ghcr.io/${{ steps.lower-owner.outputs.owner }}/${{ steps.lower-repo.outputs.repository }} | |
| tags: | | |
| # Tag with branch name | |
| type=ref,event=branch | |
| # Tag with pr-number | |
| type=ref,event=pr | |
| # Tag with git tag on release | |
| type=ref,event=tag | |
| type=raw,value=release,enable=${{ github.event_name == 'release' }} | |
| - name: Build and push image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| platforms: ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm/v7,linux/arm64' }} | |
| push: false | |
| outputs: type=oci,dest=./image.tar | |
| cache-from: type=registry,ref=ghcr.io/${{ steps.lower-owner.outputs.owner }}/opensprinkler-build-cache:ospi | |
| cache-to: ${{ steps.cache-target.outputs.cache-to }} | |
| - name: Upload image | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: docker-image | |
| path: ./image.tar | |
| release-pio: | |
| name: Release PlatformIO | |
| runs-on: ubuntu-latest | |
| needs: [build-pio, build-docker] | |
| if: ${{ github.event_name == 'release' }} | |
| steps: | |
| - name: Download firmware | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: firmware | |
| path: ./firmware | |
| release-docker: | |
| name: Release Docker | |
| runs-on: ubuntu-latest | |
| needs: [build-pio, build-docker] | |
| if: ${{ !github.event.pull_request }} | |
| steps: | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - id: lower-repo | |
| name: Repository to lowercase | |
| run: | | |
| REPO=${{ github.event.repository.name }} | |
| echo "repository=${REPO@L}" >> $GITHUB_OUTPUT | |
| - id: lower-owner | |
| name: Owner to lowercase | |
| run: | | |
| echo "owner=${GITHUB_REPOSITORY_OWNER@L}" >> $GITHUB_OUTPUT | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ env.ACT && github.actor || steps.lower-owner.outputs.owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Generate docker image tags | |
| id: metadata | |
| uses: docker/metadata-action@v5 | |
| with: | |
| flavor: | | |
| latest=auto | |
| images: | | |
| name=ghcr.io/${{ steps.lower-owner.outputs.owner }}/${{ steps.lower-repo.outputs.repository }} | |
| tags: | | |
| # Tag with branch name | |
| type=ref,event=branch | |
| # Tag with pr-number | |
| type=ref,event=pr | |
| # Tag with git tag on release | |
| type=ref,event=tag | |
| type=raw,value=release,enable=${{ github.event_name == 'release' }} | |
| - name: Push image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| platforms: linux/amd64,linux/arm/v7,linux/arm64 | |
| # Skip pushing when PR from a fork | |
| push: true | |
| cache-from: type=registry,ref=ghcr.io/${{ steps.lower-owner.outputs.owner }}/opensprinkler-build-cache:ospi | |
| tags: ${{ steps.metadata.outputs.tags }} | |
| labels: ${{ steps.metadata.outputs.labels }} |