Skip to content

c

c #43

Workflow file for this run

name: Build examples and test all
on:
pull_request:
branches: ["main"]
push:
branches:
- ci-test/*
workflow_dispatch:
permissions:
contents: read
env:
GIST_ID: ${{ vars.GIST_ID }}
GIST_TOKEN: ${{ secrets.GIST_TOKEN }}
GITHUB_API_VERSION: 2022-11-28
jobs:
build-test:
strategy:
matrix:
target:
[
x86_64-linux,
aarch64-linux,
x86_64-macos,
aarch64-macos,
x86_64-windows,
]
include:
- target: x86_64-linux
runs-on: ubuntu-latest
- target: aarch64-linux
runs-on: ubuntu-24.04-arm
- target: x86_64-macos
runs-on: macos-13
- target: aarch64-macos
runs-on: macos-latest
- target: x86_64-windows
runs-on: windows-latest
runs-on: ${{ matrix.runs-on }}
steps:
- name: Setup Zig
uses: mlugg/setup-zig@v1
with:
version: 0.14.0
- name: Checkout
uses: actions/checkout@v4
- name: Build examples
run: zig build examples -Dtarget=${{ matrix.target }}
- name: Test
run: zig build test -Dtarget=${{ matrix.target }}
- name: Generate filename
shell: bash
run: |
REPO_NAME=$(echo "${{ github.repository }}" | awk -F/ '{print $2}')
echo "FILENAME=ci-badge.$REPO_NAME.${{ matrix.target }}.json" >> $GITHUB_ENV
- name: Update badge (Linux/macOS)
# if: runner.os != 'Windows' && always()
if: always()
shell: bash
run: |
COLOR=$([ ${{ job.status }} = "success" ] && echo "brightgreen" || echo "red")
JSON_CONTENT='{
"schemaVersion": 1,
"label": "ci",
"message": "'${{ matrix.target }}'",
"color": "'$COLOR'",
"namedLogo": "github"
}'
ESCAPED_CONTENT=$(jq -s -R -r @json <<< "$JSON_CONTENT")
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token $GIST_TOKEN" \
-H "X-GitHub-Api-Version: $GITHUB_API_VERSION" \
-d '{
"description": "CI status badges for ${{ github.repository }}",
"files": {
"'${{ env.FILENAME }}'": {
"content": '"$ESCAPED_CONTENT"'
}
}
}' \
https://api.github.com/gists/$GIST_ID
# - name: Update badge (Windows)
# if: runner.os == 'Windows' && always()
# shell: pwsh
# run: |
# $color = if ("${{ job.status }}" -eq "success") { "brightgreen" } else { "red" }
# $jsonContent = @"
# {
# "schemaVersion": 1,
# "label": "ci",
# "message": "${{ matrix.target }}",
# "color": "$color",
# "namedLogo": "github"
# }
# "@
# $escapedContent = $jsonContent | ConvertTo-Json -Compress
# $body = @{
# description = "CI status badges for ${{ github.repository }}"
# files = @{
# "${{ env.FILENAME }}" = @{
# content = $escapedContent
# }
# }
# } | ConvertTo-Json -Depth 10
# Invoke-RestMethod `
# -Uri "https://api.github.com/gists/$env:GIST_ID" `
# -Method PATCH `
# -Headers @{
# "Accept" = "application/vnd.github+json"
# "Authorization" = "token $env:GIST_TOKEN"
# "X-GitHub-Api-Version" = "$env:GITHUB_API_VERSION"
# } `
# -Body $body