-
Notifications
You must be signed in to change notification settings - Fork 0
172 lines (153 loc) · 4.98 KB
/
Copy pathrelease.yml
File metadata and controls
172 lines (153 loc) · 4.98 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
name: Release Pipeline
on:
workflow_dispatch:
inputs:
mode:
description: "Choose whether to create a new tagged release or deploy an existing tag"
required: true
type: choice
default: release
options:
- release
- deploy-existing-tag
version:
description: "Version without the v prefix (examples: 1.2.0, 1.2.0-rc.1)"
required: true
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: release-pages
cancel-in-progress: false
jobs:
validate:
runs-on: ubuntu-latest
outputs:
tag_name: ${{ steps.meta.outputs.tag_name }}
source_ref: ${{ steps.meta.outputs.source_ref }}
is_prerelease: ${{ steps.meta.outputs.is_prerelease }}
should_create_release: ${{ steps.meta.outputs.should_create_release }}
steps:
- name: Validate version format
env:
VERSION: ${{ inputs.version }}
run: |
python - <<'PY'
import os, re, sys
version = os.environ["VERSION"]
pattern = r"\d+\.\d+\.\d+(?:-(?:alpha|beta|rc)\.\d+)?"
if not re.fullmatch(pattern, version):
print(f"Invalid version: {version}")
print("Expected formats: 1.2.0, 1.2.0-alpha.1, 1.2.0-beta.1, 1.2.0-rc.1")
sys.exit(1)
PY
- name: Restrict new releases to main
if: inputs.mode == 'release'
run: |
if [[ "${{ github.ref_name }}" != "main" ]]; then
echo "New releases must be dispatched from the main branch."
exit 1
fi
- name: Checkout repository metadata
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve release metadata
id: meta
env:
MODE: ${{ inputs.mode }}
VERSION: ${{ inputs.version }}
DISPATCH_REF: ${{ github.ref_name }}
run: |
TAG_NAME="v${VERSION}"
if [[ "$MODE" == "release" ]]; then
if git ls-remote --exit-code --tags origin "refs/tags/${TAG_NAME}" >/dev/null 2>&1; then
echo "Tag ${TAG_NAME} already exists on origin."
exit 1
fi
SOURCE_REF="${GITHUB_SHA}"
SHOULD_CREATE_RELEASE=true
else
if ! git ls-remote --exit-code --tags origin "refs/tags/${TAG_NAME}" >/dev/null 2>&1; then
echo "Tag ${TAG_NAME} does not exist on origin."
exit 1
fi
SOURCE_REF="${TAG_NAME}"
SHOULD_CREATE_RELEASE=false
fi
if [[ "$VERSION" == *-* ]]; then
IS_PRERELEASE=true
else
IS_PRERELEASE=false
fi
{
echo "tag_name=${TAG_NAME}"
echo "source_ref=${SOURCE_REF}"
echo "is_prerelease=${IS_PRERELEASE}"
echo "should_create_release=${SHOULD_CREATE_RELEASE}"
} >> "$GITHUB_OUTPUT"
build:
runs-on: ubuntu-latest
needs: validate
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.validate.outputs.source_ref }}
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Set Eleventy path prefix
run: |
REPO_NAME="${GITHUB_REPOSITORY#*/}"
if [[ "$REPO_NAME" == *.github.io ]]; then
echo "ELEVENTY_PATH_PREFIX=/" >> "$GITHUB_ENV"
else
echo "ELEVENTY_PATH_PREFIX=/${REPO_NAME}/" >> "$GITHUB_ENV"
fi
- run: npm ci
- run: npm run build:css
- run: npx eleventy --pathprefix="$ELEVENTY_PATH_PREFIX"
- run: npm run check
- uses: actions/upload-pages-artifact@v3
with:
path: _site
release:
runs-on: ubuntu-latest
needs: [validate, build]
if: needs.validate.outputs.should_create_release == 'true'
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create and push tag
env:
TAG_NAME: ${{ needs.validate.outputs.tag_name }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git fetch --tags origin
git tag "$TAG_NAME" "$GITHUB_SHA"
git push origin "$TAG_NAME"
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.validate.outputs.tag_name }}
generate_release_notes: true
prerelease: ${{ needs.validate.outputs.is_prerelease == 'true' }}
deploy:
runs-on: ubuntu-latest
needs: [validate, build, release]
if: |
always() &&
needs.build.result == 'success' &&
(needs.release.result == 'success' || needs.release.result == 'skipped')
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4