Skip to content

Commit

Permalink
Split out publication to its own workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan971 committed Jan 11, 2025
1 parent 2d95df9 commit b351b11
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 66 deletions.
88 changes: 22 additions & 66 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ on:

env:
JAVA_VERSION: "23"
DOCKER_LAYER_CACHE: "/tmp/.buildx-cache"
DOCKER_REGISTRY: "ghcr.io"

jobs:
set_variables:
Expand Down Expand Up @@ -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"
Expand All @@ -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 }}"
84 changes: 84 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}"

0 comments on commit b351b11

Please sign in to comment.