-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (136 loc) · 4.9 KB
/
Copy pathrelease.yml
File metadata and controls
168 lines (136 loc) · 4.9 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
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: Existing git tag to publish, for example v0.1.0-beta.1
required: true
type: string
permissions:
contents: write
packages: write
concurrency:
group: release-${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
REGISTRY_IMAGE: ghcr.io/contentrain/studio
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Resolve release tag
id: release_meta
shell: bash
run: |
set -euo pipefail
TAG="${RELEASE_TAG}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "Invalid release tag: $TAG" >&2
exit 1
fi
git fetch --force --tags origin
git rev-parse "${TAG}^{commit}" >/dev/null
git checkout --detach "$TAG"
VERSION="${TAG#v}"
PACKAGE_VERSION="$(node -e "console.log(JSON.parse(require('fs').readFileSync('package.json', 'utf8')).version || '')")"
if [[ "$PACKAGE_VERSION" != "$VERSION" ]]; then
echo "package.json version ($PACKAGE_VERSION) does not match tag ($VERSION)" >&2
exit 1
fi
FULL_SHA="$(git rev-parse HEAD)"
SHORT_SHA="$(git rev-parse --short=7 HEAD)"
PRERELEASE=false
if [[ "$VERSION" == *-* ]]; then
PRERELEASE=true
fi
TAGS=(
"${REGISTRY_IMAGE}:${TAG}"
"${REGISTRY_IMAGE}:sha-${SHORT_SHA}"
)
if [[ "$PRERELEASE" == false ]]; then
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
TAGS+=(
"${REGISTRY_IMAGE}:${MAJOR}.${MINOR}"
"${REGISTRY_IMAGE}:${MAJOR}"
"${REGISTRY_IMAGE}:latest"
)
fi
{
echo "version=$VERSION"
echo "full_sha=$FULL_SHA"
echo "short_sha=$SHORT_SHA"
echo "prerelease=$PRERELEASE"
echo "tags<<EOF"
printf '%s\n' "${TAGS[@]}"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- uses: pnpm/action-setup@v6
with:
version: 10.26.2
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Generate Contentrain client
run: npx contentrain generate
- name: Lint
run: pnpm lint
- name: Typecheck
run: pnpm typecheck
- name: Start local Supabase DB
run: pnpm dlx supabase start --yes --workdir . --exclude gotrue,realtime,storage-api,imgproxy,kong,mailpit,postgrest,postgres-meta,studio,edge-runtime,logflare,vector,supavisor
- name: Test
run: pnpm test:ci
- name: Test RLS
run: pnpm test:rls
- name: Install Playwright browsers
run: pnpm exec playwright-core install --with-deps chromium
- name: Test E2E
run: pnpm test:e2e
- name: Build
run: pnpm build
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.release_meta.outputs.tags }}
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.title=Contentrain Studio
org.opencontainers.image.version=${{ steps.release_meta.outputs.version }}
org.opencontainers.image.revision=${{ steps.release_meta.outputs.full_sha }}
- name: Extract changelog for this version
id: changelog
shell: bash
run: |
VERSION="${{ steps.release_meta.outputs.version }}"
# Extract the section between this version header and the next version header
BODY=$(awk "/^## v${VERSION//./\\.}/{found=1; next} /^## v[0-9]/{if(found) exit} found" CHANGELOG.md)
if [ -z "$BODY" ]; then
BODY="See [full changelog](https://github.com/${{ github.repository }}/compare/...v${VERSION})"
fi
# Write to file to avoid quoting issues
echo "$BODY" > /tmp/release-body.md
- name: Create GitHub release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ env.RELEASE_TAG }}
body_path: /tmp/release-body.md
prerelease: ${{ steps.release_meta.outputs.prerelease == 'true' }}