Skip to content

Add repository size budget check #24

Add repository size budget check

Add repository size budget check #24

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: 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 }}
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: 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 }}
cache-from: type=gha
cache-to: type=gha,mode=max,ignore-error=true