mirror of
https://github.com/fumiama/gozel.git
synced 2026-06-05 00:10:24 +08:00
188 lines
6.0 KiB
YAML
188 lines
6.0 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
types: [opened, synchronize, reopened, labeled]
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
vet_build_test:
|
|
name: Vet & Build & Test
|
|
runs-on: ${{ matrix.os }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
os: [ubuntu-latest, windows-latest]
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
|
|
- name: Find and remove all .cpp files
|
|
run: |
|
|
find . -name "*.cpp" -type f -delete
|
|
shell: bash
|
|
|
|
- name: Run go vet
|
|
run: go vet ./...
|
|
|
|
- name: Build all packages
|
|
run: go build ./...
|
|
|
|
- name: Build cmd/gen
|
|
run: go build ./cmd/gen
|
|
|
|
- name: Run tests
|
|
run: go test -v -count=1 ./...
|
|
|
|
- name: Run golangci-lint
|
|
uses: golangci/golangci-lint-action@v9
|
|
with:
|
|
version: v2.11
|
|
|
|
test-examples:
|
|
name: Test examples
|
|
runs-on: ${{ matrix.os }}
|
|
needs: [vet_build_test]
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
os: [ubuntu-latest, windows-latest]
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
|
|
- name: Install Intel Level Zero (Linux)
|
|
if: runner.os == 'Linux'
|
|
run: |
|
|
wget -qO - https://repositories.intel.com/gpu/intel-graphics.key | \
|
|
sudo gpg --dearmor -o /usr/share/keyrings/intel-graphics.gpg
|
|
. /etc/os-release
|
|
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/intel-graphics.gpg] \
|
|
https://repositories.intel.com/gpu/ubuntu ${VERSION_CODENAME} unified" | \
|
|
sudo tee /etc/apt/sources.list.d/intel-gpu.list
|
|
sudo apt-get update
|
|
sudo apt-get install -y intel-level-zero-gpu level-zero
|
|
|
|
- name: Install Intel Level Zero (Windows)
|
|
if: runner.os == 'Windows'
|
|
shell: pwsh
|
|
run: |
|
|
$release = Invoke-RestMethod "https://api.github.com/repos/oneapi-src/level-zero/releases/latest"
|
|
$asset = $release.assets | Where-Object { $_.name -match 'win.*\.zip$' } | Select-Object -First 1
|
|
if ($asset) {
|
|
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile level-zero-win.zip
|
|
Expand-Archive level-zero-win.zip -DestinationPath level-zero-win
|
|
# Copy all DLLs: ze_loader.dll, ze_null.dll, ze_validation_layer.dll, etc.
|
|
$dlls = Get-ChildItem -Recurse -Filter "*.dll" -Path level-zero-win
|
|
if ($dlls) {
|
|
foreach ($dll in $dlls) {
|
|
Copy-Item $dll.FullName "$env:SystemRoot\System32\" -Force
|
|
Write-Host "Installed $($dll.Name) to System32"
|
|
}
|
|
} else {
|
|
Write-Warning "No DLLs found in downloaded archive"
|
|
}
|
|
} else {
|
|
Write-Warning "No Windows zip asset found in level-zero releases, skipping"
|
|
}
|
|
|
|
- name: Run examples
|
|
shell: bash
|
|
env:
|
|
# Activate the Level Zero null driver (ze_null) so the loader
|
|
# can enumerate a fake device on runners without real Intel GPU hardware.
|
|
ZE_ENABLE_NULL_DRIVER: "1"
|
|
run: |
|
|
for dir in examples/*/; do
|
|
if [ -f "${dir}/main.go" ]; then
|
|
echo "==> Running ${dir}..."
|
|
go run "./${dir}/main.go" || true
|
|
fi
|
|
done
|
|
|
|
go-generate:
|
|
name: Run all Generates & Commit
|
|
runs-on: ubuntu-latest
|
|
needs: [vet_build_test]
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ github.head_ref || github.ref_name }}
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
|
|
- name: Download SYCL Linux
|
|
run: |
|
|
wget -q -O /tmp/sycl_linux.tar.gz https://github.com/intel/llvm/releases/download/v6.3.0/sycl_linux.tar.gz
|
|
mkdir -p /tmp/sycl_linux
|
|
tar -xzf /tmp/sycl_linux.tar.gz -C /tmp/sycl_linux
|
|
|
|
- name: Add SYCL bin to PATH
|
|
run: |
|
|
ls -hl /tmp/sycl_linux
|
|
echo "/tmp/sycl_linux/bin" >> $GITHUB_PATH
|
|
|
|
- name: Run go generate
|
|
run: |
|
|
go generate ./...
|
|
gofmt -w .
|
|
|
|
- name: Check for changes
|
|
id: diff
|
|
run: |
|
|
if [ -n "$(git diff --name-only)" ]; then
|
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Commit and push to PR branch
|
|
if: steps.diff.outputs.changed == 'true' && github.event_name == 'pull_request'
|
|
id: push_to_pr
|
|
continue-on-error: true
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
git add -A
|
|
git commit -m "chore: run go generate"
|
|
git push
|
|
|
|
- name: Comment on PR if push failed
|
|
if: steps.diff.outputs.changed == 'true' && github.event_name == 'pull_request' && steps.push_to_pr.outcome == 'failure'
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
github.rest.issues.createComment({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: '`go generate` produced file changes but could not be pushed automatically (likely a fork PR). Please run `go generate ./... && gofmt -w .` locally and push the changes.'
|
|
})
|
|
|
|
- name: Create Pull Request
|
|
if: steps.diff.outputs.changed == 'true' && github.event_name == 'push'
|
|
uses: peter-evans/create-pull-request@v7
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
commit-message: "chore: run go generate"
|
|
title: "chore: run go generate"
|
|
body: |
|
|
Automated PR created by CI.
|
|
|
|
`go generate .` detected generated file differences and applied updates.
|
|
branch: auto/go-generate
|
|
delete-branch: true
|
|
|