-
Notifications
You must be signed in to change notification settings - Fork 1
200 lines (169 loc) · 6.86 KB
/
publish-release.yaml
File metadata and controls
200 lines (169 loc) · 6.86 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
---
name: Publish New Package Version
on:
workflow_dispatch:
inputs:
package:
type: choice
description: Package name
options:
- offchain-manager
- addresses
- indexer
- mint-manager
version:
type: string
description: "version"
publish:
type: boolean
description: Publish to npm
default: false
changelog:
type: string
description: "Changelog (required if publishing, markdown format, do NOT include version or date header. Use sections like ### Added, ### Changed, etc.)"
default: ""
discord_notify:
type: boolean
description: "If checked, the release will notify on discord"
default: false
jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: "https://registry.npmjs.org/"
- name: Read previous version from package.json
id: previous-version
working-directory: packages/${{ inputs.package }}
run: |
version=$(jq -r '.version' package.json)
echo "Previous version: $version"
echo "version=$version" >> $GITHUB_OUTPUT
- name: Extract new version from input
id: current-version
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
# Ensure semver format
if [[ ! "$INPUT_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then
echo "❌ Invalid version format. Must follow semantic versioning (e.g., 1.2.3 or 1.2.3-suffix)"
exit 1
fi
version="${{ inputs.version }}"
echo "Current version: $version"
echo "version=$version" >> $GITHUB_OUTPUT
- name: Check valid version increase
uses: aleoyakas/check-semver-increased-action@v1
id: check-version
with:
current-version: ${{ steps.current-version.outputs.version }}
previous-version: ${{ steps.previous-version.outputs.version }}
- name: Fail if version not increased
if: steps.check-version.outputs.is-version-increased != 'true'
run: |
echo "❌ Version has not increased. Please bump the version above ${{ steps.previous-version.outputs.version }}"
exit 1
- name: Install dependencies
run: npm ci
# Ensure registry version of addresses is installed for mint-manager builds
- name: Ensure registry @thenamespace/addresses for mint-manager
if: ${{ inputs.package == 'mint-manager' }}
run: npm install -w @thenamespace/mint-manager @thenamespace/addresses@^1.0.15
- name: Build selected package
working-directory: packages/${{ inputs.package }}
run: npm run build
- name: Update package version in package.json
working-directory: packages/${{ inputs.package }}
run: |
npm version ${{ inputs.version }} --no-git-tag-version
- name: Validate changelog if publishing
if: ${{ inputs.publish == true }}
run: |
if [ -z "${{ inputs.changelog }}" ]; then
echo "❌ Changelog is required when publishing."
exit 1
fi
- name: Publish package to npm registry
if: ${{ inputs.publish == true }}
working-directory: packages/${{ inputs.package }}
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Commit and push version bump and tag
if: ${{ inputs.publish == true }}
env:
VERSION: ${{ inputs.version }}
CHANGELOG: ${{ inputs.changelog }}
PACKAGE: ${{ inputs.package }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
echo "📝 Inserting changelog for $VERSION"
FILE="changelog/${PACKAGE}-changelog.md"
TEMP_FILE="${FILE}.tmp"
DATE=$(date +'%Y-%m-%d')
HEADER="## [${VERSION}] - ${DATE}"
if [ ! -f "$FILE" ]; then
echo -e "# Changelog\n" > "$FILE"
fi
# Find the line number of the "# Changelog" header
HEADER_LINE=$(grep -n "^# Changelog" "$FILE" | cut -d: -f1)
if [ -z "$HEADER_LINE" ]; then
# If not found, just prepend
HEADER_LINE=0
fi
# Find the line number after the intro section (after the first blank line following '# Changelog')
INTRO_END_LINE=$(awk '/^# Changelog/{flag=1; next} flag && /^$/{print NR; exit}' "$FILE")
if [ -z "$INTRO_END_LINE" ]; then
# Fallback: if not found, use header line
HEADER_LINE=$(grep -n "^# Changelog" "$FILE" | cut -d: -f1)
if [ -z "$HEADER_LINE" ]; then
HEADER_LINE=0
fi
INTRO_END_LINE=$((HEADER_LINE + 1))
fi
# Process the changelog input to ensure proper formatting
# Handle both multi-line and single-line input from GitHub UI
PRETTY_CHANGELOG=$(echo "$CHANGELOG" | sed -E 's/\\n/\n/g' | sed -E 's/\\1/\n/g' | sed -E 's/^[[:space:]]*//' | sed -E 's/[[:space:]]*$//')
# Write up to and including the intro
if [ "$INTRO_END_LINE" -gt 0 ]; then
head -n "$INTRO_END_LINE" "$FILE" > "$TEMP_FILE"
fi
# Add the new entry
echo -e "\n${HEADER}\n\n${PRETTY_CHANGELOG}\n" >> "$TEMP_FILE"
# Add the rest of the file
if [ "$INTRO_END_LINE" -gt 0 ]; then
tail -n "+$((INTRO_END_LINE + 1))" "$FILE" >> "$TEMP_FILE"
fi
mv "$TEMP_FILE" "$FILE"
# Commit the updated package.json with new version
git add packages/$PACKAGE/package.json
git add changelog/*
git commit -m "chore($PACKAGE): bump version to $VERSION"
# Create a tag with the version
TAG="${PACKAGE}-${VERSION}"
git tag -a "$TAG" -m "Release $TAG"
# Push commit and tag
git push origin HEAD
git push origin "$TAG"
- name: Post update to Discord
if: ${{ inputs.discord_notify == true }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK }}
VERSION: ${{ inputs.version }}
CHANGELOG: ${{ inputs.changelog }}
PACKAGE: ${{ inputs.package }}
run: |
MESSAGE="Published a new version of *@thenamespace/${PACKAGE}*, version: \`${VERSION}\`!\n\n📝 ${CHANGELOG}"
curl -X POST -H "Content-Type: application/json" \
-d "{\"content\": \"$MESSAGE\"}" \
"$DISCORD_WEBHOOK_URL"