-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (78 loc) · 2.96 KB
/
new_ci.yaml
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
name: Build and Push Docker on PRs
on:
pull_request:
branches: [ "main" ]
jobs:
check-dockerfile-changes:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
outputs:
affected_folder: ${{ steps.affected-folder.outputs.AFFECTED_FOLDER }}
image_name_folder: ${{ steps.affected-folder.outputs.IMAGE_NAME_FOLDER }}
steps:
- name: Checkout repo
uses: actions/[email protected]
- name: Log in to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Determine affected folder
id: affected-folder
run: |
git remote update
git fetch
AFFECTED_FOLDER=$(git diff --name-only origin/main..origin/${{ github.head_ref }} | grep -i 'Dockerfile' | xargs -I {} dirname {} | sort -u)
IMAGE_NAME_FOLDER=$(git diff --name-only origin/main..origin/${{ github.head_ref }} | grep -i 'Dockerfile' | xargs -I {} dirname {} | sort -u | awk -F/ '{print $(NF-0)}')
echo "AFFECTED_FOLDER=$AFFECTED_FOLDER" >> $GITHUB_OUTPUT
echo "IMAGE_NAME_FOLDER=$IMAGE_NAME_FOLDER" >> $GITHUB_OUTPUT
echo "Affected folders: $AFFECTED_FOLDER"
echo "Image name folder: $IMAGE_NAME_FOLDER"
if [[ $AFFECTED_FOLDER == '' ]]; then
echo "========= No Dockerfile affected on this PR ========="
exit 0
fi
- name: Set Repo Name
id: repo-name
run: |
echo "REPO=natandias1" >> $GITHUB_OUTPUT
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
build-and-push:
needs: check-dockerfile-changes
if: ${{ github.event_name == 'pull_request' && needs.check-dockerfile-changes.outputs.AFFECTED_FOLDER != '' }}
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/[email protected]
- name: Log in to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set Repo Name
id: repo-name
run: |
echo "REPO=natandias1" >> $GITHUB_ENV
- name: Docker Metadata action
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REPO }}/${{ needs.check-dockerfile-changes.outputs.IMAGE_NAME_FOLDER }}
tags: |
type=ref,event=branch
type=ref,event=pr
flavor: |
latest=false
- name: Build and push Docker images
uses: docker/[email protected]
with:
file: ${{ needs.check-dockerfile-changes.outputs.AFFECTED_FOLDER }}/Dockerfile
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ github.event_name == 'pull_request' }}
- name: Check status
run: echo "Dockerfile check complete"