-
Notifications
You must be signed in to change notification settings - Fork 10
102 lines (89 loc) · 3.12 KB
/
docker-publish.yml
File metadata and controls
102 lines (89 loc) · 3.12 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Build and Publish Docker Image
on:
push:
branches: [ "master" ]
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "master" ]
env:
IMAGE_NAME: dunajdev/docker-mailserver-gui
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
pull-requests: read # Needed for tj-actions/changed-files on PRs
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Fetch history to compare files (important for PRs)
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}
- name: Check for relevant file changes
id: check_changes
uses: tj-actions/changed-files@v44 # Use a recent version
with:
files: |
backend/**
frontend/**
docker/**
Dockerfile
docker-compose.yml
.github/workflows/**
files_ignore: |
**.md
backend/db.json
# --- Conditional Steps ---
# Run subsequent steps only if relevant files were changed
- name: Set up Node.js
if: steps.check_changes.outputs.any_changed == 'true'
uses: actions/setup-node@v4
with:
node-version: '20' # Use a recent LTS version
- name: Install backend dependencies and check formatting
if: steps.check_changes.outputs.any_changed == 'true'
run: |
cd backend
npm ci
npm run format:check
- name: Install frontend dependencies and check formatting
if: steps.check_changes.outputs.any_changed == 'true'
run: |
cd frontend
npm ci
npm run format:check
- name: Set up Docker Buildx
if: steps.check_changes.outputs.any_changed == 'true'
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
# Also check if relevant files changed
if: steps.check_changes.outputs.any_changed == 'true' && github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata for Docker
if: steps.check_changes.outputs.any_changed == 'true'
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=short
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
if: steps.check_changes.outputs.any_changed == 'true'
uses: docker/build-push-action@v5
with:
context: .
# Push condition remains the same, but the whole step is conditional
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max