-
Notifications
You must be signed in to change notification settings - Fork 16
104 lines (91 loc) · 3.02 KB
/
cicd.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
94
95
96
97
98
99
100
101
102
103
104
name: CI and CD
on:
push:
branches: [ main ]
jobs:
# ==============
# CI task
# ==============
quality-check:
name: Quality Scan
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Cache Gradle packages
id: gradle-cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: download dependencies
if: ${{ steps.gradle-cache.outputs.cache-hit != 'true' }}
working-directory: ./kbazaar
run: ./gradlew dependencies
- name: Run test
working-directory: ./kbazaar
run: make test
- name: Build and analyze
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
working-directory: ./kbazaar
run: make sonar
build-and-push-docker-image:
name: Build docker image and push to repositories
runs-on: ubuntu-latest
needs: quality-check
steps:
- uses: actions/checkout@v4
- name: Setup SHA
run: echo "GITHUB_SHA=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Login ghcr.io
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: ./kbazaar
push: ${{ github.ref == 'refs/heads/main' }}
tags: ghcr.io/kbtg-kampus-classnest-se-java/workshop-<group-id>:${{ env.GITHUB_SHA }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
# ==============
# CD task
# ==============
gitops-versioning:
runs-on: ubuntu-latest
needs: build-and-push-docker-image
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: config git
run: |
git --version
git config user.name "robot"
git config user.email "[email protected]"
- name: change image tag
run: |
sed -i -E "s/ghcr.io\/kbtg-kampus-classnest-se-java\/workshop-<group-id>.*$/ghcr.io\/kbtg-kampus-classnest-se-java\/workshop-<group-id>:${GITHUB_SHA}/" infra/gitops/dev/deployment.yml
git add infra/gitops/dev/deployment.yml
git commit -m "[skip actions] 🤖 change docker image version to ${GITHUB_SHA}"
- name: push changes
uses: ad-m/github-push-action@master
with:
branch: main