Skip to content

image

image #305

Workflow file for this run

name: image
concurrency:
group: image-${{ github.ref }}
cancel-in-progress: true
on:
schedule:
- cron: '0 8 */6 * *' # every 6 days to keep cache
push:
branches:
- 'master'
tags:
- 'v*'
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
env:
DOCKERHUB_SLUG: crazymax/xgo
GHCR_SLUG: ghcr.io/crazy-max/xgo
PLATFORMS: linux/amd64,linux/arm64
LATEST_CURRENT: 1.21.5
LATEST_PREVIOUS: 1.20.12
jobs:
prepare:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Remove dotnet
run: sudo rm -rf /usr/share/dotnet
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build base (cache only)
uses: docker/bake-action@v4
with:
targets: base
set: |
*.platform=${{ env.PLATFORMS }}
*.cache-from=type=gha,scope=base
*.cache-to=type=gha,scope=base,mode=max
build:
needs: prepare
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go_version:
- 1.20.0
- 1.20.1
- 1.20.2
- 1.20.3
- 1.20.4
- 1.20.5
- 1.20.6
- 1.20.7
- 1.20.8
- 1.20.9
- 1.20.10
- 1.20.11
- 1.20.12
- 1.21.0
- 1.21.1
- 1.21.2
- 1.21.3
- 1.21.4
- 1.21.5
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Remove dotnet
run: sudo rm -rf /usr/share/dotnet
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Tags
id: tags
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const os = require('os');
const majorMinor = "${{ matrix.go_version }}".match(/[0-9]+\.[0-9]+/g)[0];
const tags = ["${{ matrix.go_version }}"];
switch ("${{ matrix.go_version }}") {
case "${{ env.LATEST_CURRENT }}": {
tags.push(`${majorMinor}.x`, majorMinor, "latest");
break;
}
case "${{ env.LATEST_PREVIOUS }}": {
tags.push(`${majorMinor}.x`, majorMinor);
break;
}
}
return tags.join(os.EOL);
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKERHUB_SLUG }}
${{ env.GHCR_SLUG }}
tags: ${{ steps.tags.outputs.result }}
labels: |
org.opencontainers.image.title=xgo (go-${{ matrix.go_version }})
org.opencontainers.image.description=Go CGO cross compiler
org.opencontainers.image.vendor=CrazyMax
-
name: Login to DockerHub
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Login to GHCR
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build
uses: docker/bake-action@v4
with:
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: image
set: |
*.platform=${{ env.PLATFORMS }}
*.args.GO_VERSION=${{ matrix.go_version }}
*.cache-from=type=gha,scope=go-${{ matrix.go_version }}
*.cache-from=type=gha,scope=base
*.cache-to=type=gha,scope=go-${{ matrix.go_version }}
push: ${{ startsWith(github.ref, 'refs/tags/v') }}