-
Notifications
You must be signed in to change notification settings - Fork 1
118 lines (105 loc) · 4.85 KB
/
Copy pathauto-deploy.yaml
File metadata and controls
118 lines (105 loc) · 4.85 KB
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
name: Build and Push Docker Image
on:
pull_request:
branches: [dev, main]
types: [closed]
jobs:
build-and-push:
if: github.event.pull_request.merged == true
name: Build and Push Docker Image
runs-on: self-hosted
permissions:
contents: write
pull-requests: write
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract repository name
id: repo
run: |
REPO_NAME=$(basename "${{ github.repository }}")
echo "repo_name=$REPO_NAME" >> $GITHUB_OUTPUT
- name: Determine bump type
id: bump
run: |
if [[ "${{ github.event.pull_request.base.ref }}" == "dev" ]]; then
echo "bump_type=minor" >> $GITHUB_OUTPUT
elif [[ "${{ github.event.pull_request.base.ref }}" == "main" ]]; then
echo "bump_type=major" >> $GITHUB_OUTPUT
else
echo "Unsupported base branch"
exit 1
fi
- name: Bump version and create tag
id: tag_version
uses: anothrNick/github-tag-action@1.75.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEFAULT_BUMP: ${{ steps.bump.outputs.bump_type }}
RELEASE_BRANCHES: main,dev
PRERELEASE: false
WITH_V: false
- name: Set image name and tag
id: image
run: |
REGISTRY="${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.repo.outputs.repo_name }}"
TAG="${{ steps.tag_version.outputs.new_tag }}"
LATEST_TAG=$([[ "${{ github.event.pull_request.base.ref }}" == "main" ]] && echo "latest" || echo "staging-latest")
DEPLOYMENT_URL=$([[ "${{ github.event.pull_request.base.ref }}" == "main" ]] && echo "https://raven.cmp27.space" || echo "https://staging.raven.cmp27.space")
DEPLOYMENT_TARGET=$([[ "${{ github.event.pull_request.base.ref }}" == "main" ]] && echo "Production" || echo "Staging")
DM_WS_URL=$([[ "${{ github.event.pull_request.base.ref }}" == "main" ]] && echo "${{ secrets.NUXT_PUBLIC_DM_WS_URL_MAIN }}" || echo "${{ secrets.NUXT_PUBLIC_DM_WS_URL_DEV }}")
echo "registry=$REGISTRY" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "deployment_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
echo "deployment_target=$DEPLOYMENT_TARGET" >> $GITHUB_OUTPUT
echo "dm_ws_url=$DM_WS_URL" >> $GITHUB_OUTPUT
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
push: true
build-args: |
NUXT_PUBLIC_RECAPTCHA_SITE_KEY=${{ secrets.NUXT_PUBLIC_RECAPTCHA_SITE_KEY }}
NUXT_PUBLIC_DM_WS_URL=${{ steps.image.outputs.dm_ws_url }}
RAVEN_TENOR_KEY=${{ secrets.RAVEN_TENOR_KEY }}
tags: |
"${{ steps.image.outputs.registry }}:${{ steps.image.outputs.tag }}"
"${{ steps.image.outputs.registry }}:${{ steps.image.outputs.latest_tag }}"
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Notify Discord Success
if: always() && steps.build-and-push.outcome == 'success'
uses: Ilshidur/action-discord@master
env:
DISCORD_WEBHOOK: ${{ secrets.DEPLOYMENT_DISCORD_WEBHOOK }}
with:
args: |
✅ **${{steps.image.outputs.deployment_target}} Version Updated Successfully**
[View Deployment](${{steps.image.outputs.deployment_url}}) - Note that It takes time to propagate, check deployment-updates channel.
Repository: `${{ steps.image.outputs.registry }}`
Version: `${{ steps.image.outputs.tag }}`
Branch: `${{ github.event.pull_request.base.ref }}`
Author: ${{ github.event.pull_request.user.login }}
PR: [${{ github.event.pull_request.title }}](${{ github.event.pull_request.html_url }})
- name: Notify Discord Failure
if: always() && steps.build-and-push.outcome != 'success'
uses: Ilshidur/action-discord@master
env:
DISCORD_WEBHOOK: ${{ secrets.DEPLOYMENT_DISCORD_WEBHOOK }}
with:
args: |
❌ **${{steps.image.outputs.deployment_target}} Version Update Failed**
Reason: Docker image build or push failed.
Repository: `${{ steps.image.outputs.registry }}`
Branch: `${{ github.event.pull_request.base.ref }}`
Author: ${{ github.event.pull_request.user.login }}
PR: [${{ github.event.pull_request.title }}](${{ github.event.pull_request.html_url }})