-
Notifications
You must be signed in to change notification settings - Fork 1
54 lines (44 loc) · 1.49 KB
/
build-docker-images.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: Build and Push Docker Images
on:
push:
branches: [develop, 'GEN*', 'gen*']
paths:
- 'scripts/references/**'
jobs:
build_and_push:
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
permissions:
packages: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set Tag Based on Branch
id: tags
run: echo "TAG=${GITHUB_REF_NAME}" >> $GITHUB_ENV
- name: Determine Image to Build
id: image
run: |
if git diff --name-only HEAD^ HEAD | grep '^scripts/references/'; then
echo "IMAGE_NAME=${{ github.repository }}-references" >> $GITHUB_ENV
echo "DOCKERFILE_PATH=scripts/references/Dockerfile" >> $GITHUB_ENV
else
echo "IMAGE_NAME=" >> $GITHUB_ENV # No image to build
fi
- name: Skip Build if No Image Determined
if: env.IMAGE_NAME == ''
run: echo "No changes in targeted directories; skipping Docker build and push."
- name: Log in to GHCR
if: env.IMAGE_NAME != ''
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker Image
if: env.IMAGE_NAME != ''
run: |
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} -f ${{ env.DOCKERFILE_PATH }} .
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}