ci: fix host-mode docker go invocation
All checks were successful
CI / Test and build (push) Successful in 2m3s

This commit is contained in:
Maxfield Luke 2026-07-29 05:00:11 -04:00
parent 10b311410e
commit 9cd56a7770
2 changed files with 14 additions and 30 deletions

View file

@ -1,4 +1,3 @@
# Host-mode runner: no local Go — use official golang image + docker.sock.
name: CI name: CI
on: on:
@ -22,19 +21,12 @@ jobs:
run: | run: |
set -euo pipefail set -euo pipefail
case "$GITHUB_WORKSPACE" in case "$GITHUB_WORKSPACE" in
/data/*) HOST_WORKSPACE="/opt/forgejo-runner/data${GITHUB_WORKSPACE#/data}" ;; /data/*) HOST_WS="/opt/forgejo-runner/data${GITHUB_WORKSPACE#/data}" ;;
*) HOST_WORKSPACE="$GITHUB_WORKSPACE" ;; *) HOST_WS="$GITHUB_WORKSPACE" ;;
esac esac
test -f "$GITHUB_WORKSPACE/go.mod" test -f "$GITHUB_WORKSPACE/go.mod"
# Single -c string so host-mode act does not split the docker command.
docker run --rm --network host \ docker run --rm --network host \
--volume "$HOST_WORKSPACE:/src" \ -v "${HOST_WS}:/src" -w /src -e CGO_ENABLED=0 \
--workdir /src \
-e CGO_ENABLED=0 \
golang:1.25-bookworm \ golang:1.25-bookworm \
bash -lc ' sh -c "go version && go test ./... && make build && ls -la dist/"
set -euo pipefail
go version
go test ./...
make build
ls -la dist/
'

View file

@ -1,4 +1,3 @@
# Build multi-arch binaries and publish a Forgejo release on tags v*.
name: Release name: Release
on: on:
@ -22,26 +21,21 @@ jobs:
run: | run: |
set -euo pipefail set -euo pipefail
case "$GITHUB_WORKSPACE" in case "$GITHUB_WORKSPACE" in
/data/*) HOST_WORKSPACE="/opt/forgejo-runner/data${GITHUB_WORKSPACE#/data}" ;; /data/*) HOST_WS="/opt/forgejo-runner/data${GITHUB_WORKSPACE#/data}" ;;
*) HOST_WORKSPACE="$GITHUB_WORKSPACE" ;; *) HOST_WS="$GITHUB_WORKSPACE" ;;
esac esac
version="${GITHUB_REF_NAME}" version="${GITHUB_REF_NAME}"
if [[ "$version" == "main" || -z "$version" ]]; then if [ "$version" = "main" ] || [ -z "$version" ]; then
version="dev-$(echo "$GITHUB_SHA" | cut -c1-7)" version="dev-$(printf '%s' "$GITHUB_SHA" | cut -c1-7)"
fi fi
commit="$(printf '%s' "$GITHUB_SHA" | cut -c1-7)"
docker run --rm --network host \ docker run --rm --network host \
--volume "$HOST_WORKSPACE:/src" \ -v "${HOST_WS}:/src" -w /src \
--workdir /src \
-e CGO_ENABLED=0 \ -e CGO_ENABLED=0 \
-e VERSION="$version" \ -e VERSION="$version" \
-e COMMIT="$(echo "$GITHUB_SHA" | cut -c1-7)" \ -e COMMIT="$commit" \
golang:1.25-bookworm \ golang:1.25-bookworm \
bash -lc ' sh -c 'go test ./... && make release VERSION="$VERSION" COMMIT="$COMMIT" && ls -la dist/'
set -euo pipefail
go test ./...
make release VERSION="$VERSION" COMMIT="$COMMIT"
ls -la dist/
'
- name: Publish Forgejo release - name: Publish Forgejo release
if: startsWith(github.ref, 'refs/tags/v') if: startsWith(github.ref, 'refs/tags/v')
@ -51,7 +45,6 @@ jobs:
set -euo pipefail set -euo pipefail
tag="${GITHUB_REF_NAME}" tag="${GITHUB_REF_NAME}"
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases" api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases"
# Create release (ignore if already exists)
body=$(printf '%s' "{\"tag_name\":\"${tag}\",\"name\":\"${tag}\",\"draft\":false,\"prerelease\":false}") body=$(printf '%s' "{\"tag_name\":\"${tag}\",\"name\":\"${tag}\",\"draft\":false,\"prerelease\":false}")
resp=$(curl -sS -w "\n%{http_code}" -X POST \ resp=$(curl -sS -w "\n%{http_code}" -X POST \
-H "Authorization: token ${TOKEN}" \ -H "Authorization: token ${TOKEN}" \
@ -59,8 +52,7 @@ jobs:
-d "$body" "$api" || true) -d "$body" "$api" || true)
code=$(printf '%s' "$resp" | tail -n1) code=$(printf '%s' "$resp" | tail -n1)
payload=$(printf '%s' "$resp" | sed '$d') payload=$(printf '%s' "$resp" | sed '$d')
if [[ "$code" != "201" && "$code" != "200" ]]; then if [ "$code" != "201" ] && [ "$code" != "200" ]; then
# try fetch existing
payload=$(curl -sS -H "Authorization: token ${TOKEN}" \ payload=$(curl -sS -H "Authorization: token ${TOKEN}" \
"${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases/tags/${tag}") "${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases/tags/${tag}")
fi fi