-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (84 loc) · 3.26 KB
/
pipeline.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
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: Pipeline
on:
push:
pull_request:
env:
containerRegistry: container-registry.cr.de-fra.ionos.com
imageName: fdpg-api
isMain: ${{ github.ref == 'refs/heads/main' }}
isDev: ${{ github.ref == 'refs/heads/dev' }}
nodeVersion: '22.12.0'
jobs:
qualitiy_gate:
name: 'Qualitiy Gate'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: 'Setup Node'
uses: actions/setup-node@v3
with:
node-version: ${{env.nodeVersion}}
cache: yarn
- name: 'Installing Modules'
run: yarn install
- name: 'Jest Unit Testing'
run: yarn test
- name: 'Publish Test Results'
uses: mikepenz/action-junit-report@v3
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/reports/junit.xml'
fail_on_failure: true
- name: 'Publish Code Coverage'
uses: 5monkeys/cobertura-action@master
if: ${{github.event_name == 'pull_request' }}
with:
path: '**/reports/coverage/cobertura-coverage.xml'
minimum_coverage: 75
fail_below_threshold: false
only_changed_files: true
build_container_image:
name: 'Build Container Image'
runs-on: ubuntu-latest
needs: qualitiy_gate
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: set npmVersionString variable
run: echo "npmVersionString="$(node -p "require('./package.json').version") >> "$GITHUB_ENV"
- name: set pipeDate variable
run: echo "pipeDate=$(date +%Y%m%d)" >> "$GITHUB_ENV"
- name: set pipeTime variable
run: echo "pipeTime=$(date +%H%M%S)" >> "$GITHUB_ENV"
- name: set buildNumberOfDate variable
# Github does not support resetting counters => buildNumberOfDate will never be reset to 1, always increases
run: echo "buildNumberOfDate=${{github.run_number}}" >> "$GITHUB_ENV"
- name: set variables for main
if: ${{env.isMain == 'true'}}
run: echo "imageTag=${{env.npmVersionString}}_${{env.pipeDate}}_${{env.buildNumberOfDate}}" >> "$GITHUB_ENV"
- name: set variables for dev
if: ${{env.isDev == 'true'}}
run: echo "imageTag=latest" >> "$GITHUB_ENV"
- name: set variables when neither main nor dev
if: ${{env.isDev == 'false' && env.isMain == 'false'}}
run: echo "imageTag=test-latest" >> "$GITHUB_ENV"
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: ${{ env.containerRegistry }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
push: ${{env.isMain == 'true' || env.isDev == 'true' }}
tags: ${{env.containerRegistry}}/fdpg/${{env.imageName}}:${{env.imageTag}}
labels: BUILD_DATE=${{env.pipeDate}}
BUILD_TIME=${{env.pipeTime}}
BUILD_NO_OF_DATE=${{env.buildNumberOfDate}}
SOURCE_BRANCH=${{github.ref}}
build-args: |
SOFTWARE_VERSION=${{github.ref}}