From d98eb22cf1cea2802297f99d9782a68c8a1baa97 Mon Sep 17 00:00:00 2001 From: arfrie22 <43021241+arfrie22@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:01:43 -0400 Subject: [PATCH 1/3] change to new ci --- .github/workflows/build-ci.yml | 170 +++++++++++++++++++++++++++++ .github/workflows/c-cpp.yml | 17 --- .github/workflows/docker-image.yml | 44 -------- 3 files changed, 170 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/build-ci.yml delete mode 100644 .github/workflows/c-cpp.yml delete mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml new file mode 100644 index 00000000..054d97f4 --- /dev/null +++ b/.github/workflows/build-ci.yml @@ -0,0 +1,170 @@ +# Based heavily on the docker build action from immich (https://github.com/immich-app/immich/) + +name: Docker + +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: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: | + ~/.cache/pip + ~/.platformio/.cache + key: ${{ runner.os }}-pio + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + - name: Install PlatformIO Core + run: pip install --upgrade platformio + + - name: Build PlatformIO Project + run: pio run --environment d1_mini + + - name: Move and rename firmware + run: mv .pio/build/d1_mini/firmware.bin ./firmware_os_esp8266.bin + + - name: Upload firmware + uses: actions/upload-artifact@v4 + with: + name: firmware + path: ./firmware_os_esp8266.bin + build-docker: + name: Build and Push + runs-on: ubuntu-latest + needs: [build-pio, build-ospi] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - 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 || github.repository_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/${{ github.repository_owner }}/mkrcx-build-cache:${{ github.repository }}" >> $GITHUB_OUTPUT + fi + + - name: Build and push image + uses: docker/build-push-action@v5.1.0 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm/v7,linux/arm64 + # Skip pushing when PR from a fork + push: ${{ !github.event.pull_request.head.repo.fork }} + output: type=docker,dest=./output.tar + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/mkrcx-build-cache:${{ github.repository }} + cache-to: ${{ steps.cache-target.outputs.cache-to }} + + - name: Upload image + uses: actions/upload-artifact@v4 + with: + name: docker-image + path: ./output.tar + expire-in: 1h + 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 + + - name: Add firmware to release + uses: softprops/action-gh-release@v2 + with: + files: firmware/* + + release-docker: + name: Release Docker + runs-on: ubuntu-latest + needs: [ build-pio build-docker ] + steps: + - name: Download docker image + uses: actions/download-artifact@v4 + with: + name: docker-image + + - 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 || github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - 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 || github.repository_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/${{ github.repository_owner }}/${{ github.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: Load image + run: docker load -i ./docker-image/output.tar + + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64,linux/arm/v7,linux/arm64 + # Skip pushing when PR from a fork + push: ${{ !github.event.pull_request.head.repo.fork }} + tags: ${{ steps.metadata.outputs.tags }} + labels: ${{ steps.metadata.outputs.labels }} diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml deleted file mode 100644 index c6d4e80a..00000000 --- a/.github/workflows/c-cpp.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: C/C++ CI - -on: - push: - branches: [ "*" ] - pull_request: - branches: [ "*" ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: make - run: sudo apt install -y libmosquittopp-dev && make diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index ea010d7d..00000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Docker Image CI - -on: - push: - branches: [ "*" ] - pull_request: - branches: [ "*" ] - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - build-and-push-image: - runs-on: ubuntu-latest - - permissions: - contents: read - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Log in to the Container registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - - name: Build and push Docker image - uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} From 7129e3972da5423fff2702575eccfbbd360dd760 Mon Sep 17 00:00:00 2001 From: arfrie22 <43021241+arfrie22@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:32:54 -0400 Subject: [PATCH 2/3] fixed build yml --- .github/workflows/build-ci.yml | 170 +++++++++++++++++++-------------- 1 file changed, 100 insertions(+), 70 deletions(-) diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index 054d97f4..8ee42e74 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -1,6 +1,6 @@ # Based heavily on the docker build action from immich (https://github.com/immich-app/immich/) -name: Docker +name: Build CI and Release on: workflow_dispatch: @@ -20,21 +20,23 @@ jobs: name: Build PlatformIO runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/checkout@v4 + - uses: actions/cache@v4 with: path: | ~/.cache/pip ~/.platformio/.cache key: ${{ runner.os }}-pio - - uses: actions/setup-python@v4 - with: - python-version: '3.11' + # - 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: Build PlatformIO Project - run: pio run --environment d1_mini + run: pio run --environment d1_mini - name: Move and rename firmware run: mv .pio/build/d1_mini/firmware.bin ./firmware_os_esp8266.bin @@ -45,9 +47,8 @@ jobs: name: firmware path: ./firmware_os_esp8266.bin build-docker: - name: Build and Push + name: Build Docker runs-on: ubuntu-latest - needs: [build-pio, build-ospi] steps: - name: Checkout uses: actions/checkout@v4 @@ -58,13 +59,24 @@ jobs: - 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 || github.repository_owner }} + username: ${{ env.ACT && github.actor || steps.lower-owner.outputs.owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Determine build cache output @@ -74,31 +86,47 @@ jobs: # 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/${{ github.repository_owner }}/mkrcx-build-cache:${{ github.repository }}" >> $GITHUB_OUTPUT + 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@v5.1.0 + uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile platforms: linux/amd64,linux/arm/v7,linux/arm64 # Skip pushing when PR from a fork - push: ${{ !github.event.pull_request.head.repo.fork }} - output: type=docker,dest=./output.tar - cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/mkrcx-build-cache:${{ github.repository }} + 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: ./output.tar - expire-in: 1h + path: ./image.tar release-pio: name: Release PlatformIO runs-on: ubuntu-latest - needs: [ build-pio build-docker ] + needs: [build-pio, build-docker] if: ${{ github.event_name == 'release' }} steps: - name: Download firmware @@ -115,56 +143,58 @@ jobs: release-docker: name: Release Docker runs-on: ubuntu-latest - needs: [ build-pio build-docker ] + needs: [build-pio, build-docker] + if: ${{ !github.event.pull_request.head.repo.fork }} steps: - - name: Download docker image - uses: actions/download-artifact@v4 - with: - name: docker-image - - - 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 || github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - 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 || github.repository_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/${{ github.repository_owner }}/${{ github.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: Load image - run: docker load -i ./docker-image/output.tar - - - name: Build and push - uses: docker/build-push-action@v6 - with: - platforms: linux/amd64,linux/arm/v7,linux/arm64 - # Skip pushing when PR from a fork - push: ${{ !github.event.pull_request.head.repo.fork }} - tags: ${{ steps.metadata.outputs.tags }} - labels: ${{ steps.metadata.outputs.labels }} + - 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: 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 }} From d8426580fc8b2aeba7d782b3e39ed3b15a90308a Mon Sep 17 00:00:00 2001 From: arfrie22 <43021241+arfrie22@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:07:23 -0400 Subject: [PATCH 3/3] it should not run release on pr --- .github/workflows/build-ci.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index 8ee42e74..ba502a74 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -112,7 +112,6 @@ jobs: context: . file: ./Dockerfile platforms: linux/amd64,linux/arm/v7,linux/arm64 - # Skip pushing when PR from a fork push: false outputs: type=oci,dest=./image.tar cache-from: type=registry,ref=ghcr.io/${{ steps.lower-owner.outputs.owner }}/opensprinkler-build-cache:ospi @@ -144,7 +143,7 @@ jobs: name: Release Docker runs-on: ubuntu-latest needs: [build-pio, build-docker] - if: ${{ !github.event.pull_request.head.repo.fork }} + if: ${{ !github.event.pull_request }} steps: - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -165,8 +164,6 @@ jobs: - 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 }}