-
Notifications
You must be signed in to change notification settings - Fork 3
128 lines (113 loc) · 3.87 KB
/
nightly.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
name: Nightly
on:
push:
paths-ignore:
- "*.md"
- ".github/**"
- "!.github/workflows/docker-nightly.yml"
branches:
- main
workflow_dispatch:
jobs:
determine-changes:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set matrix
id: set-matrix
run: |
APPS=("website" "telegram-game")
CHANGED=()
for app in "${APPS[@]}"; do
folder="apps/${app}"
if git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q "^${folder}/"; then
CHANGED+=("${app}")
fi
done
if [ ${#CHANGED[@]} -gt 0 ]; then
echo "matrix=$(printf '%s\n' "${CHANGED[@]}" | jq -R . | jq -s . | tr -d '[:space:]')" >> $GITHUB_OUTPUT
else
echo "matrix=[]" >> $GITHUB_OUTPUT
fi
- name: Result
run: |
echo "${{ steps.set-matrix.outputs.matrix }}"
build:
needs: determine-changes
if: ${{ needs.determine-changes.outputs.matrix != '[]' }}
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
strategy:
matrix:
app: ${{ fromJson(needs.determine-changes.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set APP in env
run: |
echo "APP_NAME=${{ matrix.app }}" >> $GITHUB_ENV
echo "APP_VERSION=nightly" >> $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 }}:${{ env.APP_VERSION }}
deploy:
needs: [determine-changes, build]
if: ${{ needs.determine-changes.outputs.matrix != '[]' }}
runs-on: ubuntu-latest
strategy:
matrix:
app: ${{ fromJson(needs.determine-changes.outputs.matrix) }}
permissions:
deployments: write
steps:
- name: Set APP ID in env
id: set-app-id
run: |
app_id=$(echo '${{ secrets.DOKPLOY_STAGE_APPS }}' | jq -r '."${{ matrix.app }}"')
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.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
environment: stage ${{ matrix.app }}
- name: Dokploy Deployment
if: ${{ steps.set-app-id.outputs.APP_ID != '' }}
uses: benbristow/[email protected]
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.BOT_GITHUB_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.BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
state: 'failure'