-
Notifications
You must be signed in to change notification settings - Fork 0
210 lines (206 loc) · 7.02 KB
/
Copy pathbuild.yml
File metadata and controls
210 lines (206 loc) · 7.02 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: 🚀 Build and Release
on:
push:
branches: [ main ]
paths: [ '.version', 'app/**', 'index.ts', 'package.json', 'bun.lock', 'Dockerfile', 'config.yaml' ]
pull_request:
branches: [ main ]
paths: [ '.version', 'app/**', 'index.ts', 'package.json', 'bun.lock', 'Dockerfile', 'config.yaml' ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: dickobrazz-server
jobs:
version-check:
name: 🔍 Check Version Changes
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
outputs:
version: ${{ steps.version.outputs.version }}
version-changed: ${{ steps.version-changed.outputs.changed }}
should-release: ${{ steps.should-release.outputs.release }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Get current version
id: version
run: |
VERSION=$(cat .version)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "📦 Current version: $VERSION"
- name: Check if version changed
id: version-changed
run: |
if git diff HEAD~1 HEAD --name-only | grep -q "^.version$"; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "✅ Version file changed"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "❌ Version file not changed"
fi
- name: Should we release?
id: should-release
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" && "${{ steps.version-changed.outputs.changed }}" == "true" ]]; then
echo "release=true" >> $GITHUB_OUTPUT
echo "🚀 Will create release and push image"
else
echo "release=false" >> $GITHUB_OUTPUT
echo "⏭️ Skipping release (not master or version not changed)"
fi
test:
name: ✅ Bun Tests
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: "1.3.8"
- name: Cache Bun
uses: actions/cache@v4
with:
path: |
~/.bun/install/cache
~/.bun/install/global
key: bun-${{ runner.os }}-${{ hashFiles('bun.lock') }}
restore-keys: |
bun-${{ runner.os }}-
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Run tests
run: bun run test --reporter=junit --reporter-outfile=reports/junit.xml
- name: Upload test report
if: always()
uses: actions/upload-artifact@v6
with:
name: junit-report
path: reports/junit.xml
lint:
name: 🧹 Bun Checks
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: "1.3.8"
- name: Cache Bun
uses: actions/cache@v4
with:
path: |
~/.bun/install/cache
~/.bun/install/global
key: bun-${{ runner.os }}-${{ hashFiles('bun.lock') }}
restore-keys: |
bun-${{ runner.os }}-
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Run checks
run: bun run check
pr-check:
name: 🧪 PR Build Check
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image (PR check)
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: false
tags: dickobrazz-server:pr-${{ github.event.number }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build success
run: |
echo "✅ Docker образ успешно собран для PR #${{ github.event.number }}"
build:
name: 🔨 Build and Push Docker Image
runs-on: ubuntu-latest
needs: version-check
if: github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
if: needs.version-check.outputs.should-release == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=true
type=raw,value=${{ needs.version-check.outputs.version }},enable=${{ needs.version-check.outputs.version-changed == 'true' }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: ${{ needs.version-check.outputs.should-release == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Image digest
if: needs.version-check.outputs.should-release == 'true'
run: |
echo "📦 Image pushed: ${{ steps.meta.outputs.tags }}"
release:
name: 📋 Create GitHub Release
runs-on: ubuntu-latest
needs: [version-check, build]
if: needs.version-check.outputs.should-release == 'true'
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.version-check.outputs.version }}
release_name: 🌶️ Dickobrazz Server v${{ needs.version-check.outputs.version }}
body: |
## 🚀 Dickobrazz Server v${{ needs.version-check.outputs.version }}
### 📦 Docker Image
```bash
docker pull ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ needs.version-check.outputs.version }}
docker pull ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest
```
draft: false
prerelease: false