-
Notifications
You must be signed in to change notification settings - Fork 2
106 lines (87 loc) · 3.5 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
95
96
97
98
99
100
101
102
103
104
105
name: Docker build and push
on: [push]
env:
# TEST_TARGET: Name of the testing target in the Dockerfile
TEST_TARGET: container-unit-test
# DO_TEST - true to build and run unit tests, false to skip the tests
DO_TEST: true
# 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@v4
- 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@v3
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@v5
with:
push: false
target: ${{ env.TEST_TARGET }}
tags: ${{ env.HPE_BUILD_REPO }}:${{ env.TESTTAG }}
secrets: |
"GH_HPETOKEN=${{ secrets.GH_HPETOKEN }}"
- 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@v5
with:
push: false
tags: ${{ env.HPE_BUILD_REPO }}:${{ env.TAG }}
secrets: |
"GH_HPETOKEN=${{ secrets.GH_HPETOKEN }}"
- 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}
create_release:
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0
- name: Repair tag
run: git fetch -f origin ${{ github.ref }}:${{ github.ref }}
- name: Verify that the tag is annotated
run: if test x$(git for-each-ref ${{ github.ref }} | awk '{print $2}') = xtag; then /bin/true; else echo "\"${{ github.ref }}\" does not look like an annotated tag!"; /bin/false; fi
- name: Release
uses: softprops/action-gh-release@v1
with:
#prerelease: true
generate_release_notes: true