Skip to content

Update build_and_release.yml #66

Update build_and_release.yml

Update build_and_release.yml #66

name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.13.0
- run: zig fmt --check .
build:
permissions: write-all
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
target: x86_64-linux
- os: macos-latest
target: aarch64-macos-none
- os: windows-latest
target: x86_64-windows
runs-on: ${{ matrix.os }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- name: Get commit hash
id: commit
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- uses: goto-bus-stop/setup-zig@v2
name: Setup zig
with:
version: 0.13.0
- name: Install dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y libgl1-mesa-dev libx11-dev libgtk-4-dev build-essential
- name: Set SDKROOT (macOS)
if: matrix.os == 'macos-latest'
run: echo "export SDKROOT=$(xcrun --show-sdk-path)" >> $GITHUB_ENV
- name: Get universal dependencies
run: zig fetch --save https://github.com/Not-Nik/raylib-zig/archive/devel.tar.gz
- name: Build binary
run: zig build -Doptimize=ReleaseSafe
- name: Prepare binary (MacOS, Ubuntu)
if: matrix.os != 'windows-latest'
run: |
chmod +x zig-out/bin/DiaB-concept
mv zig-out/bin/DiaB-concept zig-out/bin/DiaB-concept_${{ matrix.os }}-${{ matrix.target }}
- name: Prepare binary (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$binary = Get-ChildItem -Path zig-out\bin -Filter *.exe | Select-Object -First 1
if ($binary) {
$newName = "DiaB-concept_${{ matrix.os }}-${{ matrix.target }}.exe"
Rename-Item -Path $binary.FullName -NewName $newName
Write-Output "Renamed $($binary.Name) to $newName"
} else {
Write-Error "No .exe file found in zig-out\bin"
exit 1
}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: DiaB-concept_${{ matrix.os }}-${{ matrix.target }}
path: zig-out/bin/DiaB-concept_${{ matrix.os }}-${{ matrix.target }}${{ matrix.os == 'windows-latest' && '.exe' || '' }}
if-no-files-found: error
release:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v2
- name: Get version
id: get_version
run: |
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
PATCH=$(echo $VERSION | cut -d. -f3)
NEW_PATCH=$((PATCH+1))
NEW_VERSION="0.1.$NEW_PATCH"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get_version.outputs.new_version }}
release_name: Release v${{ steps.get_version.outputs.new_version }}
draft: false
prerelease: false
generate_release_notes: true
- name: Upload Release Assets
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs').promises;
const glob = require('glob');
const { repo: { owner, repo }, sha } = context;
console.log('Current working directory:', process.cwd());
const files = glob.sync('./**/DiaB-concept_*');
console.log('Found files:', files);
for (const file of files) {
console.log('Uploading:', file);
await github.rest.repos.uploadReleaseAsset({
owner,
repo,
release_id: ${{ steps.create_release.outputs.id }},
name: file.split('/').pop(),
data: await fs.readFile(file)
});
}