-
Notifications
You must be signed in to change notification settings - Fork 1
153 lines (145 loc) · 4.52 KB
/
build.yaml
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
name: Build
on: push
jobs:
backend-lint:
name: Backend Lint
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false
- name: Lint
uses: golangci/golangci-lint-action@v6
backend-test:
name: Backend Test
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Test
run: go test ./...
frontend-lint:
name: Frontend Lint
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Setup Node.js for use with actions
uses: actions/setup-node@v4
with:
node-version-file: frontend/.nvmrc
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
run: npm --prefix frontend install --prefer-offline --no-audit
- run: npm --prefix frontend run lint
build-backend:
name: Build Backend Image
runs-on: ubuntu-24.04
outputs:
digest: ${{ steps.docker_build.outputs.digest }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/gabe565/portfolio
tags: |
type=raw,priority=1000,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build and Push
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
pull: true
push: ${{ github.ref_name == 'main' || startsWith(github.ref, 'refs/tags/v') }}
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
target: backend
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-frontend:
name: Build Frontend
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: frontend/.nvmrc
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
run: npm --prefix=frontend install --prefer-offline --no-audit
- name: Build
env:
VITE_API_ADDRESS: https://api.gabecook.com
VITE_PLAUSIBLE_HOST: https://analytics.gabe565.com
VITE_TURNSTILE_KEY: ${{ secrets.VITE_TURNSTILE_KEY }}
run: npm --prefix=frontend run build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: frontend/dist
deploy-prod:
name: Deploy (prod)
needs: [backend-lint, backend-test, frontend-lint, build-backend, build-frontend]
if: startsWith(github.ref, 'refs/tags/v')
concurrency:
group: deploy-prod
cancel-in-progress: true
uses: ./.github/workflows/deploy.yaml
with:
environment: prod
url: https://gabecook.com
path: ${{ vars.path }}
digest: ${{ needs.build-backend.outputs.digest }}
secrets:
infra-ssh-key: ${{ secrets.INFRA_SSH_KEY }}
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
release:
name: Release
runs-on: ubuntu-24.04
needs: [backend-lint, backend-test, frontend-lint, build-backend, build-frontend]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate Changelog
id: changelog
uses: gabe565/changelog-generator@v1
- name: Release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.changelog.outputs.changelog }}