Compare commits
4
Commits
a5476ccdd7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d33b304fe3
|
||
|
|
892ee61ddf
|
||
|
|
7e60e090f2
|
||
|
|
87a34cf42d
|
@@ -0,0 +1,144 @@
|
|||||||
|
name: Build and Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build executables
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
ZIG_INSTALL_ROOT: /ci-cache/zig-chess/0.16.0/linux-amd64/tool
|
||||||
|
ZIG_LOCAL_CACHE_DIR: /ci-cache/zig-chess/0.16.0/linux-amd64/local
|
||||||
|
ZIG_GLOBAL_CACHE_DIR: /ci-cache/zig-chess/0.16.0/linux-amd64/global
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: https://github.com/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install pinned Zig from the persistent cache
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
cache_parent="$(dirname "$ZIG_INSTALL_ROOT")"
|
||||||
|
mkdir -p "$cache_parent"
|
||||||
|
exec 9>"$cache_parent/.install.lock"
|
||||||
|
flock -x 9
|
||||||
|
if ! test -x "$ZIG_INSTALL_ROOT/zig" || \
|
||||||
|
! test "$("$ZIG_INSTALL_ROOT/zig" version)" = "0.16.0"; then
|
||||||
|
archive="$(mktemp /tmp/zig-0.16.0.XXXXXXXX.tar.xz)"
|
||||||
|
staging="$(mktemp -d "$cache_parent/.tool.XXXXXXXX")"
|
||||||
|
trap 'rm -f "$archive"; rm -rf "$staging"' EXIT
|
||||||
|
curl --fail --location --retry 3 --retry-all-errors \
|
||||||
|
--output "$archive" \
|
||||||
|
https://ziglang.org/download/0.16.0/zig-x86_64-linux-0.16.0.tar.xz
|
||||||
|
printf '%s %s\n' \
|
||||||
|
70e49664a74374b48b51e6f3fdfbf437f6395d42509050588bd49abe52ba3d00 \
|
||||||
|
"$archive" | sha256sum --check -
|
||||||
|
tar -xJf "$archive" --strip-components=1 -C "$staging"
|
||||||
|
rm -rf "$ZIG_INSTALL_ROOT"
|
||||||
|
mv "$staging" "$ZIG_INSTALL_ROOT"
|
||||||
|
rm -f "$archive"
|
||||||
|
trap - EXIT
|
||||||
|
fi
|
||||||
|
echo "$ZIG_INSTALL_ROOT" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
|
- name: Install native build dependencies
|
||||||
|
run: |
|
||||||
|
apt-get -o Acquire::Retries=2 update
|
||||||
|
apt-get install -y --no-install-recommends \
|
||||||
|
glslc \
|
||||||
|
libx11-dev \
|
||||||
|
libxcursor-dev \
|
||||||
|
libxi-dev \
|
||||||
|
libxinerama-dev \
|
||||||
|
libxrandr-dev
|
||||||
|
|
||||||
|
- name: Show tool versions
|
||||||
|
run: |
|
||||||
|
zig version
|
||||||
|
glslc --version
|
||||||
|
|
||||||
|
- name: Prepare persistent Zig caches
|
||||||
|
run: |
|
||||||
|
mkdir -p "$ZIG_LOCAL_CACHE_DIR" "$ZIG_GLOBAL_CACHE_DIR"
|
||||||
|
|
||||||
|
- name: Build GUI executable
|
||||||
|
run: |
|
||||||
|
zig build \
|
||||||
|
--cache-dir "$ZIG_LOCAL_CACHE_DIR" \
|
||||||
|
--global-cache-dir "$ZIG_GLOBAL_CACHE_DIR"
|
||||||
|
|
||||||
|
- name: Build magic generator executable
|
||||||
|
run: |
|
||||||
|
zig build magic-numbers \
|
||||||
|
--cache-dir "$ZIG_LOCAL_CACHE_DIR" \
|
||||||
|
--global-cache-dir "$ZIG_GLOBAL_CACHE_DIR"
|
||||||
|
|
||||||
|
- name: Package executables
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
version="${GITHUB_REF_NAME}"
|
||||||
|
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
||||||
|
arch="$(uname -m)"
|
||||||
|
artifact_dir="zig-chess-${version}-${os}-${arch}"
|
||||||
|
mkdir -p "dist/${artifact_dir}"
|
||||||
|
cp zig-out/bin/zig-chess "dist/${artifact_dir}/"
|
||||||
|
cp zig-out/bin/magic-numbers "dist/${artifact_dir}/"
|
||||||
|
tar -C dist -czf "dist/${artifact_dir}.tar.gz" "${artifact_dir}"
|
||||||
|
sha256sum "dist/${artifact_dir}.tar.gz" > "dist/${artifact_dir}.tar.gz.sha256"
|
||||||
|
|
||||||
|
- name: Upload build artifact
|
||||||
|
uses: https://github.com/actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: zig-chess-${{ github.ref_name }}
|
||||||
|
path: |
|
||||||
|
dist/*.tar.gz
|
||||||
|
dist/*.sha256
|
||||||
|
|
||||||
|
- name: Create Gitea release for version tag
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||||
|
tag="${GITHUB_REF_NAME}"
|
||||||
|
|
||||||
|
release_json="$(mktemp)"
|
||||||
|
asset_response="$(mktemp)"
|
||||||
|
|
||||||
|
printf '{"tag_name":"%s","target_commitish":"%s","name":"%s","body":"Automated release for %s","draft":false,"prerelease":false}' \
|
||||||
|
"$tag" "$GITHUB_SHA" "$tag" "$tag" > "$release_json"
|
||||||
|
|
||||||
|
response="$(curl -sS \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-X POST \
|
||||||
|
--data @"$release_json" \
|
||||||
|
"${api}/releases")"
|
||||||
|
|
||||||
|
release_id="$(printf '%s' "$response" | python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])')"
|
||||||
|
|
||||||
|
for asset in dist/*.tar.gz dist/*.sha256; do
|
||||||
|
name="$(basename "$asset")"
|
||||||
|
curl -sS \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-X POST \
|
||||||
|
-F "attachment=@${asset}" \
|
||||||
|
"${api}/releases/${release_id}/assets?name=${name}" > "$asset_response"
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user