Skip to content

add: eval categorization mod #91

add: eval categorization mod

add: eval categorization mod #91

Workflow file for this run

name: Build Mods
permissions:
contents: read
id-token: write
packages: write
on:
pull_request:
push:
branches:
- main
workflow_dispatch:
inputs:
directory:
description: "Directory containing pyproject.toml to build"
required: true
type: string
jobs:
discover:
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
# Fetch the last commit as well so we can compare against it
fetch-depth: 2
- name: Determine Changed Directories
id: changed
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# For manual triggers, use the specified directory
if [ -f "${{ github.event.inputs.directory }}/pyproject.toml" ]; then
# Output as JSON array with single item
echo "changed_dirs=[\"${{ github.event.inputs.directory }}\"]" >> $GITHUB_OUTPUT
else
echo "Error: No pyproject.toml found in ${{ github.event.inputs.directory }}"
exit 1
fi
else
# Compare current commit to the base commit (for PRs) or the last commit (for push)
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE_SHA="${{ github.event.pull_request.base.sha }}"
else
BASE_SHA="$(git rev-parse HEAD~1)"
fi
# Get changed files and find directories with pyproject.toml
changed_files=$(git diff --name-only $BASE_SHA HEAD)
dirs=()
for f in $changed_files; do
d=$(dirname "$f")
if [[ "$d" == mods/* ]] && [ -f "$d/pyproject.toml" ]; then
dirs+=("$d")
fi
done
# Remove duplicates and format for output
unique_dirs=$(printf "%s\n" "${dirs[@]}" | sort -u)
if [ -z "$unique_dirs" ]; then
echo "No directories with pyproject.toml changed."
echo "changed_dirs=[]" >> $GITHUB_OUTPUT
else
# Convert to JSON array
json_array=$(printf '%s\n' "${unique_dirs[@]}" | jq -R . | jq -c -s .)
echo "changed_dirs=$json_array" >> $GITHUB_OUTPUT
fi
fi
outputs:
changed_dirs: ${{ steps.changed.outputs.changed_dirs }}
build:
needs: discover
if: ${{ needs.discover.outputs.changed_dirs != '[]' }}
runs-on: ${{ matrix.runner }}
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
directory: ${{ fromJson(needs.discover.outputs.changed_dirs) }}
platform: [linux/amd64, linux/arm64]
include:
- platform: linux/amd64
runner: ubuntu-latest-8-cores
- platform: linux/arm64
runner: ubuntu-latest-arm64-4
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Determine registry
id: registry
run: |
if [ "${{ github.ref_name }}" = "main" ]; then
echo "registry=us-central1-docker.pkg.dev/wandb-production/mods" >> $GITHUB_OUTPUT
echo "idpool=projects/959666683579/locations/global/workloadIdentityPools/weave-mods-pool/providers/github" >> $GITHUB_OUTPUT
echo "[email protected]" >> $GITHUB_OUTPUT
echo "default_registry=ghcr.io/wandb/weave-mods" >> $GITHUB_OUTPUT
else
echo "registry=us-central1-docker.pkg.dev/wandb-qa/mods" >> $GITHUB_OUTPUT
echo "idpool=projects/281760294016/locations/global/workloadIdentityPools/weave-mods-pool/providers/github" >> $GITHUB_OUTPUT
echo "[email protected]" >> $GITHUB_OUTPUT
echo "default_registry=ghcr.io/wandb/weave-mods" >> $GITHUB_OUTPUT
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Authenticate to GCP
if: ${{ steps.registry.outputs.idpool != '' }}
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ steps.registry.outputs.idpool }}
service_account: ${{ steps.registry.outputs.sa }}
- name: Configure Docker for Artifact Registry
if: ${{ steps.registry.outputs.idpool != '' }}
run: |
gcloud auth configure-docker us-central1-docker.pkg.dev
- name: Generate context
id: context
env:
REGISTRY: ${{ steps.registry.outputs.registry }}
DEFAULT_REGISTRY: ${{ steps.registry.outputs.default_registry }}
run: |
uv run build.py --root "${{ matrix.directory }}" > build_output.json
echo "image=$(cat build_output.json)" >> $GITHUB_OUTPUT
echo "tags=$(jq -r '.tags | join(",")' build_output.json)" >> $GITHUB_OUTPUT
echo "labels=$(jq -c '.labels' build_output.json)" >> $GITHUB_OUTPUT
echo "name=$(jq -r '.tags[0]' build_output.json | sed 's/:[^:]*$//')" >> $GITHUB_OUTPUT
echo "dir=$(echo ${{ matrix.directory }} | sed 's/\//-/g')" >> $GITHUB_OUTPUT
echo "platform=$(echo ${{ matrix.platform }} | sed 's/\//-/g')" >> $GITHUB_OUTPUT
- name: Python Build Cache for Docker
uses: actions/cache@v4
with:
path: python-build-cache
key: ${{ matrix.platform }}-python-build-cache-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ matrix.platform }}-python-build-cache-
- name: Inject python-build-cache
uses: reproducible-containers/buildkit-cache-dance@4b2444fec0c0fb9dbf175a96c094720a692ef810 # v2.1.4
with:
cache-source: python-build-cache
- name: Build and push by digest
id: build
uses: docker/build-push-action@v4
with:
context: ${{ matrix.directory }}
platforms: ${{ matrix.platform }}
push: true
labels: ${{ steps.context.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=image,name=${{ steps.context.outputs.name }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ steps.context.outputs.dir }}-${{ steps.context.outputs.platform }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
outputs:
dir: ${{ steps.context.outputs.dir }}
name: ${{ steps.context.outputs.name }}
tags: ${{ steps.context.outputs.tags }}
registry: ${{ steps.registry.outputs.registry }}
idpool: ${{ steps.registry.outputs.idpool }}
sa: ${{ steps.registry.outputs.sa }}
merge:
needs: [discover, build]
runs-on: ubuntu-latest
timeout-minutes: 1
strategy:
matrix:
directory: ${{ fromJson(needs.discover.outputs.changed_dirs) }}
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-${{ needs.build.outputs.dir }}-*
merge-multiple: true
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Authenticate to GCP
if: ${{ needs.build.outputs.idpool != '' }}
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ needs.build.outputs.idpool }}
service_account: ${{ needs.build.outputs.sa }}
- name: Configure Docker for Artifact Registry
if: ${{ needs.build.outputs.idpool != '' }}
run: |
gcloud auth configure-docker us-central1-docker.pkg.dev
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
IFS=',' read -ra TAGS <<< "${{ needs.build.outputs.tags }}"
for TAG in "${TAGS[@]}"; do
docker buildx imagetools create -t "$TAG" \
$(printf '${{ needs.build.outputs.name }}@sha256:%s ' *)
done
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ needs.build.outputs.name }}