mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-06-28 04:45:36 -04:00
ai testing pipeline
This commit is contained in:
parent
59cb48ffb0
commit
f5fee78b6a
1 changed files with 38 additions and 35 deletions
73
.github/workflows/build.yml
vendored
73
.github/workflows/build.yml
vendored
|
@ -6,55 +6,58 @@ on:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
permissions:
|
||||||
matrix:
|
packages: write
|
||||||
project: [admin-dashboard, auth-expressjs, battleship, calculator, cv, cv-project, inventory, library, messages, nodejs-mini-message-board, portfolio, restaurant, shopping-cart, signup_form, tictactoe, todo, weather]
|
contents: read
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set target revision
|
|
||||||
id: set-revision
|
|
||||||
run: |
|
|
||||||
echo "target_revision=${GITHUB_SHA}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Docker Login
|
- name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Check for existing image
|
- name: Build and push images
|
||||||
id: check-image
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME_PREFIX: ${{ github.repository_owner }}
|
||||||
run: |
|
run: |
|
||||||
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/${{ matrix.project }}:${{ steps.set-revision.outputs.target_revision }}
|
set -eux
|
||||||
if docker manifest inspect $IMAGE_NAME > /dev/null 2>&1; then
|
|
||||||
echo "image_exists=true" >> $GITHUB_OUTPUT
|
find . -name 'Dockerfile' -path '*/devops/*' -print0 | while IFS= read -r -d $'\0' dockerfile; do
|
||||||
|
dir=$(dirname "$dockerfile")
|
||||||
|
project=$(basename "$(dirname "$dir")")
|
||||||
|
image="$REGISTRY/$IMAGE_NAME_PREFIX/$project:latest"
|
||||||
|
echo "Building $image using $dockerfile"
|
||||||
|
|
||||||
|
# Check if an image with the same tag already exists
|
||||||
|
manifest=$(curl -s -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -u "${{ github.repository_owner }}:${{ secrets.GITHUB_TOKEN }}" "https://ghcr.io/v2/$IMAGE_NAME_PREFIX/$project/manifests/latest" 2> /dev/null)
|
||||||
|
if [[ -z "$manifest" ]]; then
|
||||||
|
echo "No existing image found for $project, building..."
|
||||||
|
docker buildx build --push --platform linux/amd64,linux/arm64 -t "$image" -f "$dockerfile" "$dir"
|
||||||
else
|
else
|
||||||
echo "image_exists=false" >> $GITHUB_OUTPUT
|
echo "Found existing image for $project, checking for changes..."
|
||||||
|
|
||||||
|
# Determine the last commit hash that resulted in a successful build
|
||||||
|
last_commit=$(git log -n 1 --pretty=format:%H)
|
||||||
|
|
||||||
|
# Get the list of changed files
|
||||||
|
changed_files=$(git diff --name-only "$last_commit" HEAD "$dir" || true)
|
||||||
|
|
||||||
|
# Check if the project has changed
|
||||||
|
if [[ -n "$changed_files" ]] || [[ $(git diff --quiet HEAD "$dir" || echo "changed") != "" ]]; then
|
||||||
|
echo "Changes detected for $project, building..."
|
||||||
|
docker buildx build --push --platform linux/amd64,linux/arm64 -t "$image" -f "$dockerfile" "$dir"
|
||||||
|
else
|
||||||
|
echo "No changes detected for $project, skipping build."
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
- name: Build and Push Docker Image
|
done
|
||||||
if: steps.check-image.outputs.image_exists == 'false'
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
context: ${{ matrix.project }}
|
|
||||||
push: true
|
|
||||||
tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.project }}:${{ steps.set-revision.outputs.target_revision }}
|
|
||||||
target: ${{ matrix.project }}
|
|
||||||
|
|
||||||
- name: Build and Push Docker Image If Changed
|
|
||||||
if: steps.check-image.outputs.image_exists == 'true'
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
context: ${{ matrix.project }}
|
|
||||||
push: true
|
|
||||||
tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.project }}:${{ steps.set-revision.outputs.target_revision }}
|
|
||||||
target: ${{ matrix.project }}
|
|
||||||
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/${{ matrix.project }}:${{ steps.set-revision.outputs.target_revision }}
|
|
Loading…
Add table
Add a link
Reference in a new issue