-
Notifications
You must be signed in to change notification settings - Fork 3
139 lines (124 loc) · 4.47 KB
/
release.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
136
137
138
139
name: Release
on:
release:
types: [published]
workflow_dispatch:
inputs:
release:
description: 'ex: @chat-game/website-v1.0.0'
type: string
required: true
ref:
description: 'branch, tag or SHA'
type: string
jobs:
determine-changes:
runs-on: ubuntu-latest
outputs:
package: ${{ steps.set-package.outputs.package }}
version: ${{ steps.set-package.outputs.version }}
steps:
- name: Regex matching
uses: actions-ecosystem/action-regex-match@v2
id: regex-match
with:
text: ${{ github.event.inputs.release || github.ref_name }}
regex: '@chat-game\/([a-z-]+)-(v[0-9]+.[0-9]+.[0-9]+)'
- name: Set package in env
id: set-package
run: |
APPS=("website" "telegram-game")
MATCH="${{ steps.regex-match.outputs.match }}"
if [ -z "$MATCH" ]; then
echo "package=" >> $GITHUB_OUTPUT
echo "version=" >> $GITHUB_OUTPUT
else
found=false
for app in "${APPS[@]}"; do
if [ "$app" == "${{ steps.regex-match.outputs.group1 }}" ]; then
found=true
break
fi
done
if $found; then
echo "package=${{ steps.regex-match.outputs.group1 }}" >> $GITHUB_OUTPUT
echo "version=${{ steps.regex-match.outputs.group2 }}" >> $GITHUB_OUTPUT
else
echo "package=" >> $GITHUB_OUTPUT
echo "version=" >> $GITHUB_OUTPUT
fi
fi
- name: Result
run: |
echo "${{ steps.set-package.outputs.package }}"
echo "${{ steps.set-package.outputs.version }}"
build:
needs: determine-changes
if: ${{ needs.determine-changes.outputs.package != '' }}
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ref || github.ref_name }}
- name: Set APP in env
run: |
echo "APP_NAME=${{ needs.determine-changes.outputs.package }}" >> $GITHUB_ENV
echo "APP_VERSION=${{ needs.determine-changes.outputs.version }}" >> $GITHUB_ENV
- name: Login to Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build ${{ matrix.package }}
uses: docker/build-push-action@v6
with:
context: .
file: docker/${{ env.APP_NAME }}/Dockerfile
push: true
tags: ${{ secrets.NAMESPACE }}/${{ env.APP_NAME }}:latest,${{ secrets.NAMESPACE }}/${{ env.APP_NAME }}:${{ env.APP_VERSION }}
deploy:
needs: [determine-changes, build]
if: ${{ needs.determine-changes.outputs.package != '' }}
runs-on: ubuntu-latest
permissions:
deployments: write
steps:
- name: Set APP ID in env
id: set-app-id
run: |
app_id=$(echo '${{ secrets.DOKPLOY_APPS }}' | jq -r '."${{ needs.determine-changes.outputs.package }}"')
echo "::add-mask::$app_id"
echo "APP_ID=$app_id" >> $GITHUB_OUTPUT
- name: Create GitHub deployment
if: ${{ steps.set-app-id.outputs.APP_ID != '' }}
uses: chrnorm/deployment-action@v2
id: deployment
with:
token: ${{ secrets.GITHUB_TOKEN }}
environment: production ${{ needs.determine-changes.outputs.package }}
- name: Dokploy Deployment
if: ${{ steps.set-app-id.outputs.APP_ID != '' }}
uses: benbristow/dokploy-deploy-action@0.0.1
with:
auth_token: ${{ secrets.DOKPLOY_AUTH_TOKEN }}
application_id: ${{ steps.set-app-id.outputs.APP_ID }}
dokploy_url: ${{ secrets.DOKPLOY_URL }}
- name: Update deployment status (success)
if: ${{ steps.set-app-id.outputs.APP_ID != '' && success() }}
uses: chrnorm/deployment-status@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
state: 'success'
- name: Update deployment status (failure)
if: ${{ steps.set-app-id.outputs.APP_ID != '' && failure() }}
uses: chrnorm/deployment-status@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
state: 'failure'