diff --git a/.github/workflows/build-test-docker.yml b/.github/workflows/build-test-docker.yml index 50a0098..d79efc9 100644 --- a/.github/workflows/build-test-docker.yml +++ b/.github/workflows/build-test-docker.yml @@ -6,6 +6,25 @@ on: image-tag: type: string required: true + platform: + type: string + required: false + default: "linux/amd64" + image-name: + type: string + required: true + cache-from: + type: string + required: false + default: "" + cache-to: + type: string + required: false + default: "" + setup-qemu: + type: string + required: false + default: "false" jobs: test-docker-build: @@ -14,17 +33,7 @@ jobs: permissions: contents: read packages: read - strategy: - matrix: - include: - - arch: amd64 - platform: linux/amd64 - image-name: build-amd64 - needs-qemu: false - - arch: arm64 - platform: linux/arm64 - image-name: build-arm64 - needs-qemu: true + steps: - name: Check out the repo uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -43,11 +52,12 @@ jobs: file: ./Dockerfile push: false load: true - platforms: ${{ matrix.platform }} - cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-${{ matrix.arch }} - image-name: ${{ matrix.image-name }} - setup-qemu: ${{ matrix.needs-qemu }} + platforms: ${{ inputs.platform }} + cache-from: ${{ inputs.cache-from }} + cache-to: ${{ inputs.cache-to }} + image-name: ${{ inputs.image-name }} + setup-qemu: ${{ inputs.setup-qemu }} - name: Test run: | - docker run --platform ${{ matrix.platform }} --rm ${{ matrix.image-name }}:${{ inputs.image-tag }} --version + docker run --platform ${{ inputs.platform }} --rm ${{ inputs.image-name }}:${{ inputs.image-tag }} --version diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index dd2455f..181f3aa 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,8 +14,29 @@ jobs: build_and_test_docker: uses: ./.github/workflows/build-test-docker.yml + strategy: + matrix: + include: + - platform: linux/amd64 + cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64 + cache-to: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64 + image-name: build-amd64 + setup-qemu: false + - platform: linux/arm64 + cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64 + cache-to: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64 + image-name: build-arm64 + setup-qemu: true + with: - image-tag: latest + image-tag: "pr-${{ github.event.pull_request.number }}" + platform: ${{ matrix.platform }} + cache-from: ${{ matrix.cache-from }} + cache-to: ${{ matrix.cache-to }} + image-name: ${{ matrix.image-name }} + setup-qemu: ${{ matrix.setup-qemu }} + + secrets: inherit publish_to_pypi: name: Publish to PyPI @@ -77,22 +98,6 @@ jobs: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64 type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64 - - name: Delete old cache entries - env: - GH_TOKEN: ${{ github.token }} - run: | - # Get all versions of the container package - versions=$(gh api "orgs/elementsinteractive/packages/container/twyn/versions" --paginate) - - # Extract version IDs that do NOT have any buildcache-* tags (buildcache-amd64, buildcache-arm64, etc.) - ids_to_delete=$(echo "$versions" | jq -r '.[] | select(.metadata.container.tags | map(test("^buildcache-")) | any | not) | .id') - - # Delete them - for id in $ids_to_delete; do - echo "Deleting old cache version ID: $id" - gh api -X DELETE "orgs/elementsinteractive/packages/container/twyn/versions/$id" - done - release_notes: runs-on: ubuntu-latest needs: [publish_to_pypi, publish_to_dockerhub] diff --git a/.github/workflows/trigger-test-docker-build.yml b/.github/workflows/trigger-test-docker-build.yml index c7e4e73..55dbaf8 100644 --- a/.github/workflows/trigger-test-docker-build.yml +++ b/.github/workflows/trigger-test-docker-build.yml @@ -37,5 +37,26 @@ jobs: name: Trigger test Docker build if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true') uses: ./.github/workflows/build-test-docker.yml + strategy: + matrix: + include: + - platform: linux/amd64 + cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-amd64 + cache-to: "" + image-name: build-amd64 + setup-qemu: false + - platform: linux/arm64 + cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-arm64 + cache-to: "" + image-name: build-arm64 + setup-qemu: true + with: image-tag: "pr-${{ github.event.pull_request.number }}" + platform: ${{ matrix.platform }} + cache-from: ${{ matrix.cache-from }} + cache-to: ${{ matrix.cache-to }} + image-name: ${{ matrix.image-name }} + setup-qemu: ${{ matrix.setup-qemu }} + + secrets: inherit