From 8f1dec274c55834cae69e76e47c814e6321be927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20K=C3=BCffner?= <11882946+mkuf@users.noreply.github.com> Date: Sun, 3 Mar 2024 18:45:22 +0100 Subject: [PATCH] Rework GitHub workflows (#119) * ci: add build action for PRs * ci: use matrix job for build and review * ci: use matrix job for dockerhub description --- .../actions/image-build-common/action.yaml | 37 +++++++++++ .../workflows/image-build-and-publish.yaml | 35 ++++++++++ .github/workflows/image-build-klipper.yaml | 13 ---- .../workflows/image-build-klipperscreen.yaml | 13 ---- .github/workflows/image-build-moonraker.yaml | 13 ---- .github/workflows/image-build-review.yaml | 56 ++++++++++++++++ .github/workflows/image-build-ustreamer.yaml | 13 ---- .github/workflows/image-docs-klipper.yaml | 18 ----- .../workflows/image-docs-klipperscreen.yaml | 18 ----- .github/workflows/image-docs-moonraker.yaml | 18 ----- .github/workflows/image-docs-publish.yaml | 50 ++++++++++++++ .github/workflows/image-docs-ustreamer.yaml | 18 ----- .../template-image-build-workflow.yaml | 66 ------------------- .../template-image-docs-workflow.yaml | 32 --------- 14 files changed, 178 insertions(+), 222 deletions(-) create mode 100644 .github/actions/image-build-common/action.yaml create mode 100644 .github/workflows/image-build-and-publish.yaml delete mode 100644 .github/workflows/image-build-klipper.yaml delete mode 100644 .github/workflows/image-build-klipperscreen.yaml delete mode 100644 .github/workflows/image-build-moonraker.yaml create mode 100644 .github/workflows/image-build-review.yaml delete mode 100644 .github/workflows/image-build-ustreamer.yaml delete mode 100644 .github/workflows/image-docs-klipper.yaml delete mode 100644 .github/workflows/image-docs-klipperscreen.yaml delete mode 100644 .github/workflows/image-docs-moonraker.yaml create mode 100644 .github/workflows/image-docs-publish.yaml delete mode 100644 .github/workflows/image-docs-ustreamer.yaml delete mode 100644 .github/workflows/template-image-build-workflow.yaml delete mode 100644 .github/workflows/template-image-docs-workflow.yaml diff --git a/.github/actions/image-build-common/action.yaml b/.github/actions/image-build-common/action.yaml new file mode 100644 index 0000000..e5ce84d --- /dev/null +++ b/.github/actions/image-build-common/action.yaml @@ -0,0 +1,37 @@ +name: "image-build-common" +description: "Common runner setup to build Container Images for prind" + +runs: + using: "composite" + steps: + - name: "[misc] Clean Runner" + shell: bash + run: | + set -x + ## Remove files + to_delete=( + "/swapfile" + "/usr/local/share/boost" + "$AGENT_TOOLSDIRECTORY" + "/usr/share/dotnet" + "$ANDROID_SDK_ROOT" + "/usr/local/lib/android" + "$ANDROID_SDK_ROOT" + "/usr/share/swift" + ) + for f in ${to_delete[@]}; do + sudo rm -rf ${f} || true + done + + ## Clean docker + docker system prune --all --volumes --force + + - name: "[docker] set up qemu" + uses: docker/setup-qemu-action@v2.2.0 + + - name: "[docker] set up buildx" + uses: docker/setup-buildx-action@v2.7.0 + + - name: "[prind] install requirements" + shell: bash + run: pip install -r scripts/build/requirements.txt diff --git a/.github/workflows/image-build-and-publish.yaml b/.github/workflows/image-build-and-publish.yaml new file mode 100644 index 0000000..f21c1d9 --- /dev/null +++ b/.github/workflows/image-build-and-publish.yaml @@ -0,0 +1,35 @@ +name: 'Build and Publish Images' +on: + workflow_dispatch: + schedule: + - cron: '0 2 * * *' +jobs: + build: + strategy: + matrix: + app: + - klipper + - klipperscreen + - moonraker + - ustreamer + runs-on: ubuntu-latest + steps: + - name: "[prind] checkout" + uses: actions/checkout@v3 + - name: "[prind] set up build environment" + uses: ./.github/actions/image-build-common + - name: "[docker] login" + uses: docker/login-action@v2.2.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: "[prind] build" + run: | + python3 scripts/build/build.py ${{ matrix.app }} \ + --backfill 3 \ + --platform linux/amd64 \ + --platform linux/arm/v6 \ + --platform linux/arm/v7 \ + --platform linux/arm64/v8 \ + --registry docker.io/${{ secrets.DOCKERHUB_USERNAME }} \ + --push diff --git a/.github/workflows/image-build-klipper.yaml b/.github/workflows/image-build-klipper.yaml deleted file mode 100644 index 646ff32..0000000 --- a/.github/workflows/image-build-klipper.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: 'Image: Klipper' -on: - workflow_dispatch: - schedule: - - cron: '0 2 * * *' -jobs: - build: - uses: ./.github/workflows/template-image-build-workflow.yaml - with: - app: klipper - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/image-build-klipperscreen.yaml b/.github/workflows/image-build-klipperscreen.yaml deleted file mode 100644 index d3a8636..0000000 --- a/.github/workflows/image-build-klipperscreen.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: 'Image: KlipperScreen' -on: - workflow_dispatch: - schedule: - - cron: '0 2 * * *' -jobs: - build: - uses: ./.github/workflows/template-image-build-workflow.yaml - with: - app: klipperscreen - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/image-build-moonraker.yaml b/.github/workflows/image-build-moonraker.yaml deleted file mode 100644 index 14685e8..0000000 --- a/.github/workflows/image-build-moonraker.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: 'Image: Moonraker' -on: - workflow_dispatch: - schedule: - - cron: '0 2 * * *' -jobs: - build: - uses: ./.github/workflows/template-image-build-workflow.yaml - with: - app: moonraker - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/image-build-review.yaml b/.github/workflows/image-build-review.yaml new file mode 100644 index 0000000..87f219f --- /dev/null +++ b/.github/workflows/image-build-review.yaml @@ -0,0 +1,56 @@ +name: 'Build Images for Review' +on: + pull_request: + paths: + - .github/workflows/image-build-review.yaml + - scripts/build/* + - docker/* + +jobs: + changes: + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + apps: ${{ steps.filter.outputs.changes }} + steps: + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + klipper: + - .github/workflows/image-build-review.yaml + - scripts/build/** + - docker/klipper/** + klipperscreen: + - .github/workflows/image-build-review.yaml + - scripts/build/** + - docker/klipperscreen/** + moonraker: + - .github/workflows/image-build-review.yaml + - scripts/build/** + - docker/moonraker/** + ustreamer: + - .github/workflows/image-build-review.yaml + - scripts/build/** + - docker/ustreamer/** + build: + needs: changes + strategy: + matrix: + app: ${{ fromJSON(needs.changes.outputs.apps) }} + runs-on: ubuntu-latest + steps: + - name: "[prind] checkout" + uses: actions/checkout@v3 + - name: "[prind] set up build environment" + uses: ./.github/actions/image-build-common + - name: "[prind] build" + run: | + python3 scripts/build/build.py ${{ matrix.app }} \ + --backfill 0 \ + --platform linux/amd64 \ + --platform linux/arm/v6 \ + --platform linux/arm/v7 \ + --platform linux/arm64/v8 \ + --force diff --git a/.github/workflows/image-build-ustreamer.yaml b/.github/workflows/image-build-ustreamer.yaml deleted file mode 100644 index 5c46b4b..0000000 --- a/.github/workflows/image-build-ustreamer.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: 'Image: Ustreamer' -on: - workflow_dispatch: - schedule: - - cron: '0 2 * * *' -jobs: - build: - uses: ./.github/workflows/template-image-build-workflow.yaml - with: - app: ustreamer - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/image-docs-klipper.yaml b/.github/workflows/image-docs-klipper.yaml deleted file mode 100644 index a961424..0000000 --- a/.github/workflows/image-docs-klipper.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: 'Docs: Klipper' -on: - push: - branches: - - main - paths: - - .github/workflows/template-image-docs-workflow.yaml - - docker/klipper/README.md - -jobs: - docs: - uses: ./.github/workflows/template-image-docs-workflow.yaml - with: - app: klipper - short-description: "Klipper is a 3d-Printer firmware." - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/image-docs-klipperscreen.yaml b/.github/workflows/image-docs-klipperscreen.yaml deleted file mode 100644 index 86ca904..0000000 --- a/.github/workflows/image-docs-klipperscreen.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: 'Docs: KlipperScreen' -on: - push: - branches: - - main - paths: - - .github/workflows/template-image-docs-workflow.yaml - - docker/klipperscreen/README.md - -jobs: - docs: - uses: ./.github/workflows/template-image-docs-workflow.yaml - with: - app: klipperscreen - short-description: "KlipperScreen is a touchscreen GUI that interfaces with Klipper via Moonraker." - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/image-docs-moonraker.yaml b/.github/workflows/image-docs-moonraker.yaml deleted file mode 100644 index 8c995da..0000000 --- a/.github/workflows/image-docs-moonraker.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: 'Docs: Moonraker' -on: - push: - branches: - - main - paths: - - .github/workflows/template-image-docs-workflow.yaml - - docker/moonraker/README.md - -jobs: - docs: - uses: ./.github/workflows/template-image-docs-workflow.yaml - with: - app: moonraker - short-description: "Web API used to interact with the 3D printing firmware Klipper." - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/image-docs-publish.yaml b/.github/workflows/image-docs-publish.yaml new file mode 100644 index 0000000..0f1fdc4 --- /dev/null +++ b/.github/workflows/image-docs-publish.yaml @@ -0,0 +1,50 @@ +name: "Update Image Description at Dockerhub" + +on: + push: + branches: + - main + paths: + - .github/workflows/image-docs-publish.yaml + - docker/**/README.md + +jobs: + changes: + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + apps: ${{ steps.filter.outputs.changes }} + steps: + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + klipper: + - .github/workflows/image-docs-publish.yaml + - docker/klipper/README.md + klipperscreen: + - .github/workflows/image-docs-publish.yaml + - docker/klipperscreen/README.md + moonraker: + - .github/workflows/image-docs-publish.yaml + - docker/moonraker/README.md + ustreamer: + - .github/workflows/image-docs-publish.yaml + - docker/moonraker/README.md + dockerhub-description: + needs: changes + strategy: + matrix: + app: ${{ fromJSON(needs.changes.outputs.apps) }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: "Update Docker Hub Description" + uses: peter-evans/dockerhub-description@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + repository: ${{ secrets.DOCKERHUB_USERNAME }}/${{ matrix.app }} + readme-filepath: ./docker/${{ matrix.app }}/README.md + enable-url-completion: true diff --git a/.github/workflows/image-docs-ustreamer.yaml b/.github/workflows/image-docs-ustreamer.yaml deleted file mode 100644 index 90d7d89..0000000 --- a/.github/workflows/image-docs-ustreamer.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: 'Docs: Ustreamer' -on: - push: - branches: - - main - paths: - - .github/workflows/template-image-docs-workflow.yaml - - docker/ustreamer/README.md - -jobs: - docs: - uses: ./.github/workflows/template-image-docs-workflow.yaml - with: - app: ustreamer - short-description: "µStreamer is a lightweight and very quick server to stream MJPEG video" - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/template-image-build-workflow.yaml b/.github/workflows/template-image-build-workflow.yaml deleted file mode 100644 index 37da0f5..0000000 --- a/.github/workflows/template-image-build-workflow.yaml +++ /dev/null @@ -1,66 +0,0 @@ -name: "Template: image-build-workflow" -on: - workflow_call: - inputs: - app: - required: true - type: string - description: 'app image to build' - secrets: - DOCKERHUB_USERNAME: - required: true - DOCKERHUB_TOKEN: - required: true - -jobs: - build-images: - runs-on: ubuntu-latest - steps: - - name: Clean Runner - run: | - set -x - ## Remove files - to_delete=( - "/swapfile" - "/usr/local/share/boost" - "$AGENT_TOOLSDIRECTORY" - "/usr/share/dotnet" - "$ANDROID_SDK_ROOT" - "/usr/local/lib/android" - "$ANDROID_SDK_ROOT" - "/usr/share/swift" - ) - for f in ${to_delete[@]}; do - sudo rm -rf ${f} || true - done - - ## Clean docker - docker system prune --all --volumes --force - - - name: Checkout - uses: actions/checkout@v3.5.3 - - - name: Docker Setup QEMU - uses: docker/setup-qemu-action@v2.2.0 - - - name: Docker Setup Buildx - uses: docker/setup-buildx-action@v2.7.0 - - - name: Docker Login - uses: docker/login-action@v2.2.0 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Install Build requirements - run: pip install -r scripts/build/requirements.txt - - name: Run Build Script - run: | - python3 scripts/build/build.py ${{ inputs.app }} \ - --backfill 3 \ - --platform linux/amd64 \ - --platform linux/arm/v6 \ - --platform linux/arm/v7 \ - --platform linux/arm64/v8 \ - --registry docker.io/${GITHUB_REPOSITORY_OWNER} \ - --push diff --git a/.github/workflows/template-image-docs-workflow.yaml b/.github/workflows/template-image-docs-workflow.yaml deleted file mode 100644 index e5c11fe..0000000 --- a/.github/workflows/template-image-docs-workflow.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: "Template: image-docs-workflow" -on: - workflow_call: - inputs: - app: - required: true - type: string - description: 'app image to build' - short-description: - required: true - type: string - description: 'Docker Hub repository short description' - secrets: - DOCKERHUB_USERNAME: - required: true - DOCKERHUB_TOKEN: - required: true - -jobs: - image-docs: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: "Update Docker Hub Description" - uses: peter-evans/dockerhub-description@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - repository: ${{ secrets.DOCKERHUB_USERNAME }}/${{ inputs.app }} - short-description: ${{ inputs.short-description }} - readme-filepath: ./docker/${{ inputs.app }}/README.md - enable-url-completion: true