-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (117 loc) · 4.72 KB
/
dev.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
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
name: Build and Deploy for Dev, QA, and Stable
on:
workflow_dispatch:
inputs:
RELEASE:
required: false
type: string
description: "The name of the release you want to deploy to stable."
pull_request:
types: [opened, reopened, synchronize]
branches:
- dev
pull_request_target:
types: [closed]
branches:
- dev
push:
tags:
- "*"
release:
types: [created]
env:
ARTIFACT_NAME: actions-demo
jobs:
build_test_and_deploy_dev:
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request' && github.base_ref == 'dev' ||
(github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'dev')
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Get Short SHA
run: |
echo "SHA_SHORT=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Run tests
run: |
echo "Fake running some test"
- name: Build Docker Image
uses: docker/build-push-action@v6
with:
context: .
push: false
tags: |
kennyd3d/${{ env.ARTIFACT_NAME }}:${{ env.SHA_SHORT }}
- name: Push Docker Image if merged
if: ${{ github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'dev' }}
run: |
docker push kennyd3d/${{ env.ARTIFACT_NAME }}:${{ env.SHA_SHORT }}
echo "Docker image pushed with tag ${{ env.SHA_SHORT }}"
echo "# 🎊 Successfully pushed the tag ${{ env.SHA_SHORT }} to Artifactory" >> $GITHUB_STEP_SUMMARY
- name: Deploy to k8
if: ${{ github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'dev' }}
run: |
echo "Pretending to deploy to k8"
# Build test and deploy to qa namespace when a release tag is created
build_test_and_deploy_qa:
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'created'
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get 7-digit SHA from the release
run: |
echo "Commit SHA: ${GITHUB_SHA::7}"
echo "SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
- name: Check if release tag's SHA is in artifactory
run: |
TAG_NAME=${GITHUB_REF#refs/tags/}
SHA_SHORT=$(git rev-parse --short=7 ${TAG_NAME})
echo "SHA_SHORT=${SHA_SHORT}" >> $GITHUB_ENV
if ! docker pull kennyd3d/${{ env.ARTIFACT_NAME }}:${{ env.SHA_SHORT }}; then
echo "❌ Failed to pull Docker image kennyd3d/${{ env.ARTIFACT_NAME }}:${{ env.SHA_SHORT }}" >> $GITHUB_STEP_SUMMARY
exit 1
- name: Retag and push Docker Image with Release Name
run: |
echo \"Retagging image tag to: ${{ github.event.release.name }}"
docker tag kennyd3d/${{ env.ARTIFACT_NAME }}:${{ env.SHORT_SHA }} kennyd3d/${{ env.ARTIFACT_NAME }}:${{ github.event.release.name }}
docker images # List Docker images to verify retagging\n"
docker push kennyd3d/${{ env.ARTIFACT_NAME }}:${{ env.RELEASE_NAME }}
- name: Deploy to Stable k8
run: |
echo "Test to deploy to Stable k8 using image kennyd3d/${{ env.ARTIFACT_NAME }}:${{ env.RELEASE_NAME }}"
# Manually deploy the release given the release name
deploy_stable:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' }}
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Check if release is in artifactory
run: |
if docker manifest inspect ${{ github.event.release.name }} > /dev/null 2>&1; then
echo echo '# 🎊 Successfully Deployed to Stable' >> $GITHUB_STEP_SUMMARY
else
echo echo '# ❌ Failed Stable Deployment: Release not found in artifactory' >> $GITHUB_STEP_SUMMARY
exit 1
fi
- name: Deploy to Stable k8
run: |
echo "Test to deploy to Stable k8 using image kennyd3d/${{ env.ARTIFACT_NAME }}:${{ github.event.release.name }}"