-
Notifications
You must be signed in to change notification settings - Fork 3
208 lines (186 loc) · 7.07 KB
/
Copy pathapp-release.yml
File metadata and controls
208 lines (186 loc) · 7.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
196
197
198
199
200
201
202
203
204
205
206
207
208
name: App Release (reusable)
# Generalized release workflow for apps built on Eclipse Docks: publishes a GitHub
# Release for a vX.Y.Z tag (see @eclipse-docks/cli's `docks release` command), then
# optionally builds and deploys the app to GitHub Pages.
#
# Prefer triggering from a Release workflow after CI succeeds on main, passing
# `version`. Tag-push callers may omit `version` and rely on GITHUB_REF instead.
#
# on:
# workflow_run:
# workflows: [CI]
# types: [completed]
#
# jobs:
# resolve:
# if: github.event.workflow_run.conclusion == 'success'
# ...
#
# release:
# needs: resolve
# uses: eclipse-docks/core/.github/workflows/app-release.yml@main
# with:
# version: ${{ needs.resolve.outputs.version }}
# base_path: /my-app/
# publish_dir: ./packages/app/dist
# secrets: inherit
on:
workflow_call:
inputs:
base_path:
description: "Public base path passed to the build as VITE_BASE_PATH (e.g. /my-app/)"
type: string
default: /
publish_dir:
description: "Build output directory to publish to GitHub Pages"
type: string
default: ./dist
build_command:
description: "Command used to build the app"
type: string
default: npm run build
node_version:
description: "Node.js version to use (ignored if node_version_file is set)"
type: string
default: "24"
node_version_file:
description: "Path to a file (e.g. .nvmrc) to read the Node.js version from instead of node_version"
type: string
default: ""
deploy_pages:
description: "Whether to deploy the built app to GitHub Pages"
type: boolean
default: true
pages_url:
description: "Optional override for the URL shown in the deployment summary (derived from cname if set, otherwise the standard github.io URL)"
type: string
default: ""
cname:
description: "Custom domain to write as a CNAME file into publish_dir (also used to derive the summary URL when pages_url is omitted)"
type: string
default: ""
publish_branch:
description: "Git branch to publish the built app to (created as an orphan branch if it does not exist)"
type: string
default: gh-pages
version:
description: "Release tag (e.g. v1.2.3). When empty, derived from a vX.Y.Z tag push ref."
type: string
default: ""
outputs:
version:
description: "The released version tag (e.g. v1.2.3; empty if this run was not triggered by a release tag)"
value: ${{ jobs.release.outputs.version }}
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Resolve release tag and notes
id: version
run: |
TAG="${{ inputs.version }}"
if [ -z "$TAG" ]; then
TAG="${GITHUB_REF#refs/tags/}"
fi
echo "Release tag: $TAG"
if ! printf '%s\n' "$TAG" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Not a release tag: $TAG"
echo "version=" >> $GITHUB_OUTPUT
exit 0
fi
if ! git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Error: Tag $TAG not found in repository"
exit 1
fi
echo "version=$TAG" >> $GITHUB_OUTPUT
BODY=$(git tag -l "$TAG" --format='%(contents)')
FIRST_LINE=$(printf '%s\n' "$BODY" | head -n1)
if [ "$FIRST_LINE" = "$TAG" ]; then
RELEASE_BODY=$(printf '%s\n' "$BODY" | tail -n +2)
else
RELEASE_BODY="$BODY"
fi
if [ -z "$(printf '%s' "$RELEASE_BODY" | tr -d '[:space:]')" ]; then
RELEASE_BODY=""
fi
{
echo "release_body<<EOF"
printf '%s\n' "$RELEASE_BODY"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Create Release
if: steps.version.outputs.version != ''
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.version.outputs.version }}
name: Release ${{ steps.version.outputs.version }}
body: ${{ steps.version.outputs.release_body }}
draft: false
prerelease: false
make_latest: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deploy:
needs: release
if: inputs.deploy_pages && needs.release.outputs.version != ''
runs-on: ubuntu-latest
steps:
- name: Checkout release tag
uses: actions/checkout@v7
with:
ref: ${{ needs.release.outputs.version }}
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: ${{ inputs.node_version_file == '' && inputs.node_version || '' }}
node-version-file: ${{ inputs.node_version_file }}
cache: npm
- name: Install dependencies
run: npm ci
- name: Set package.json version from release tag
run: |
VERSION="${{ needs.release.outputs.version }}"
npm version --no-commit-hooks --no-git-tag-version "${VERSION#v}" --workspaces
- name: Build app
run: ${{ inputs.build_command }}
env:
VITE_BASE_PATH: ${{ inputs.base_path }}
- name: Add .nojekyll
run: touch "${{ inputs.publish_dir }}/.nojekyll"
- name: Add CNAME
if: inputs.cname != ''
run: echo "${{ inputs.cname }}" > "${{ inputs.publish_dir }}/CNAME"
- name: Ensure publish branch exists
run: |
BRANCH="${{ inputs.publish_branch }}"
if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
echo "Branch $BRANCH already exists"
exit 0
fi
echo "Creating orphan branch $BRANCH"
EMPTY_TREE=$(git hash-object -t tree /dev/null)
COMMIT=$(git commit-tree "$EMPTY_TREE" -m "Initialize $BRANCH")
git push origin "$COMMIT:refs/heads/$BRANCH"
echo "Created orphan branch $BRANCH at $COMMIT"
- name: Deploy to GitHub Pages branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ${{ inputs.publish_dir }}
publish_branch: ${{ inputs.publish_branch }}
- name: Deployment summary
run: |
echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Release**: ${{ needs.release.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Branch**: ${{ inputs.publish_branch }}" >> $GITHUB_STEP_SUMMARY
echo "- **URL**: ${{ inputs.pages_url || (inputs.cname != '' && format('https://{0}', inputs.cname)) || format('https://{0}.github.io/{1}/', github.repository_owner, github.event.repository.name) }}" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY