Skip to content

Generate Release

Generate Release #38

Workflow file for this run

name: Generate Release
on:
release:
types: [published]
permissions:
contents: write
jobs:
build-and-release:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
# Ubuntu
- os: ubuntu-latest
arch: x86_64
compiler: gcc
- os: ubuntu-latest
arch: arm64
compiler: gcc
# macOS
- os: macos-latest
arch: x86_64
compiler: gcc
- os: macos-latest
arch: arm64
compiler: gcc
# Windows
- os: windows-latest
arch: x86_64
compiler: msvc
- os: windows-latest
arch: x86_64
compiler: mingw
name: Build on ${{ matrix.os }} for ${{ matrix.arch }} using ${{ matrix.compiler }}
steps:
- name: Checkout code
uses: actions/checkout@v3
# Read version on Unix-based systems
- name: Read version (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
source VERSION
echo "VERSION_MAJOR=$VERSION_MAJOR" >> $GITHUB_ENV
echo "VERSION_MINOR=$VERSION_MINOR" >> $GITHUB_ENV
echo "VERSION_PATCH=$VERSION_PATCH" >> $GITHUB_ENV
echo "VERSION=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" >> $GITHUB_ENV
# Read version on Windows systems
- name: Read version (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$versionContent = Get-Content VERSION
foreach ($line in $versionContent) {
if ($line -match 'VERSION_MAJOR=(.*)') { $env:VERSION_MAJOR = $Matches[1] }
if ($line -match 'VERSION_MINOR=(.*)') { $env:VERSION_MINOR = $Matches[1] }
if ($line -match 'VERSION_PATCH=(.*)') { $env:VERSION_PATCH = $Matches[1] }
}
Add-Content -Path $env:GITHUB_ENV -Value "VERSION_MAJOR=$($env:VERSION_MAJOR)"
Add-Content -Path $env:GITHUB_ENV -Value "VERSION_MINOR=$($env:VERSION_MINOR)"
Add-Content -Path $env:GITHUB_ENV -Value "VERSION_PATCH=$($env:VERSION_PATCH)"
Add-Content -Path $env:GITHUB_ENV -Value "VERSION=$($env:VERSION_MAJOR).$($env:VERSION_MINOR).$($env:VERSION_PATCH)"
# Set Release Name on Unix systems
- name: Set Release Name (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
if [[ "${{ matrix.os }}" == *"ubuntu"* ]]; then
OS_NAME="linux"
elif [[ "${{ matrix.os }}" == *"macos"* ]]; then
OS_NAME="macos"
else
OS_NAME="${{ matrix.os }}"
fi
echo "RELEASE_NAME=libcardano-c-${{ env.VERSION }}-${OS_NAME}-${{ matrix.arch }}-${{ matrix.compiler }}" >> $GITHUB_ENV
# Set Release Name on Windows systems
- name: Set Release Name (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$osName = if ($env:RUNNER_OS -eq "Windows") { "windows" } else { $env:RUNNER_OS }
Add-Content -Path $env:GITHUB_ENV -Value "RELEASE_NAME=libcardano-c-${{ env.VERSION }}-${osName}-${{ matrix.arch }}-${{ matrix.compiler }}"
# Install dependencies for Unix
- name: Install dependencies (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
sudo apt-get update
case "${{ matrix.arch }}" in
arm64) sudo apt-get install -y gcc-aarch64-linux-gnu ;;
esac
elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then
# CMake is already installed on macOS runners
cmake --version
fi
# Install dependencies for Windows (MinGW from niXman)
- name: Install dependencies (Windows MinGW from niXman)
if: runner.os == 'Windows' && matrix.compiler == 'mingw'
shell: pwsh
run: |
$MingwVersion = "x86_64-14.2.0-release-win32-seh-ucrt-rt_v12-rev0"
$MingwUrl = "https://github.com/niXman/mingw-builds-binaries/releases/download/14.2.0-rt_v12-rev0/$MingwVersion.7z"
$MingwDir = "$env:RUNNER_TEMP\mingw-w64"
Invoke-WebRequest -Uri $MingwUrl -OutFile "$env:RUNNER_TEMP\$MingwVersion.7z"
7z x "$env:RUNNER_TEMP\$MingwVersion.7z" -o$MingwDir
"$MingwDir\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
# Setup MSVC environment
- name: Setup MSVC environment
if: runner.os == 'Windows' && matrix.compiler == 'msvc'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
# Build on Unix systems
- name: Build (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
case "${{ matrix.arch }}" in
arm64)
cmake -DCMAKE_SYSTEM_PROCESSOR=aarch64 \
-DVERSION_MAJOR=${{ env.VERSION_MAJOR }} \
-DVERSION_MINOR=${{ env.VERSION_MINOR }} \
-DVERSION_PATCH=${{ env.VERSION_PATCH }} \
-DCMAKE_BUILD_TYPE=Release \
.
;;
x86_64)
cmake -DCMAKE_SYSTEM_PROCESSOR=x86_64 \
-DVERSION_MAJOR=${{ env.VERSION_MAJOR }} \
-DVERSION_MINOR=${{ env.VERSION_MINOR }} \
-DVERSION_PATCH=${{ env.VERSION_PATCH }} \
-DCMAKE_BUILD_TYPE=Release \
.
;;
esac
cmake --build . --config Release
# Build on Windows MSVC
- name: Build (Windows MSVC)
if: runner.os == 'Windows' && matrix.compiler == 'msvc'
shell: cmd
run: |
cmake -G "Visual Studio 17 2022" -A x64 ^
-DVERSION_MAJOR=%VERSION_MAJOR% ^
-DVERSION_MINOR=%VERSION_MINOR% ^
-DVERSION_PATCH=%VERSION_PATCH% ^
.
cmake --build . --config Release
# Build on Windows MinGW (Without Clang-Tidy for MinGW builds for now)
- name: Build (Windows MinGW)
if: runner.os == 'Windows' && matrix.compiler == 'mingw'
shell: bash
run: |
cmake -G "MinGW Makefiles" \
-DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \
-CMAKE_C_CLANG_TIDY="" \
-DCMAKE_C_FLAGS="-I${{ github.workspace }}/lib/include \
-I${{ github.workspace }}/lib \
-I${{ github.workspace }}/lib/external \
-I${{ github.workspace }}/lib/external/libsodium \
-I${{ github.workspace }}/lib/external/libsodium/include \
-I${{ github.workspace }}/lib/external/gmp \
-I${{ github.workspace }}/lib/external/json-c" \
-DVERSION_MAJOR=${{ env.VERSION_MAJOR }} \
-DVERSION_MINOR=${{ env.VERSION_MINOR }} \
-DVERSION_PATCH=${{ env.VERSION_PATCH }} \
-DCMAKE_BUILD_TYPE=Release \
.
cmake --build . --config Release
# Package binaries (Unix)
- name: Package binaries (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
RELEASE_DIR=release/${{ env.RELEASE_NAME }}
mkdir -p $RELEASE_DIR/lib
cp README.md $RELEASE_DIR/
cp COPYING $RELEASE_DIR/LICENSE
cp -r lib/include $RELEASE_DIR/
cp build/release/lib/*.so $RELEASE_DIR/lib 2>/dev/null || true
cp build/release/lib/*.dylib $RELEASE_DIR/lib 2>/dev/null || true
cp build/release/lib/*.a $RELEASE_DIR/lib 2>/dev/null || true
cp build/release/lib/*.pc $RELEASE_DIR/lib 2>/dev/null || true
tar -czf "${{ env.RELEASE_NAME }}.tar.gz" -C release/${{ env.RELEASE_NAME }} .
# Package binaries (Windows MSVC)
- name: Package binaries (Windows MSVC)
if: runner.os == 'Windows' && matrix.compiler == 'msvc'
shell: cmd
run: |
set RELEASE_DIR=release\%RELEASE_NAME%
mkdir %RELEASE_DIR%
mkdir %RELEASE_DIR%\lib
xcopy /E /I lib\include %RELEASE_DIR%\include
for %%f in (dll lib) do (
xcopy /Y build\release\lib\Release\*.%%f %RELEASE_DIR%\lib\
)
xcopy /Y README.md %RELEASE_DIR%\
xcopy /Y COPYING %RELEASE_DIR%\LICENSE
powershell Compress-Archive -Path %RELEASE_DIR%\* -DestinationPath %RELEASE_NAME%.zip
# Package binaries (Windows MinGW)
- name: Package binaries (Windows MinGW)
if: runner.os == 'Windows' && matrix.compiler == 'mingw'
shell: bash
run: |
RELEASE_DIR=release/${{ env.RELEASE_NAME }}
mkdir -p $RELEASE_DIR/lib
cp -r lib/include $RELEASE_DIR/
cp README.md $RELEASE_DIR/
cp COPYING $RELEASE_DIR/LICENSE
cp build/release/lib/release/*.dll $RELEASE_DIR/lib 2>/dev/null || true
cp build/release/lib/release/*.dll.a $RELEASE_DIR/lib 2>/dev/null || true
7z a "${{ env.RELEASE_NAME }}.zip" $RELEASE_DIR
# Upload artifacts to GitHub Release (Unix)
- name: Upload artifacts to GitHub Release (Unix)
if: runner.os != 'Windows'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.RELEASE_NAME }}.tar.gz
asset_name: ${{ env.RELEASE_NAME }}.tar.gz
asset_content_type: application/gzip
# Upload artifacts to GitHub Release (Windows)
- name: Upload artifacts to GitHub Release (Windows)
if: runner.os == 'Windows'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.RELEASE_NAME }}.zip
asset_name: ${{ env.RELEASE_NAME }}.zip
asset_content_type: application/zip