-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (172 loc) · 5.42 KB
/
deployment.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
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
name: Deployment
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}
cancel-in-progress: true
env:
REGISTRY: docker.io
IMAGE_OWNER: trueberryless
IMAGE_NAME: trueberryless
NODE_VERSION: 20
jobs:
changes:
name: Filter
runs-on: ubuntu-latest
outputs:
src: ${{ steps.filter.outputs.src }}
steps:
- name: Check out the repo
uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
src:
- 'src/**'
changesets:
name: Changesets
runs-on: ubuntu-latest
outputs:
hasChangesets: ${{ steps.changesets.outputs.hasChangesets }}
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup PNPM
uses: pnpm/action-setup@v3
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
- name: Install Dependencies
run: pnpm i
- name: Create Release Pull Request
id: changesets
uses: changesets/action@v1
with:
commit: "[ci] release"
title: "[ci] release"
env:
GITHUB_TOKEN: ${{ secrets.PUBLIC_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
image-tag:
name: Image Tag
runs-on: ubuntu-latest
outputs:
IMAGE_TAG: ${{ env.IMAGE_TAG }}
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Read version from package.json
id: get_version
run: |
VERSION=$(jq -r '.version' src/package.json)
echo "IMAGE_TAG=$VERSION" >> $GITHUB_ENV
deployment:
needs: [changes, changesets, image-tag]
if: >
(
needs.changesets.outputs.hasChangesets == 'false' &&
(
contains(github.event.head_commit.message, 'deploy') ||
contains(github.event.head_commit.message, '[ci] release')
)
) ||
github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PNPM
uses: pnpm/action-setup@v3
with:
package_json_file: ./src/package.json
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
cache-dependency-path: ./pnpm-lock.yaml
- name: Install dependencies
run: pnpm install
shell: bash
working-directory: ./src
- name: Build Website
run: pnpm run build
shell: bash
working-directory: ./src
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:${{ needs.image-tag.outputs.IMAGE_TAG }}
${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
- name: Update deployment.yaml file
run: |
yq eval '.spec.template.spec.containers[0].image = "${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:${{ needs.image-tag.outputs.IMAGE_TAG }}"' -i manifest/deployment.yaml
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: update deployment.json container image (automated)
release:
name: Release
needs: [image-tag, deployment]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
- id: extract-changelog
uses: sean0x42/[email protected]
with:
file: src/CHANGELOG.md
pattern: ${{ needs.image-tag.outputs.IMAGE_TAG }}
- uses: ncipollo/release-action@v1
id: create_release
with:
tag: ${{ env.IMAGE_NAME }}-docs@${{ needs.image-tag.outputs.IMAGE_TAG }}
makeLatest: true
body: ${{ steps.extract-changelog.outputs.markdown }}
skipIfReleaseExists: true
- name: Check if release was created
id: check_release
run: |
if [ -z "${{ steps.create_release.outputs.html_url }}" ]; then
echo "RELEASE_SKIPPED=true" >> $GITHUB_ENV
else
echo "RELEASE_SKIPPED=false" >> $GITHUB_ENV
fi
- name: Discord notification
if: env.RELEASE_SKIPPED == 'false'
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }}
uses: Ilshidur/[email protected]
with:
args: |
# ${{ env.IMAGE_NAME }}@${{ needs.image-tag.outputs.IMAGE_TAG }}
${{ steps.extract-changelog.outputs.markdown }}