-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (149 loc) · 5.08 KB
/
build.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: docker-cypress
on:
pull_request:
push:
workflow_dispatch:
jobs:
slack-start:
name: Notify Slack of Testing Start
runs-on: ubuntu-latest
steps:
- uses: FranzDiebold/[email protected]
- uses: 8398a7/action-slack@v3
with:
status: custom
fields: workflow,commit,repo,author,action,message
custom_payload: |
{
attachments: [{
color: 'warning',
text: `${process.env.AS_REPO} ${process.env.CI_REF_NAME} - Build Started :shipit: (${process.env.AS_ACTION})\n${process.env.AS_COMMIT} ${process.env.AS_MESSAGE}\n${process.env.AS_AUTHOR}`,
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()
set-deployment-image-tag:
name: Set deployment image tag
runs-on: ubuntu-latest
steps:
- uses: FranzDiebold/[email protected]
-
name: Get current time
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYYMMDDHHMMSS
-
name: Set Tag
env:
TIMESTAMP: "${{ steps.current-time.outputs.formattedTime }}"
run: echo "BUILD_IMAGE_TAG=$CI_SHA_SHORT-$TIMESTAMP" > /tmp/image_tag.env
-
name: Display Tag
run: cat /tmp/image_tag.env
-
uses: actions/upload-artifact@v2
with:
name: build-image-tag
path: /tmp/image_tag.env
set-deployment-image-name:
name: Set deployment image name
runs-on: ubuntu-latest
steps:
- uses: FranzDiebold/[email protected]
-
name: Set Name
run: echo "BUILD_IMAGE_NAME=cypress" > /tmp/image_name.env
-
name: Display Tag
run: cat /tmp/image_name.env
-
uses: actions/upload-artifact@v2
with:
name: build-image-name
path: /tmp/image_name.env
build-image:
name: Build Image
needs: [set-deployment-image-tag]
runs-on: ubuntu-latest
steps:
- uses: FranzDiebold/[email protected]
- uses: actions/checkout@v2
-
name: Retrieve Image Tag
uses: actions/download-artifact@v2
with:
name: build-image-tag
path: /tmp
-
name: Set Image Tag
run: cat /tmp/image_tag.env >> $GITHUB_ENV
-
name: Retrieve Image Name
uses: actions/download-artifact@v2
with:
name: build-image-name
path: /tmp
-
name: Set Image Name
run: cat /tmp/image_name.env >> $GITHUB_ENV
-
name: Get current time
uses: gerred/actions/current-time@master
id: current-time
-
name: Build Docker Image
env:
TIMESTAMP: "${{ steps.current-time.outputs.time }}"
run: |
docker build \
--build-arg BUILD_DATE=$TIMESTAMP \
--build-arg VCS_REF=$CI_REF_NAME \
--build-arg VERSION=$BUILD_IMAGE_TAG \
--tag "ghcr.io/$CI_REPOSITORY_OWNER/$BUILD_IMAGE_NAME:$BUILD_IMAGE_TAG" \
.
-
name: Login to GHCR
run: echo $GH_CONTAINER_REGISTRY_TOKEN | docker login ghcr.io -u $GH_CONTAINER_REGISTRY_USER --password-stdin
env:
GH_CONTAINER_REGISTRY_TOKEN: ${{secrets.GH_CONTAINER_REGISTRY_TOKEN}}
GH_CONTAINER_REGISTRY_USER: ${{secrets.GH_CONTAINER_REGISTRY_USER}}
-
name: Push Image to GHCR
run: docker push "ghcr.io/$CI_REPOSITORY_OWNER/$BUILD_IMAGE_NAME:$BUILD_IMAGE_TAG"
-
name: Update Branch Tag
run: docker image tag "ghcr.io/$CI_REPOSITORY_OWNER/$BUILD_IMAGE_NAME:$BUILD_IMAGE_TAG" "ghcr.io/$CI_REPOSITORY_OWNER/$BUILD_IMAGE_NAME:$CI_REF_NAME"
-
name: Push Branch Tag
run: docker push "ghcr.io/$CI_REPOSITORY_OWNER/$BUILD_IMAGE_NAME:$CI_REF_NAME"
slack-results:
name: Notify Slack of Build Results
runs-on: ubuntu-latest
needs: [build-image]
if: always()
steps:
- uses: FranzDiebold/[email protected]
- uses: technote-space/workflow-conclusion-action@v2
- name: Set environment variables
run: |
if [[ ${{ env.WORKFLOW_CONCLUSION }} == success ]]; then
echo 'DEPLOY_EMOJI=:rocket:' >> $GITHUB_ENV
else
echo 'DEPLOY_EMOJI=:boom:' >> $GITHUB_ENV
fi
- uses: 8398a7/action-slack@v3
with:
status: custom
job_name:
fields: workflow,job,commit,repo,ref,author,action,message
custom_payload: |
{
attachments: [{
color: '${{ env.WORKFLOW_CONCLUSION }}' === 'success' ? 'good' : '${{ env.WORKFLOW_CONCLUSION }}' === 'failure' ? 'danger' : 'warning',
text: `${process.env.AS_REPO} ${process.env.CI_REF_NAME} - ${{ env.WORKFLOW_CONCLUSION }} ${{ env.DEPLOY_EMOJI }} (${process.env.AS_ACTION})\n${process.env.AS_COMMIT} ${process.env.AS_MESSAGE}\n${process.env.AS_AUTHOR}`,
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}