-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (76 loc) · 2.87 KB
/
main.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
name: Docker build and push
on:
push:
branches:
- '*'
tags:
- 'v*'
pull_request:
branches:
- 'master'
- 'releases/v*'
- 'feature/*'
env:
# TEST_TARGET: Name of the testing target in the Dockerfile
TEST_TARGET: testing
# DO_TEST - true to build and run unit tests, false to skip the tests
DO_TEST: false
# DO_PUSH - true to push to the HPE_DEPLOY_REPO, false to not push
DO_PUSH: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Lowercase repository name for docker build
id: lowercase-repository-name
run: |
echo "HPE_BUILD_REPO=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "HPE_DEPLOY_REPO=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: set TAG & TESTTAG for main/master
if: ${{ github.event.repository.default_branch == 'main' || github.event.repository.default_branch == 'master' }}
run: |
echo "TAG=${{ github.sha }}" >> ${GITHUB_ENV}
echo "LATESTTAG=latest" >> ${GITHUB_ENV}
echo "TESTTAG=test-${{ github.sha }}" >> ${GITHUB_ENV}
- name: set TAG & TESTTAG for all other branches
if: ${{ github.event.repository.default_branch != 'main' && github.event.repository.default_branch != 'master' }}
run: |
echo "TAG=dev-${{ github.sha }}" >> ${GITHUB_ENV}
echo "LATESTTAG=dev-latest" >> ${GITHUB_ENV}
echo "TESTTAG=test-${{ github.sha }}" >> ${GITHUB_ENV}
- name: Docker login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the test Docker image
if: ${{ env.DO_TEST == 'true' }}
id: docker_build_test_target
uses: docker/build-push-action@v2
with:
push: false
target: ${{ env.TEST_TARGET }}
tags: ${{ env.HPE_BUILD_REPO }}:${{ env.TESTTAG }}
- name: Run the Docker image unit tests
if: ${{ env.DO_TEST == 'true' }}
run: docker run ${HPE_BUILD_REPO}:${TESTTAG}
- name: Build the final Docker image
id: docker_build
uses: docker/build-push-action@v2
with:
push: false
tags: ${{ env.HPE_BUILD_REPO }}:${{ env.TAG }}
- name: Peek at the docker images
run: docker images
- name: Tag the build
run: docker tag docker.io/${HPE_BUILD_REPO}:${TAG} ghcr.io/${HPE_DEPLOY_REPO}:${TAG}
- name: Tag the build as latest
run: docker tag ${HPE_BUILD_REPO}:${TAG} ghcr.io/${HPE_DEPLOY_REPO}:${LATESTTAG}
- name: Push the tagged build
if: ${{ env.DO_PUSH == 'true' }}
run: docker push ghcr.io/${HPE_DEPLOY_REPO}:${TAG}
- name: Push the build tagged as latest
if: ${{ env.DO_PUSH == 'true' }}
run: docker push ghcr.io/${HPE_DEPLOY_REPO}:${LATESTTAG}