Repository navigation
195 lines (175 loc) · 6.07 KB
/
Copy pathrelease-enterprise-admin.yml
File metadata and controls
195 lines (175 loc) · 6.07 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
name: Release Enterprise Admin
on:
push:
branches:
- main
- enterprise
paths:
- "enterprise/admin/**"
- ".github/workflows/release-enterprise-admin.yml"
workflow_dispatch:
inputs:
environment:
description: "Release environment (prod promotes the most recent dev tag)"
type: choice
required: true
default: prod
options:
- prod
- dev
version:
description: "Semver version to release (prod only, defaults to latest dev tag)"
required: false
type: string
env:
IMAGE_NAME: ghcr.io/josiahsrc/voquill/enterprise-admin
jobs:
metadata:
name: Determine release metadata
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ steps.meta.outputs.version }}
tag_name: ${{ steps.meta.outputs.tag_name }}
commit_sha: ${{ steps.meta.outputs.commit_sha }}
release_env: ${{ steps.meta.outputs.release_env }}
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute release metadata
id: meta
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_ENVIRONMENT: ${{ github.event.inputs.environment || '' }}
INPUT_VERSION: ${{ github.event.inputs.version || '' }}
run: |
set -euo pipefail
git fetch --tags --force
if [[ "${EVENT_NAME}" == "push" ]]; then
RELEASE_ENV="dev"
else
RELEASE_ENV="${INPUT_ENVIRONMENT:-prod}"
fi
SEMVER_REGEX='^[0-9]+\.[0-9]+\.[0-9]+$'
TAG_PREFIX="enterprise-admin"
mapfile -t DEV_TAGS < <(git tag --list "${TAG_PREFIX}-dev-v*" --sort=-v:refname)
LAST_DEV_TAG="${DEV_TAGS[0]:-}"
if [[ "${RELEASE_ENV}" == "dev" ]]; then
if [[ -z "${LAST_DEV_TAG}" ]]; then
VERSION_BASE="0.0.0"
else
VERSION_BASE="${LAST_DEV_TAG#${TAG_PREFIX}-dev-v}"
fi
if [[ ! "${VERSION_BASE}" =~ ${SEMVER_REGEX} ]]; then
echo "Last dev tag (${LAST_DEV_TAG:-none}) is not in x.y.z format." >&2
exit 1
fi
IFS='.' read -r MAJOR MINOR PATCH <<< "${VERSION_BASE}"
PATCH=$((PATCH + 1))
VERSION="${MAJOR}.${MINOR}.${PATCH}"
TAG_NAME="${TAG_PREFIX}-dev-v${VERSION}"
COMMIT_SHA="${GITHUB_SHA}"
else
if [[ -n "${INPUT_VERSION}" ]]; then
TARGET_VERSION="${INPUT_VERSION}"
if [[ ! "${TARGET_VERSION}" =~ ${SEMVER_REGEX} ]]; then
echo "Provided version '${TARGET_VERSION}' is not in x.y.z format." >&2
exit 1
fi
TARGET_DEV_TAG="${TAG_PREFIX}-dev-v${TARGET_VERSION}"
if ! git rev-parse -q --verify "refs/tags/${TARGET_DEV_TAG}" >/dev/null; then
echo "Dev tag ${TARGET_DEV_TAG} not found for promotion." >&2
exit 1
fi
else
if [[ -z "${LAST_DEV_TAG}" ]]; then
echo "No dev tag found to promote to prod." >&2
exit 1
fi
TARGET_DEV_TAG="${LAST_DEV_TAG}"
TARGET_VERSION="${TARGET_DEV_TAG#${TAG_PREFIX}-dev-v}"
fi
VERSION="${TARGET_VERSION}"
TAG_NAME="${TAG_PREFIX}-v${VERSION}"
COMMIT_SHA="$(git rev-parse "${TARGET_DEV_TAG}^{commit}")"
fi
if git rev-parse -q --verify "refs/tags/${TAG_NAME}" >/dev/null; then
echo "Tag ${TAG_NAME} already exists. Aborting." >&2
exit 1
fi
{
echo "release_env=${RELEASE_ENV}"
echo "version=${VERSION}"
echo "tag_name=${TAG_NAME}"
echo "commit_sha=${COMMIT_SHA}"
} >> "$GITHUB_OUTPUT"
- name: Create release tag
uses: actions/github-script@v7
env:
TAG_NAME: ${{ steps.meta.outputs.tag_name }}
TARGET_SHA: ${{ steps.meta.outputs.commit_sha }}
with:
script: |
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${process.env.TAG_NAME}`,
sha: process.env.TARGET_SHA,
});
build:
name: Build & Push
needs: metadata
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
ref: ${{ needs.metadata.outputs.commit_sha }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Compute Docker tags
id: tags
env:
VERSION: ${{ needs.metadata.outputs.version }}
RELEASE_ENV: ${{ needs.metadata.outputs.release_env }}
run: |
set -euo pipefail
tags="${IMAGE_NAME}:${VERSION}"
if [[ "${RELEASE_ENV}" == "prod" ]]; then
tags="${tags},${IMAGE_NAME}:prod,${IMAGE_NAME}:latest"
else
tags="${tags},${IMAGE_NAME}:dev"
fi
echo "tags=${tags}" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: enterprise/admin/Dockerfile
target: production
platforms: linux/amd64
push: true
tags: ${{ steps.tags.outputs.tags }}
build-args: |
VITE_VERSION=${{ needs.metadata.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Log published images
run: |
echo "Published enterprise-admin images:"
IFS=',' read -ra TAGS <<< "${{ steps.tags.outputs.tags }}"
for tag in "${TAGS[@]}"; do
echo " → ${tag}"
done