forked from ladybirdweb/faveo-helpdesk
-
Notifications
You must be signed in to change notification settings - Fork 1
94 lines (82 loc) · 3.19 KB
/
build.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: Build and publish the docker images
on:
push:
branches:
- master
tags:
- "v*"
pull_request:
types:
- opened
- reopened
- synchronize
jobs:
configure:
name: Preliminary configuration
runs-on: ubuntu-latest
outputs:
ref: ${{ steps.configure.outputs.ref }}
repo-suffix: ${{ steps.configure.outputs.repo-suffix }}
repo-push: ${{ steps.configure.outputs.repo-push }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Get version
id: version
run: echo "::set-output name=version::${GITHUB_REF/refs\/tags\//}"
if: |
github.event_name == 'push' &&
github.event.repository.full_name == github.repository &&
startsWith(github.ref, 'refs/tags/v')
- name: Configure
id: configure
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
# The ref of the commit to checkout (do not use the merge commit if pull request)
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "::set-output name=ref::${{ github.event.pull_request.head.sha }}"
elif [[ "${{ steps.version.outputs.version }}" != "" ]]; then
echo "::set-output name=ref::${{ steps.version.outputs.version }}"
else
echo "::set-output name=ref::${{ github.sha }}"
fi
# The suffix to append to the repository name if not triggered by a push for a release
[[ "${{ steps.version.outputs.version }}" == "" ]] && \
echo "::set-output name=repo-suffix::-dev" || \
echo "::set-output name=repo-suffix::"
# Do not push the resulting images to DockerHub if triggered by a pull request or DockerHub credentials are not available
[[ "${{ github.event_name }}" == "pull_request" || -z $DOCKER_USERNAME ]] && \
echo "::set-output name=repo-push::false" || \
echo "::set-output name=repo-push::true"
build:
name: Build
runs-on: ubuntu-latest
needs: configure
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ needs.configure.outputs.ref }}
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
if: needs.configure.outputs.repo-push == 'true'
- name: Configure the build-push-action parameters
id: parameters
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
echo "::set-output name=repo-owner::${DOCKER_USERNAME:-crownlabs}"
echo "::set-output name=repo-name::faveo${{ needs.configure.outputs.repo-suffix }}"
- name: Build and Push the Faveo image
uses: docker/build-push-action@v2
with:
tags: |
${{ steps.parameters.outputs.repo-owner }}/${{ steps.parameters.outputs.repo-name }}:${{ needs.configure.outputs.ref }}
push: ${{ needs.configure.outputs.repo-push }}
context: .