-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (55 loc) · 1.6 KB
/
merge-to-main.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
name: Build, Test & Push Container Image - ON Merge
on:
push:
branches:
- main
jobs:
build-test-push:
runs-on: ubuntu-latest
env:
image_name: docker.io/surajnarwade/stage-test-app
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.20'
- name: Build the binary
run: go build -o app
- name: Unit test
run: go test
- uses: benjlevesque/[email protected]
id: short-sha
- run: echo $SHA
env:
SHA: ${{ steps.short-sha.outputs.sha }}
- run: echo $SHA
env:
SHA: ${{ env.SHA }}
# https://github.com/docker/login-action
- name: Log in to container registry
uses: docker/login-action@v2
with:
# For Quay
# registry: quay.io
# username: ${{ secrets.QUAY_USERNAME }}
# password: ${{ secrets.QUAY_ROBOT_TOKEN }}
# For Dockerhub
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker image
id: meta_image
uses: docker/[email protected]
with:
images: |
${{ env.image_name }}
tags: |
type=raw,value=latest
type=raw,value=staging-${{ env.SHA }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta_image.outputs.tags }}