Skip to content

Improve search result branding #54

Improve search result branding

Improve search result branding #54

Workflow file for this run

name: Build and Publish Container Image
concurrency:
group: website-build-${{ github.ref }}
cancel-in-progress: true
on:
push:
branches: ["**"]
pull_request:
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: "www-website"
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Configure Git default branch
run: git config --global init.defaultBranch master
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check repository size budget
env:
BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
run: bash scripts/check-size-budget.sh
- name: Compute image name (lowercase owner/repo)
id: img
run: |
OWNER="$(echo "${GITHUB_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]')"
REPO_NAME="${GITHUB_REPOSITORY##*/}"
IMAGE_NAME="${IMAGE_NAME:-$REPO_NAME}"
IMAGE_NAME="$(echo "${IMAGE_NAME}" | tr '[:upper:]' '[:lower:]')"
echo "IMAGE=${REGISTRY}/${OWNER}/${IMAGE_NAME}" >> "$GITHUB_ENV"
echo "Image namespace: ${REGISTRY}/${OWNER}/${IMAGE_NAME}"
- name: Compute build info
id: build_info
run: |
{
echo "created=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "source=https://github.com/${GITHUB_REPOSITORY}"
echo "branch=${GITHUB_REF_NAME}"
echo "run_url=https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
echo "author<<EOF"
git log -1 --format='%an <%ae>'
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.IMAGE }}
tags: |
type=sha
type=ref,event=branch,enable=${{ github.ref == 'refs/heads/master' }}
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
- name: Set up Buildx
uses: docker/setup-buildx-action@v4
- name: Build image for tests
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: false
load: true
tags: |
${{ env.IMAGE }}:ci
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILD_DATE=${{ steps.build_info.outputs.created }}
VCS_REF=${{ github.sha }}
VCS_URL=${{ steps.build_info.outputs.source }}
SOURCE_BRANCH=${{ steps.build_info.outputs.branch }}
IMAGE_NAME=${{ env.IMAGE }}
GITHUB_RUN_ID=${{ github.run_id }}
GITHUB_RUN_ATTEMPT=${{ github.run_attempt }}
GITHUB_RUN_URL=${{ steps.build_info.outputs.run_url }}
GITHUB_ACTOR=${{ github.actor }}
COMMIT_AUTHOR=${{ steps.build_info.outputs.author }}
cache-from: type=gha
cache-to: type=gha,mode=max,ignore-error=true
- name: Run smoke test
env:
IMAGE_UNDER_TEST: ${{ env.IMAGE }}:ci
run: |
set -euo pipefail
cid=$(docker run -d -p 0:3000 "$IMAGE_UNDER_TEST")
trap 'docker rm -f "$cid" >/dev/null 2>&1' EXIT
port=$(docker inspect -f '{{ (index (index .NetworkSettings.Ports "3000/tcp") 0).HostPort }}' "$cid")
if [ -z "$port" ]; then
echo "Failed to resolve mapped port for container $cid" >&2
docker logs "$cid" || true
exit 1
fi
for i in {1..20}; do
if curl -fsS "http://127.0.0.1:${port}/" > /dev/null; then
break
fi
if [ "$i" -eq 20 ]; then
echo "Service did not respond on / after 20s" >&2
docker logs "$cid" || true
exit 1
fi
sleep 1
done
for path in / /about /services /nabla /presentations /healthz; do
curl -fsS "http://127.0.0.1:${port}${path}" > /dev/null
done
publish:
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Configure Git default branch
run: git config --global init.defaultBranch master
- name: Checkout
uses: actions/checkout@v6
- name: Compute image name (lowercase owner/repo)
id: img
run: |
OWNER="$(echo "${GITHUB_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]')"
REPO_NAME="${GITHUB_REPOSITORY##*/}"
IMAGE_NAME="${IMAGE_NAME:-$REPO_NAME}"
IMAGE_NAME="$(echo "${IMAGE_NAME}" | tr '[:upper:]' '[:lower:]')"
echo "IMAGE=${REGISTRY}/${OWNER}/${IMAGE_NAME}" >> "$GITHUB_ENV"
echo "Image namespace: ${REGISTRY}/${OWNER}/${IMAGE_NAME}"
- name: Compute build info
id: build_info
run: |
{
echo "created=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "source=https://github.com/${GITHUB_REPOSITORY}"
echo "branch=${GITHUB_REF_NAME}"
echo "run_url=https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
echo "author<<EOF"
git log -1 --format='%an <%ae>'
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.IMAGE }}
tags: |
type=sha
type=ref,event=branch
type=raw,value=latest
- name: Set up Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
env:
GHCR_TOKEN: ${{ secrets.CR_PAT != '' && secrets.CR_PAT || secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
for attempt in 1 2 3 4 5; do
log_file="$(mktemp)"
if printf '%s\n' "$GHCR_TOKEN" | docker login "$REGISTRY" -u "$GITHUB_ACTOR" --password-stdin >"$log_file" 2>&1; then
rm -f "$log_file"
echo "GHCR login succeeded"
exit 0
fi
cat "$log_file" >&2
rm -f "$log_file"
if [ "$attempt" -eq 5 ]; then
exit 1
fi
sleep $((attempt * 10))
done
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILD_DATE=${{ steps.build_info.outputs.created }}
VCS_REF=${{ github.sha }}
VCS_URL=${{ steps.build_info.outputs.source }}
SOURCE_BRANCH=${{ steps.build_info.outputs.branch }}
IMAGE_NAME=${{ env.IMAGE }}
GITHUB_RUN_ID=${{ github.run_id }}
GITHUB_RUN_ATTEMPT=${{ github.run_attempt }}
GITHUB_RUN_URL=${{ steps.build_info.outputs.run_url }}
GITHUB_ACTOR=${{ github.actor }}
COMMIT_AUTHOR=${{ steps.build_info.outputs.author }}
cache-from: type=gha
cache-to: type=gha,mode=max,ignore-error=true
update-size-badge:
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
continue-on-error: true
permissions:
contents: write
steps:
- name: Configure Git default branch
run: git config --global init.defaultBranch master
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Generate badge data
run: BADGE_PATH=tmp/master-payload-size.json bash scripts/update-size-badge.sh
- name: Publish badge data
run: |
set -euo pipefail
badge_branch="size-badge-data"
badge_file="tmp/master-payload-size.json"
worktree="$(mktemp -d)"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if git ls-remote --exit-code --heads origin "$badge_branch" >/dev/null 2>&1; then
git fetch origin "$badge_branch"
git worktree add "$worktree" "origin/$badge_branch"
git -C "$worktree" switch -c "$badge_branch"
else
git worktree add --detach "$worktree"
git -C "$worktree" switch --orphan "$badge_branch"
git -C "$worktree" rm -rf . >/dev/null 2>&1 || true
fi
cp "$badge_file" "$worktree/master-payload-size.json"
git -C "$worktree" add master-payload-size.json
if git -C "$worktree" diff --cached --quiet; then
echo "Badge data unchanged"
exit 0
fi
git -C "$worktree" commit -m "Update master payload badge"
git -C "$worktree" push origin "HEAD:$badge_branch"