-
Notifications
You must be signed in to change notification settings - Fork 297
154 lines (131 loc) · 4.64 KB
/
Copy pathpreview.yml
File metadata and controls
154 lines (131 loc) · 4.64 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
name: Preview
on:
push:
branches: [main]
concurrency:
group: preview-main
cancel-in-progress: true
permissions:
contents: read
env:
REGISTRY: docker.io
IMAGE_NAME: stangirard/the-companion
jobs:
test-gate:
name: test-gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
working-directory: web
run: bun install
- name: Typecheck
working-directory: web
run: bun run typecheck
- name: Run tests
working-directory: web
run: bun run test
preview-docker:
name: deploy/preview
needs: test-gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- 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.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build & push preview image
uses: docker/build-push-action@v6
with:
context: web/docker
file: web/docker/Dockerfile.the-companion
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:preview-main
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:preview-${{ github.sha }}
cache-from: |
type=gha
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:preview-main
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
preview-npm:
name: deploy/preview-npm
needs: test-gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
working-directory: web
run: bun install
- name: Build frontend
working-directory: web
run: bun run build
env:
VITE_POSTHOG_KEY: ${{ secrets.VITE_POSTHOG_KEY }}
VITE_POSTHOG_HOST: ${{ vars.VITE_POSTHOG_HOST || 'https://us.i.posthog.com' }}
- name: Verify dist exists
working-directory: web
run: |
test -f dist/index.html || (echo "ERROR: dist/index.html missing" && exit 1)
- name: Compute prerelease version
id: version
working-directory: web
run: |
BASE_VERSION=$(node -p "require('./package.json').version")
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
TIMESTAMP=$(date +%Y%m%d%H%M%S)
# Bump patch by 1 so the prerelease is semver-ahead of the current
# stable release. Without this, 0.68.0-preview.* < 0.68.0 and the
# in-app update checker correctly rejects it (THE-216).
NEXT_PATCH=$(node -p "
const v = '${BASE_VERSION}'.split('.');
v[2] = Number(v[2]) + 1;
v.join('.')
")
PRE_VERSION="${NEXT_PATCH}-preview.${TIMESTAMP}.${SHORT_SHA}"
echo "version=${PRE_VERSION}" >> "$GITHUB_OUTPUT"
echo "Preview version: ${PRE_VERSION}"
- name: Validate prerelease is semver-ahead of stable
working-directory: web
run: |
BASE_VERSION=$(node -p "require('./package.json').version")
PRE_VERSION="${{ steps.version.outputs.version }}"
node -e "
const semverGt = (a, b) => {
const pa = a.split('-')[0].split('.').map(Number);
const pb = b.split('-')[0].split('.').map(Number);
for (let i = 0; i < 3; i++) {
if (pa[i] > pb[i]) return true;
if (pa[i] < pb[i]) return false;
}
// Equal core: stable > prerelease of same core
return a.split('-').length === 1 && b.split('-').length > 1;
};
if (!semverGt('${PRE_VERSION}', '${BASE_VERSION}')) {
console.error('FATAL: preview version ${PRE_VERSION} is not semver-greater than stable ${BASE_VERSION}');
process.exit(1);
}
console.log('OK: ${PRE_VERSION} > ${BASE_VERSION}');
"
- name: Set prerelease version
working-directory: web
run: npm version "${{ steps.version.outputs.version }}" --no-git-tag-version
- name: Publish prerelease to npm
working-directory: web
run: npm publish --access public --tag next
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}