Skip to content

Commit

Permalink
use child workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Jan 21, 2025
1 parent 85131a6 commit fc03daa
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 41 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/_build-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
on:
workflow_call:
inputs:
runner:
required: true
type: string
arch:
required: true
type: string
dotnet_variant:
required: true
type: string
dotnet_versions:
required: true
type: string
docker_distros:
required: true
type: string
env:
DOTNET_INSTALL_DIR: "./.dotnet"
DOTNET_ROLL_FORWARD: "Major"

jobs:
build_images:
name: ${{ matrix.docker_distro }} - net${{ matrix.dotnet_version }}
env:
PUSH_IMAGES: ${{ github.event_name != 'pull_request' && github.repository_owner == 'GitTools' }}
runs-on: ${{ inputs.runner }}
strategy:
fail-fast: false
matrix:
dotnet_version: ${{ fromJson(inputs.dotnet_versions) }}
docker_distro: ${{ fromJson(inputs.docker_distros) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Use cached cake frosting
id: cache-cake
uses: actions/cache@v4
with:
path: run
key: run-${{ runner.os }}-${{ hashFiles('./build/**') }}
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
global-json-file: build/global.json
- name: Set up Docker
uses: ./.github/actions/docker-setup
- name: Publish image to DockerHub
uses: ./.github/actions/build-images
with:
arch: ${{ inputs.arch }}
dotnet_variant: ${{ inputs.dotnet_variant }}
dotnet_version: ${{ matrix.dotnet_version }}
docker_distro: ${{ matrix.docker_distro }}
docker_registry: docker.io
docker_registry_name: dockerhub
docker_registry_username: ${{ secrets.DOCKER_USERNAME }}
docker_registry_password: ${{ secrets.DOCKER_PASSWORD }}
- name: Publish image to GitHub
uses: ./.github/actions/build-images
with:
arch: ${{ inputs.arch }}
dotnet_variant: ${{ inputs.dotnet_variant }}
dotnet_version: ${{ matrix.dotnet_version }}
docker_distro: ${{ matrix.docker_distro }}
docker_registry: ghcr.io
docker_registry_name: github
docker_registry_username: ${{ github.repository_owner }}
docker_registry_password: ${{ secrets.DOCKER_GITHUB_TOKEN }}
48 changes: 7 additions & 41 deletions .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,64 +38,30 @@ jobs:
run: dotnet run/build.dll --target=SetMatrix

build_images:
name: Build Images (${{ matrix.arch }} - ${{ matrix.distro }}) (${{ matrix.version }} - ${{ matrix.variant }})
name: Build Images (${{ matrix.arch }} - ${{ matrix.variant }})
needs: [ prepare ]
env:
PUSH_IMAGES: ${{github.event_name != 'pull_request' && github.repository_owner == 'GitTools'}}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
arch: [ amd64, arm64 ]
runner: [ ubuntu-24.04, ubuntu-24.04-arm ]
distro: ${{ fromJson(needs.prepare.outputs.dockerDistros) }}
version: ${{ fromJson(needs.prepare.outputs.dotnetVersions) }}
variant: ${{ fromJson(needs.prepare.outputs.dotnetVariants) }}
exclude:
- runner: ubuntu-24.04-arm
arch: amd64
- runner: ubuntu-24.04
arch: arm64
fail-fast: false

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Use cached cake frosting
id: cache-cake
uses: actions/cache@v4
with:
path: run
key: run-${{ runner.os }}-${{ hashFiles('./build/**') }}
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
global-json-file: build/global.json
- name: Set up Docker
uses: ./.github/actions/docker-setup
- name: Publish image to DockerHub
uses: ./.github/actions/build-images
with:
arch: ${{ matrix.arch }}
dotnet_version: ${{ matrix.version }}
dotnet_variant: ${{ matrix.variant }}
docker_distro: ${{ matrix.distro }}
docker_registry: docker.io
docker_registry_name: dockerhub
docker_registry_username: ${{ secrets.DOCKER_USERNAME }}
docker_registry_password: ${{ secrets.DOCKER_PASSWORD }}
- name: Publish image to GitHub
uses: ./.github/actions/build-images
- uses: ./.github/workflows/_build-images.yml
with:
runner: ${{ matrix.runner }}
arch: ${{ matrix.arch }}
dotnet_version: ${{ matrix.version }}
dotnet_variant: ${{ matrix.variant }}
docker_distro: ${{ matrix.distro }}
docker_registry: ghcr.io
docker_registry_name: github
docker_registry_username: ${{ github.repository_owner }}
docker_registry_password: ${{ secrets.DOCKER_GITHUB_TOKEN }}
dotnet_variant: ${{ fromJson(needs.prepare.outputs.dotnetVariants) }}
dotnet_versions: ${{ needs.prepare.outputs.dotnetVersions }}
docker_distros: ${{ needs.prepare.outputs.dockerDistros }}

build_images_manifest:
name: Build Images (${{ matrix.distro }}) (${{ matrix.version }} - ${{ matrix.variant }})
Expand Down

0 comments on commit fc03daa

Please sign in to comment.