From b351b118e577ab848df23034421fdb505b7f088f Mon Sep 17 00:00:00 2001 From: Tristan Date: Sat, 11 Jan 2025 17:10:39 +0000 Subject: [PATCH] Split out publication to its own workflow --- .github/workflows/ci.yml | 88 +++++++++-------------------------- .github/workflows/publish.yml | 84 +++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 66 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7bc25e..e1b2157 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,8 +9,6 @@ on: env: JAVA_VERSION: "23" - DOCKER_LAYER_CACHE: "/tmp/.buildx-cache" - DOCKER_REGISTRY: "ghcr.io" jobs: set_variables: @@ -68,6 +66,17 @@ jobs: name: "mcw.jar" path: "target/mcw.jar" + publish_hotspot: + needs: [ "set_variables", "build_hotspot" ] + uses: "./.github/workflows/publish.yml" + with: + JAVA_VERSION: "${{ env.JAVA_VERSION }}" + ARTIFACT_NAME: "mcw.jar" + DOCKER_IMAGE: "${{ needs.set_variables.outputs.docker_image }}" + DOCKER_TARGET: "hotspot" + DOCKER_TAG_CANONICAL: "${{ needs.set_variables.outputs.build_version }}-hotspot" + DOCKER_TAG_SHORT: "${{ needs.set_variables.outputs.image_version_short }}" + build_graal: name: "Build (GraalVM)" runs-on: "ubuntu-latest" @@ -94,69 +103,16 @@ jobs: - name: "Archive binary" uses: "actions/upload-artifact@v4" with: - name: "mcw-${{ runner.os }}-${{ runner.arch }}" + name: "mcw-bin" path: "target/mcw" - publish: - name: "Publish" - runs-on: "ubuntu-latest" - needs: [ "set_variables", "build_hotspot", "build_graal" ] - permissions: - contents: "read" - packages: "write" - - strategy: - matrix: - includes: - - artifact: "mcw.jar" - docker_target: "hotspot" - - artifact: "mcw-${{ runner.os }}-${{ runner.arch }}" - docker_target: "graal" - - steps: - - name: "Checkout repository" - uses: "actions/checkout@v4" - - name: "Download artifact" - uses: "actions/download-artifact@v4" - with: - name: "${{ matrix.artifact }}" - path: "${{ github.workspace }}/target" - - name: "Set up QEMU" - uses: "docker/setup-qemu-action@v3" - - name: "Set up Docker Buildx" - uses: "docker/setup-buildx-action@v3" - - name: "Cache Docker layers" - uses: "actions/cache@v4" - with: - path: "${{ env.DOCKER_LAYER_CACHE }}" - key: "${{ runner.os }}-jdk-${{ env.JAVA_VERSION }}-${{ matrix.docker_target }}-${{ github.sha }}" - restore-keys: | - ${{ runner.os }}-jdk-${{ env.JAVA_VERSION }}-${{ matrix.docker_target }}- - - name: "Log in to the Container registry" - uses: "docker/login-action@v3" - with: - registry: "${{ env.DOCKER_REGISTRY }}" - username: "${{ github.actor }}" - password: "${{ secrets.GITHUB_TOKEN }}" - - name: "Extract metadata (tags, labels) for Docker" - id: "meta" - uses: "docker/metadata-action@v5" - with: - images: "${{ needs.set_variables.outputs.docker_image }}" - tags: | - type=raw,event=push,enable=true,value=${{ needs.set_variables.outputs.build_version }}-${{ matrix.docker_target }} - type=raw,event=push,enable={{ is_default_branch }},value=${{ needs.set_variables.outputs.image_version_short }}-${{ matrix.docker_target }} - - name: "Build and push Docker image" - uses: "docker/build-push-action@v5" - with: - context: "." - push: "true" - platforms: "linux/amd64" - provenance: false - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - target: ${{ matrix.docker_target }} - build-args: | - JAVA_VERSION=${{ env.JAVA_VERSION }} - cache-from: type=local,src=${{ env.DOCKER_LAYER_CACHE }} - cache-to: type=local,dest=${{ env.DOCKER_LAYER_CACHE }} + publish_graal: + needs: [ "set_variables", "build_hotspot" ] + uses: "./.github/workflows/publish.yml" + with: + JAVA_VERSION: "${{ env.JAVA_VERSION }}" + ARTIFACT_NAME: "mcw-bin" + DOCKER_IMAGE: "${{ needs.set_variables.outputs.docker_image }}" + DOCKER_TARGET: "graal" + DOCKER_TAG_CANONICAL: "${{ needs.set_variables.outputs.build_version }}-hotspot" + DOCKER_TAG_SHORT: "${{ needs.set_variables.outputs.image_version_short }}" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..f1eb57a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,84 @@ +on: + workflow_call: + inputs: + JAVA_VERSION: + type: string + required: true + ARTIFACT_NAME: + type: string + required: true + DOCKER_IMAGE: + type: string + required: true + DOCKER_TARGET: + type: string + required: true + DOCKER_TAG_CANONICAL: + type: string + required: true + DOCKER_TAG_SHORT: + type: string + required: true + +name: "Publish (${{ inputs.DOCKER_TARGET }})" + +concurrency: + group: "${{ inputs.DOCKER_TAG_CANONICAL }}-${{ inputs.DOCKER_TARGET }}" + +env: + DOCKER_LAYER_CACHE: "/tmp/.buildx-cache" + DOCKER_REGISTRY: "ghcr.io" + +jobs: + docker: + runs-on: "ubuntu-latest" + permissions: + contents: "read" + packages: "write" + steps: + - name: "Checkout repository" + uses: "actions/checkout@v4" + - name: "Download artifact" + uses: "actions/download-artifact@v4" + with: + name: "${{ inputs.ARTIFACT_NAME }}" + path: "${{ github.workspace }}/target" + - name: "Set up QEMU" + uses: "docker/setup-qemu-action@v3" + - name: "Set up Docker Buildx" + uses: "docker/setup-buildx-action@v3" + - name: "Cache Docker layers" + uses: "actions/cache@v4" + with: + path: "${{ env.DOCKER_LAYER_CACHE }}" + key: "${{ runner.os }}-${{ inputs.DOCKER_TARGET }}-${{ github.sha }}" + restore-keys: | + ${{ runner.os }}-${{ inputs.DOCKER_TARGET }}- + - name: "Log in to the Container registry" + uses: "docker/login-action@v3" + with: + registry: "${{ env.DOCKER_REGISTRY }}" + username: "${{ github.actor }}" + password: "${{ secrets.GITHUB_TOKEN }}" + - name: "Extract metadata (tags, labels) for Docker" + id: "meta" + uses: "docker/metadata-action@v5" + with: + images: "${{ inputs.DOCKER_IMAGE }}" + tags: | + type=raw,event=push,enable=true,value=${{ inputs.DOCKER_TAG_CANONICAL }} + type=raw,event=push,enable={{ is_default_branch }},value=${{ inputs.DOCKER_TAG_SHORT }} + - name: "Build and push Docker image" + uses: "docker/build-push-action@v5" + with: + context: "." + push: "true" + platforms: "linux/amd64" + provenance: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + target: "${{ inputs.DOCKER_TARGET }}" + build-args: | + JAVA_VERSION=${{ inputs.JAVA_VERSION }} + cache-from: "type=local,src=${{ env.DOCKER_LAYER_CACHE }}" + cache-to: "type=local,dest=${{ env.DOCKER_LAYER_CACHE }}"