turnstile-caddy/.forgejo/workflows/publish.yaml
Lukas Schaefer 2360cc4179
All checks were successful
/ resolve-go (push) Successful in 2s
/ test (push) Successful in 3s
/ cleanup (push) Successful in 0s
Publish / publish (push) Successful in 16s
Use apache 2.0 license and improve publish flow
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
2026-09-12 23:59:41 -04:00

61 lines
2.2 KiB
YAML

name: Publish
# Tag push after the commit already passed test.yaml (typical: push commit, then tag).
# https://go.dev/doc/modules/publishing
on:
push:
tags:
- 'v*'
permissions:
contents: read
actions: read
jobs:
publish:
runs-on: selfhosted
container:
image: ghcr.io/catthehacker/ubuntu:go-latest
steps:
- name: Require passing test.yaml for this commit
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/actions/runs"
body=$(curl -fsS -H "Authorization: token ${TOKEN}" \
"${api}?head_sha=${GITHUB_SHA}&limit=50")
if echo "$body" | jq -e '
[.workflow_runs[]
| select(.workflow_id == "test.yaml" or (.workflow_id | endswith("/test.yaml")))
| select(.status == "success")
] | length > 0
' >/dev/null; then
echo "test.yaml succeeded for ${GITHUB_SHA}"
exit 0
fi
echo "No successful test.yaml run for ${GITHUB_SHA} run again once test.yaml is finished" >&2
exit 1
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.ref }}
- name: Index and verify module on proxy.golang.org
env:
GOPROXY: https://proxy.golang.org
GOSUMDB: sum.golang.org
run: |
set -euo pipefail
module="$(awk '/^module / {print $2; exit}' go.mod)"
version="${GITHUB_REF_NAME}"
# https://go.dev/doc/modules/publishing — register the tag with the module index
go list -m "${module}@${version}"
# Fetch .mod/.zip through the proxy only (no direct fallback)
go mod download "${module}@${version}"
# Proxy protocol: cached versions expose these endpoints
curl -fsS "https://proxy.golang.org/${module}/@v/${version}.info" >/dev/null
curl -fsS "https://proxy.golang.org/${module}/@v/${version}.mod" >/dev/null
curl -fsS "https://proxy.golang.org/${module}/@v/${version}.zip" >/dev/null
echo "Module ${module}@${version} is available from proxy.golang.org"