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_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: Set up Zig uses: https://github.com/mlugg/setup-zig@v2 with: version: 0.16.0 - name: Install shader compiler run: | sudo apt-get update sudo apt-get install -y glslc - 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