Feature: CI Automation #160
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Linux Build | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
DOTNET_INSTALL_DIR: ${{ github.workspace }}/.dotnet | |
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages | |
DOCKER_REGISTRY: ghcr.io/maxrev-dev | |
permissions: | |
packages: write | |
contents: read | |
jobs: | |
BuildNugetPackages-Linux: | |
strategy: | |
matrix: | |
include: | |
- os: linux/amd64 | |
arch: x64 | |
actions-runner: ubuntu-latest #self-hosted-macos-x64 | |
- os: linux/arm64 | |
arch: arm64 | |
actions-runner: self-hosted-macos-arm64 | |
runs-on: ${{ matrix.actions-runner }} | |
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')" | |
defaults: | |
run: | |
working-directory: unix | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Cache restore | |
uses: maxnowack/local-cache@main | |
with: | |
path: | | |
${{ github.workspace }}/.dotnet | |
${{ github.workspace }}/ci/cache/ | |
key: ${{ runner.os }}-buildx-${{ matrix.os }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
logout: false | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
${{ env.DOCKER_REGISTRY }}/gdal.netcore.builder.${{ matrix.arch }} | |
tags: | | |
type=sha | |
type=ref,event=branch | |
type=ref,event=pr | |
latest | |
- name: Build and push on GH runner | |
uses: docker/build-push-action@v5 | |
if: ${{ !contains(matrix.actions-runner, 'self-hosted') }} | |
with: | |
push: true | |
context: . | |
file: ci/Dockerfile.unix | |
platforms: ${{ matrix.os }} | |
build-args: | | |
BUILD_NUMBER_TAIL=${{ github.run_number }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Build and push on local runner | |
uses: docker/build-push-action@v5 | |
if: ${{ contains(matrix.actions-runner, 'self-hosted') }} | |
with: | |
load: true | |
push: false | |
tags: ${{ env.DOCKER_REGISTRY }}/gdal.netcore.builder.${{ matrix.arch }}:latest | |
context: . | |
file: ci/Dockerfile.unix | |
platforms: ${{ matrix.os }} | |
build-args: | | |
BUILD_NUMBER_TAIL=${{ github.run_number }} | |
- name: Extract artifacts | |
run: | | |
chmod +x '${{ github.workspace }}/ci/extract-container-artifacts.sh' | |
'${{ github.workspace }}/ci/extract-container-artifacts.sh' ${{ matrix.arch }} | |
- name: Store packages as artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: unix-packages-${{ matrix.arch }} | |
path: nuget/*.nupkg | |
TestAndPushPackages-Linux: | |
strategy: | |
matrix: | |
include: | |
- os: linux/amd64 | |
arch: x64 | |
actions-runner: ubuntu-latest | |
- os: linux/arm64 | |
arch: arm64 | |
actions-runner: self-hosted-macos-arm64 | |
needs: BuildNugetPackages-Linux | |
runs-on: ${{ matrix.actions-runner }} | |
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')" | |
defaults: | |
run: | |
working-directory: unix | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: unix-packages-${{ matrix.arch }} | |
path: nuget/ | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build docker image | |
run: | | |
docker buildx build --load --platform=${{ matrix.os }} \ | |
--progress=plain -t maxrev-dev/gdal.netcore.tester.${{ matrix.arch }}:latest \ | |
--build-arg BUILD_NUMBER_TAIL=${{ github.run_number }} \ | |
--build-arg BUILD_ARCH=${{ matrix.arch }} \ | |
-f '${{ github.workspace }}/ci/Dockerfile.unix.test' \ | |
${{ github.workspace }} | |
- name: Test packages | |
run: | | |
docker run \ | |
--env BUILD_NUMBER_TAIL=${{ github.run_number }} \ | |
--env BUILD_ARCH=${{ matrix.arch }} \ | |
-t maxrev-dev/gdal.netcore.tester.${{ matrix.arch }}:latest |