Files
LinkPort/.drone.yml
T
2026-09-23 18:34:01 +08:00

113 lines
4.1 KiB
YAML

kind: pipeline
name: default
steps:
- name: go-test
image: golang:1.25.0-bookworm
environment:
GOTOOLCHAIN: go1.25.0
commands:
- go test ./... -count=1 -timeout=120s
- go vet ./...
- name: frontend-build
image: node:22.19.0-bookworm
commands:
- cd web
- npm ci --no-audit --no-fund
- npm run build
- name: linux-build
image: golang:1.25.0-bookworm
environment:
GOTOOLCHAIN: go1.25.0
CGO_ENABLED: "0"
GOOS: linux
GOARCH: amd64
commands:
- test -f web/dist/index.html
- mkdir -p bin/release
- version=$(cat VERSION)
- commit=$(git rev-parse --verify HEAD)
- build_time=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
- go build -p 1 -trimpath -ldflags "-s -w -X serviceport/internal/buildinfo.Version=$version -X serviceport/internal/buildinfo.Commit=$commit -X serviceport/internal/buildinfo.BuildTime=$build_time" -o bin/release/serviceport ./cmd/serviceport
- name: package
image: node:22.19.0-bookworm
commands:
- node scripts/verify-package.mjs bin/release/serviceport
- version=$(cat VERSION)
- release="serviceport-$version-linux-amd64"
- test -z "$DRONE_TAG" || test "$DRONE_TAG" = "v$version"
- mkdir -p "bin/releases/$release/docs"
- cp bin/release/serviceport VERSION README.md "bin/releases/$release/"
- cp docs/build-output.md docs/testing.md "bin/releases/$release/docs/"
- (cd "bin/releases/$release" && sha256sum serviceport > SHA256SUMS.txt)
- (cd bin/releases && tar -czf "$release.tar.gz" "$release")
- (cd bin/releases && sha256sum "$release.tar.gz")
- echo "Package ready at bin/releases/$release.tar.gz (Drone workspace only until uploaded)"
- name: publish-gitea
image: alpine:3.22
environment:
GITEA_USER:
from_secret: gitea_user
GITEA_TOKEN:
from_secret: gitea_token
commands:
- apk add --no-cache curl
- |
if test -z "$GITEA_USER" || test -z "$GITEA_TOKEN"; then
echo 'Gitea package upload skipped: configure both gitea_user and gitea_token Drone secrets to retain the archive'
exit 0
fi
version=$(cat VERSION)
if test -n "$DRONE_TAG"; then
test "$DRONE_TAG" = "v$version" || { echo 'Tag must match VERSION (v-prefixed)'; exit 1; }
package_version="$version"
else
test -n "$DRONE_COMMIT_SHA" || { echo 'DRONE_COMMIT_SHA is missing'; exit 1; }
package_version="$DRONE_COMMIT_SHA"
fi
archive="serviceport-$version-linux-amd64.tar.gz"
url="https://git.freeicu.top/api/packages/$DRONE_REPO_OWNER/generic/serviceport/$package_version/$archive"
curl --fail-with-body -sS --show-error -u "$GITEA_USER:$GITEA_TOKEN" -T "bin/releases/$archive" "$url"
printf 'Gitea package uploaded: %s\n' "$url"
when:
event:
- push
- tag
- name: upload-ipfs
image: alpine:3.22
environment:
IPFS_API:
from_secret: ipfs_api
IPFS_TOKEN:
from_secret: ipfs_token
commands:
- apk add --no-cache curl
- |
test -n "$IPFS_API" || { echo 'IPFS_API is not configured; skipping upload'; exit 0; }
version=$(cat VERSION)
test "$DRONE_TAG" = "v$version" || { echo 'Tag must match VERSION (v-prefixed)'; exit 1; }
api="$IPFS_API"
case "$api" in */api/v0) ;; *) api="$${api%/}/api/v0" ;; esac
if test -n "$IPFS_TOKEN"; then
response=$(curl --fail-with-body -sS -X POST "$${api%/}/add?pin=true&wrap-with-directory=true" -H "Authorization: Bearer $IPFS_TOKEN" -F "file=@bin/releases/serviceport-$version-linux-amd64.tar.gz")
else
response=$(curl --fail-with-body -sS -X POST "$${api%/}/add?pin=true&wrap-with-directory=true" -F "file=@bin/releases/serviceport-$version-linux-amd64.tar.gz")
fi
cid=$(printf '%s\n' "$response" | tail -n 1 | sed -n 's/.*"Hash":"\([^"]*\)".*/\1/p')
test -n "$cid" || { echo 'IPFS response did not include a CID'; exit 1; }
printf 'IPFS CID: %s\n' "$cid"
when:
event:
- tag
trigger:
event:
- push
- pull_request
- tag