Files
go-otel/.gitea/workflows/build.yaml
T
2026-09-27 16:45:10 +02:00

92 lines
3.6 KiB
YAML

name: Build and Publish
run-name: ${{ gitea.actor }} build 🚀
on:
push:
branches: [main]
workflow_dispatch:
jobs:
Metadata:
runs-on: amd64
outputs:
version: ${{ steps.meta.outputs.version }}
git_commit: ${{ steps.meta.outputs.git_commit }}
build_date: ${{ steps.meta.outputs.build_date }}
steps:
- name: Checkout
uses: actions/checkout@v4
- id: meta
name: Derive build metadata
run: |
GIT_COMMIT=$(git rev-parse HEAD)
if git describe --tags --exact-match >/dev/null 2>&1; then
VERSION=$(git describe --tags --exact-match)
else
VERSION=$(git rev-parse --short=12 HEAD)
fi
BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "git_commit=$GIT_COMMIT" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "build_date=$BUILD_DATE" >> $GITHUB_OUTPUT
BuildAndPushAmd64:
needs: Metadata
runs-on: amd64
steps:
- uses: actions/checkout@v4
- name: Build amd64 image
run: |
docker build \
--build-arg APP_RELEASE=${{ needs.Metadata.outputs.version }} \
--build-arg VERSION=${{ needs.Metadata.outputs.version }} \
--build-arg GIT_COMMIT=${{ needs.Metadata.outputs.git_commit }} \
--build-arg BUILD_DATE=${{ needs.Metadata.outputs.build_date }} \
--progress=plain \
-t matst80/otel-debug:${{ needs.Metadata.outputs.version }} \
-t matst80/otel-debug:latest \
.
- name: Push images
run: |
docker push matst80/otel-debug:${{ needs.Metadata.outputs.version }}
docker push matst80/otel-debug:latest
- name: Reconcile after image is published
env:
GITOPS_WEBHOOK_SECRET: ${{ secrets.GITOPS_WEBHOOK_SECRET }}
run: |
if [ -z "$GITOPS_WEBHOOK_SECRET" ]; then
echo "GITOPS_WEBHOOK_SECRET must match the k8s-helper Gitea webhook secret" >&2
exit 1
fi
payload="$(mktemp)"
trap 'rm -f "$payload"' EXIT
printf '{"ref":"%s","after":"%s","repository":{"clone_url":"https://git.k6n.net/mats/go-otel.git","ssh_url":"git@git.k6n.net:mats/go-otel.git"}}' \
"$GITHUB_REF" "$GITHUB_SHA" > "$payload"
signature="$(openssl dgst -sha256 -hmac "$GITOPS_WEBHOOK_SECRET" "$payload" | awk '{print $NF}')"
curl --fail --silent --show-error \
-X POST \
-H "Content-Type: application/json" \
-H "X-Gitea-Signature: $signature" \
--data-binary "@$payload" \
https://ui.k6n.net/api/gitops/webhooks/gitea
- name: Upload source maps
env:
RELEASE: ${{ needs.Metadata.outputs.version }}
OTEL_URL: https://otel.k6n.net
run: |
# Maps come from the exact UI build stage that went into the image
# (cached layers), so bundle hashes match what is deployed.
docker build --target ui-builder \
--build-arg APP_RELEASE="$RELEASE" \
-t otel-debug-ui-builder:"$RELEASE" .
maps_dir="$(mktemp -d)"
cid="$(docker create otel-debug-ui-builder:"$RELEASE")"
docker cp "$cid:/app/dist" "$maps_dir/dist"
docker rm "$cid" >/dev/null
found=0
while IFS= read -r -d '' map; do
found=1
./scripts/upload-sourcemap.sh "${map%.map}"
done < <(find "$maps_dir" -type f -name '*.js.map' -print0)
rm -rf "$maps_dir"
[ "$found" = 1 ] || { echo "no source maps found in UI build" >&2; exit 1; }