-
Notifications
You must be signed in to change notification settings - Fork 5
133 lines (115 loc) · 4.33 KB
/
create-github-release.yml
File metadata and controls
133 lines (115 loc) · 4.33 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
name: Create GitHub Release
on:
push:
tags:
- "monitor-app-v*"
- "next-cwv-monitor-v*"
workflow_dispatch:
inputs:
tag:
description: "Tag name (e.g. monitor-app-v1.1.0)"
required: true
type: string
workflow_call:
inputs:
tag:
description: "Tag name (e.g. monitor-app-v1.1.0)"
required: true
type: string
permissions:
contents: write
jobs:
create_release:
runs-on: ubuntu-latest
steps:
- name: Resolve tag metadata
id: vars
run: |
TAG="${{ inputs.tag }}"
if [ -z "$TAG" ]; then
TAG="${GITHUB_REF_NAME}"
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
if [[ "$TAG" == monitor-app-v* ]]; then
VERSION="${TAG#monitor-app-v}"
NAME="monitor-app"
CHANGELOG_PATH="apps/monitor-app/CHANGELOG.md"
RELEASE_TITLE="Next CWV Monitor (Self-hosted) v${VERSION}"
elif [[ "$TAG" == next-cwv-monitor-v* ]]; then
VERSION="${TAG#next-cwv-monitor-v}"
NAME="next-cwv-monitor"
CHANGELOG_PATH="packages/client-sdk/CHANGELOG.md"
RELEASE_TITLE="Next CWV Monitor SDK v${VERSION}"
else
echo "Unsupported tag: $TAG"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "name=$NAME" >> "$GITHUB_OUTPUT"
echo "changelog=$CHANGELOG_PATH" >> "$GITHUB_OUTPUT"
echo "release_title=$RELEASE_TITLE" >> "$GITHUB_OUTPUT"
- name: Checkout tag
uses: actions/checkout@v4
with:
ref: ${{ steps.vars.outputs.tag }}
fetch-depth: 0
- name: Build release notes
id: notes
run: |
TAG="${{ steps.vars.outputs.tag }}"
VERSION="${{ steps.vars.outputs.version }}"
NAME="${{ steps.vars.outputs.name }}"
CHANGELOG="${{ steps.vars.outputs.changelog }}"
awk -v ver="$VERSION" '
$0 ~ "^## " ver "$" {in_section=1; print; next}
in_section && $0 ~ "^## " {exit}
in_section {print}
' "$CHANGELOG" > changelog-section.md
if [ ! -s changelog-section.md ]; then
echo "No changelog section found for $VERSION in $CHANGELOG"
{
echo "## $VERSION"
echo
echo "- See commits for details."
} > changelog-section.md
fi
NOTES_FILE="release-notes.md"
{
echo "## Changelog"
echo
cat changelog-section.md
echo
if [ "$NAME" = "monitor-app" ]; then
MAJOR_MINOR="${VERSION%.*}"
echo "## Docker images"
echo
echo "- \`ghcr.io/${{ github.repository_owner }}/cwv-monitor:${VERSION}\`"
echo "- \`ghcr.io/${{ github.repository_owner }}/cwv-monitor:${MAJOR_MINOR}\`"
echo "- \`ghcr.io/${{ github.repository_owner }}/cwv-monitor:latest\`"
echo
echo "- \`ghcr.io/${{ github.repository_owner }}/cwv-monitor-migrations:${VERSION}\`"
echo "- \`ghcr.io/${{ github.repository_owner }}/cwv-monitor-migrations:${MAJOR_MINOR}\`"
echo "- \`ghcr.io/${{ github.repository_owner }}/cwv-monitor-migrations:latest\`"
echo
echo "- \`ghcr.io/${{ github.repository_owner }}/cwv-monitor-seed:${VERSION}\`"
echo "- \`ghcr.io/${{ github.repository_owner }}/cwv-monitor-seed:${MAJOR_MINOR}\`"
echo "- \`ghcr.io/${{ github.repository_owner }}/cwv-monitor-seed:latest\`"
else
echo "## Install"
echo
echo "\`npm i next-cwv-monitor@${VERSION}\`"
fi
} > "$NOTES_FILE"
echo "notes_file=$NOTES_FILE" >> "$GITHUB_OUTPUT"
- name: Create GitHub Release (if missing)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ steps.vars.outputs.tag }}"
TITLE="${{ steps.vars.outputs.release_title }}"
NOTES_FILE="${{ steps.notes.outputs.notes_file }}"
if gh release view "$TAG" >/dev/null 2>&1; then
echo "Release for $TAG already exists, skipping"
exit 0
fi
gh release create "$TAG" --title "$TITLE" --notes-file "$NOTES_FILE"