1+ name : Continuous Integration
2+
3+ on :
4+ push :
5+ branches :
6+ - ' master'
7+ pull_request :
8+ branches :
9+ - master
10+ types :
11+ - opened
12+ - reopened
13+ - synchronize
14+ create :
15+ tags :
16+ - ' v[0-9]+.[0-9]+.[0-9]+*'
17+
18+ env :
19+ DOCKER_BUILDKIT : 1
20+ GOLANG_VERSION : 1.15
21+
22+ jobs :
23+
24+ binary :
25+ name : Build Binary
26+ runs-on : ubuntu-18.04
27+ steps :
28+ - name : Checkout Repository
29+ uses : actions/checkout@v2
30+ - name : Build Binary
31+ run : make binary
32+ env :
33+ GOFLAGS : ' -gcflags=-trimpath=${{ github.workspace }} -asmflags=-trimpath=${{ github.workspace }}'
34+ - name : Upload Binary
35+ uses : actions/upload-artifact@v2
36+ with :
37+ name : nginx-ingress-operator
38+ path : ${{ github.workspace }}/build/_output/bin/nginx-ingress-operator
39+
40+ unit-tests :
41+ name : Unit Tests
42+ runs-on : ubuntu-18.04
43+ steps :
44+ - name : Checkout Repository
45+ uses : actions/checkout@v2
46+ - name : Setup Golang Environment
47+ uses : actions/setup-go@v2
48+ with :
49+ go-version : ' ${{ env.GOLANG_VERSION }}'
50+ - name : Run Tests
51+ run : make test
52+
53+ build :
54+ name : Build Image
55+ runs-on : ubuntu-18.04
56+ needs : [binary, unit-tests]
57+ steps :
58+ - name : Checkout Repository
59+ uses : actions/checkout@v2
60+ - name : Retrieve Binary
61+ uses : actions/download-artifact@v2
62+ with :
63+ name : nginx-ingress-operator
64+ path : ${{ github.workspace }}/build/_output/bin
65+ - name : Docker Buildx
66+ uses : docker/setup-buildx-action@v1
67+ with :
68+ driver-opts : network=host
69+ - name : Cache Docker layers
70+ uses : actions/cache@v2
71+ with :
72+ path : /tmp/.buildx-cache
73+ key : ${{ runner.os }}-buildx-${{ github.sha }}
74+ restore-keys : |
75+ ${{ runner.os }}-buildx-
76+ - name : Build Image
77+ uses : docker/build-push-action@v2
78+ with :
79+ file : build/Dockerfile
80+ context : ' .'
81+ cache-from : type=local,src=/tmp/.buildx-cache
82+ cache-to : type=local,dest=/tmp/.buildx-cache
83+ tags : nginx/nginx-ingress-operator:${{ github.sha }}
84+ push : false
85+
86+ release-docker :
87+ name : Release Image
88+ runs-on : ubuntu-18.04
89+ needs : [build, unit-tests]
90+ if :
91+ github.repository == 'nginxinc/nginx-ingress-operator' &&
92+ github.event_name == 'create' &&
93+ contains(github.ref, 'refs/tags/')
94+ steps :
95+ - name : Checkout Repository
96+ uses : actions/checkout@v2
97+ - name : Retrieve Binary
98+ uses : actions/download-artifact@v2
99+ with :
100+ name : nginx-ingress-operator
101+ path : ${{ github.workspace }}/build/_output/bin
102+ - name : Retrieve Tag
103+ id : get_version
104+ run : echo ::set-output name=GIT_TAG::$(echo ${GITHUB_REF/refs\/tags\//} | tr -d v)
105+ - name : Docker Buildx
106+ uses : docker/setup-buildx-action@v1
107+ with :
108+ driver-opts : network=host
109+ - name : Cache Docker layers
110+ uses : actions/cache@v2
111+ with :
112+ path : /tmp/.buildx-cache
113+ key : ${{ runner.os }}-buildx-${{ github.sha }}
114+ restore-keys : |
115+ ${{ runner.os }}-buildx-
116+ - name : DockerHub Login
117+ uses : docker/login-action@v1
118+ with :
119+ username : ${{ secrets.DOCKER_USERNAME }}
120+ password : ${{ secrets.DOCKER_PASSWORD }}
121+ - name : Push to Dockerhub
122+ uses : docker/build-push-action@v2
123+ with :
124+ file : build/Dockerfile
125+ context : ' .'
126+ tags : |
127+ nginx/nginx-ingress-operator:latest
128+ nginx/nginx-ingress-operator:${{ steps.get_version.outputs.GIT_TAG }}
129+ push : true
130+
131+ notify :
132+ name : Notify
133+ runs-on : ubuntu-18.04
134+ needs : release-docker
135+ if : always() && github.ref == 'refs/heads/master'
136+ steps :
137+ - name : Workflow Status
138+ id : check
139+ uses : martialonline/workflow-status@v1
140+ - name : Calculate SHA
141+ id : commit
142+ run : echo "::set-output name=sha::$(echo ${GITHUB_SHA} | cut -c1-7)"
143+ - name : Send Notification
144+ uses : 8398a7/action-slack@v3
145+ if : contains(steps.check.outputs.status, 'failed')
146+ with :
147+ status : custom
148+ custom_payload : |
149+ {
150+ username: 'Github',
151+ icon_emoji: ':octocat:',
152+ mention: 'channel',
153+ attachments: [{
154+ color: '${{ steps.check.outputs.status }}' == 'success' ? 'good' : '${{ steps.check.outputs.status }}' == 'failed' ? 'danger' : 'warning',
155+ fields: [{
156+ title: 'Failed Commit',
157+ value: '${{ steps.commit.outputs.sha }}',
158+ short: true
159+ },
160+ {
161+ title: 'Author',
162+ value: '${{ github.actor }}',
163+ short: true
164+ },
165+ {
166+ title: 'Commit Message',
167+ value: `${{ github.event.head_commit.message }}`,
168+ short: false
169+ },
170+ {
171+ title: 'Pipeline URL',
172+ value: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}',
173+ short: false
174+ }]
175+ }]
176+ }
177+ env :
178+ GITHUB_TOKEN : ${{ github.token }}
179+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK }}
0 commit comments