Skip to content

Merge pull request #723 from hoangthanh28/docs/update-docker-hub-loca… #804

Merge pull request #723 from hoangthanh28/docs/update-docker-hub-loca…

Merge pull request #723 from hoangthanh28/docs/update-docker-hub-loca… #804

Workflow file for this run

# Heavyweight build and test
name: Build and Publish
on:
push:
branches:
- main
paths-ignore:
- docs/
workflow_dispatch:
jobs:
set-version-number:
name: Set version number
runs-on: ubuntu-latest
outputs:
nuGetVersion: ${{ steps.gitversion.outputs.nuGetVersionV2 }}
semVer: ${{ steps.gitversion.outputs.fullSemVer }}
is-release: ${{ steps.gitversion.outputs.CommitsSinceVersionSource == 0 }}
#is-release: 'true'
steps:
- name: Setup .NET 10
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3.1.11
with:
versionSpec: '5.x'
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v3.1.11
build-netcore-tool:
needs: set-version-number
name: Build .NET Core (global) tool
runs-on: ubuntu-latest
permissions:
id-token: write # Required to get Github JWT to auth to Nuget
contents: write
steps:
- uses: actions/checkout@v5
- name: Setup .NET 10
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet pack ./src/grate/grate.csproj -p:SelfContained=false -p:PackAsTool=true -p:PackageOutputPath=/tmp/grate/nupkg
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Upload published tool artifact
uses: actions/upload-artifact@v5
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
with:
name: grate-dotnet-tool-${{ needs.set-version-number.outputs.nuGetVersion }}
path: /tmp/grate/nupkg/*
- name: Push to Nuget.org
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
run: dotnet nuget push /tmp/grate/nupkg/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ORG_KEY }} --skip-duplicate
build-nuget-package:
needs: set-version-number
name: Build Nuget
runs-on: ubuntu-latest
strategy:
matrix:
package: [
"grate.core",
"grate.mariadb",
"grate.oracle",
"grate.postgresql",
"grate.sqlite",
"grate.sqlserver"
]
permissions:
id-token: write # Required to get Github JWT to auth to Nuget
contents: read
steps:
- uses: actions/checkout@v5
- name: Setup .NET 10 and earlier
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: Restore dependencies
run: dotnet restore
- name: Pack Nuget package ${{ matrix.package }}
run: dotnet pack ./src/${{ matrix.package }} -c Release --include-symbols -o /tmp/grate/nupkg /p:Version=${{ env.VERSION }}
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Push to Nuget.org
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
run: dotnet nuget push /tmp/grate/nupkg/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ORG_KEY }} --skip-duplicate
build-standalone:
name: Build cli
needs: set-version-number
runs-on: ubuntu-latest
strategy:
matrix:
arch: [ "win-x64", "win-x86", "win-arm64",
"linux-musl-x64", "linux-musl-arm64", "linux-x64", "linux-arm64",
"osx-x64"
]
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- name: Setup .NET 10
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Publish self-contained ${{ matrix.arch }}
run: dotnet publish ./src/grate/grate.csproj -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
TargetFramework: net10.0
- name: Upload self-contained ${{ matrix.arch }}
#if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
uses: actions/upload-artifact@v5
with:
name: grate-${{ matrix.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ./publish/${{ matrix.arch }}/self-contained/*
- name: Publish artifact ${{ matrix.arch }}
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
run: |
name=grate-${{ matrix.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}.zip
zip -j $name ./publish/${{ matrix.arch }}/self-contained/*
gh release upload ${{ needs.set-version-number.outputs.semVer }} $name --clobber
env:
GH_TOKEN: ${{ github.token }}
build-standalone-mac-arm64:
name: Build cli
needs: set-version-number
# Use macos-15 to build osx-arm64, it runs on M1, see
# https://github.blog/changelog/2024-01-30-github-actions-introducing-the-new-m1-macos-runner-available-to-open-source/
#
# I've earlier had problems with that the trimmed, self-contained binary for osx-arm64 that was built on Linux
# did not work when opened on an actual mac with arm64.
runs-on: macos-15
strategy:
matrix:
arch: [ "osx-arm64" ]
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- name: Setup .NET 10
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Publish self-contained ${{ matrix.arch }}
run: dotnet publish ./src/grate/grate.csproj -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
TargetFramework: net10.0
- name: Upload self-contained ${{ matrix.arch }}
#if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
uses: actions/upload-artifact@v5
with:
name: grate-${{ matrix.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ./publish/${{ matrix.arch }}/self-contained/*
- name: Publish artifact ${{ matrix.arch }}
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
run: |
name=grate-${{ matrix.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}.zip
zip -j $name ./publish/${{ matrix.arch }}/self-contained/*
gh release upload ${{ needs.set-version-number.outputs.semVer }} $name --clobber
env:
GH_TOKEN: ${{ github.token }}
build-msi:
name: Build MSI
needs:
- set-version-number
- build-standalone
runs-on: windows-latest
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
strategy:
matrix:
arch: [ "win-x64", "win-arm64" ]
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- uses: actions/download-artifact@v6
with:
name: grate-${{ matrix.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ${{ matrix.arch }}/
- name: Create msi
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
run: ./installers/msi/Create-Installer.ps1 -grateExe ./${{ matrix.arch }}/grate.exe -Version "${{ needs.set-version-number.outputs.nuGetVersion }}"
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Upload MSI ${{ matrix.arch }}
uses: actions/upload-artifact@v5
with:
name: grate-msi-${{ matrix.arch }}-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ./installers/msi/tmp/*.msi
- name: Publish artifact ${{ matrix.arch }}
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
shell: pwsh
run: |
$name = "grate-msi-${{ matrix.arch }}-${{ needs.set-version-number.outputs.nuGetVersion }}.msi"
$msiFile = Get-ChildItem -Path ./installers/msi/tmp -Filter *.msi | Select-Object -First 1
Copy-Item $msiFile.FullName -Destination $name
gh release upload ${{ needs.set-version-number.outputs.semVer }} $name --clobber
env:
GH_TOKEN: ${{ github.token }}
build-docker-image:
name: Build and push docker image
needs:
- set-version-number
#- build-standalone ## no need, we build directly from source
strategy:
fail-fast: false
matrix:
configuration:
- name: "amd64"
arch: "linux/amd64"
runs-on: ubuntu-latest
# Doesn't work well with docker-in-docker on amd64 runners, so we skip it for now
# - name: "arm64"
# arch: "linux/arm64"
# runs-on: macos-15
runs-on: ${{ matrix.configuration.runs-on }}
#if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
env:
#REGISTRY: ghcr.io
IMAGE_NAME: grate
steps:
- uses: actions/checkout@v5
- name: Set up Docker
uses: docker/setup-docker-action@v4
with:
daemon-config: |
{
"debug": true,
"features": {
"containerd-snapshotter": true
}
}
- name: Log in to the Container registry
uses: docker/login-action@v3
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
with:
#registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_HUB_USER}}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
with:
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{version}},value=${{ needs.set-version-number.outputs.semVer }}
type=ref,event=tag
#images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: ${{ secrets.DOCKER_HUB_USER}}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
file: ./installers/docker/Dockerfile
context: .
#platforms: linux/amd64,linux/arm64
platforms: ${{ matrix.configuration.arch }}
push: ${{ needs.set-version-number.outputs.is-release == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ needs.set-version-number.outputs.nuGetVersion }}
build-deb:
name: Build Debian package
needs:
- set-version-number
- build-standalone
runs-on: ubuntu-latest
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
strategy:
matrix:
arch: [ "linux-arm64", "linux-x64" ]
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- uses: actions/download-artifact@v6
with:
name: grate-${{ matrix.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ${{ matrix.arch }}/
- id: get-arch
name: Get architecture
run: |
arch=$(echo ${{ matrix.arch }} | cut -d- -f2 | sed 's/x64/amd64/')
echo "::set-output name=arch::$arch"
- name: Create dpkg # Linux with powershell script? really? YES! :D
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
run: ./installers/deb/Create-Package.ps1 -grateExe ./${{ matrix.arch }}/grate -Version "${{ needs.set-version-number.outputs.nuGetVersion }}" -arch ${{ steps.get-arch.outputs.arch}}
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Upload .dpkg ${{ steps.get-arch.outputs.arch }}
uses: actions/upload-artifact@v5
with:
name: grate_${{ needs.set-version-number.outputs.nuGetVersion }}-1_${{ steps.get-arch.outputs.arch}}.deb
path: ./installers/deb/grate_${{ needs.set-version-number.outputs.nuGetVersion }}-1_${{ steps.get-arch.outputs.arch }}.deb
- name: Publish artifact ${{ matrix.arch }}
if: ${{ needs.set-version-number.outputs.is-release == 'true' }}
run: |
nameOld=./installers/deb/grate_${{ needs.set-version-number.outputs.nuGetVersion }}-1_${{ steps.get-arch.outputs.arch }}.deb
name=grate_${{ needs.set-version-number.outputs.nuGetVersion }}_${{ steps.get-arch.outputs.arch }}.deb
mv $nameOld $name
gh release upload ${{ needs.set-version-number.outputs.semVer }} $name --clobber
env:
GH_TOKEN: ${{ github.token }}
test:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
category: [ "Basic_tests", "SqlServer", "PostgreSQL", "MariaDB", "Sqlite", "Oracle" ]
steps:
- uses: actions/checkout@v5
- name: Setup .NET 10 and earlier
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: Test
run: >
dotnet test
unittests/${{ matrix.category }}
--logger:"xunit;LogFilePath=/tmp/test-results/${{ matrix.category }}.xml" --
-MaxCpuCount 2
env:
LogLevel: Warning
TZ: UTC