-
Notifications
You must be signed in to change notification settings - Fork 9
162 lines (134 loc) · 5.06 KB
/
release.yml
File metadata and controls
162 lines (134 loc) · 5.06 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g., v1.1.0)"
required: true
type: string
update-major:
description: "Update major version tag (e.g., v1)"
required: true
type: boolean
default: true
jobs:
release:
runs-on: blacksmith-4vcpu-ubuntu-2404
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Validate version format
run: |
VERSION="${{ github.event.inputs.version }}"
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
echo "Error: Version must be in format vX.Y.Z or vX.Y.Z-prerelease"
echo "Examples: v1.1.0, v1.2.0-beta.1"
exit 1
fi
echo "Version format is valid: $VERSION"
- name: Check if version already exists
run: |
VERSION="${{ github.event.inputs.version }}"
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "Error: Tag $VERSION already exists"
exit 1
fi
echo "Version $VERSION is available"
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 8.15.9
- name: Setup buf
uses: bufbuild/buf-setup-action@v1
with:
github_token: ${{ github.token }}
- name: Configure npm for buf registry
env:
BUF_TOKEN: ${{ secrets.BUF_TOKEN }}
run: |
npm config set @buf:registry https://buf.build/gen/npm/v1/
npm config set //buf.build/gen/npm/v1/:_authToken "$BUF_TOKEN"
- name: Install dependencies
run: pnpm install
- name: Run tests
run: pnpm test
- name: Build
run: pnpm run build
- name: Configure git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Create semver tag
run: |
VERSION="${{ github.event.inputs.version }}"
git tag -a "$VERSION" -m "Release $VERSION"
git push origin "$VERSION"
echo "Created and pushed tag: $VERSION"
- name: Update major version tag
if: github.event.inputs.update-major
run: |
VERSION="${{ github.event.inputs.version }}"
# Extract major version (e.g., v1 from v1.2.3)
MAJOR_VERSION=$(echo "$VERSION" | grep -oE '^v[0-9]+')
echo "Updating major version tag: $MAJOR_VERSION"
# Delete remote tag if it exists
git push origin ":refs/tags/$MAJOR_VERSION" 2>/dev/null || true
# Create and push the major version tag
git tag -fa "$MAJOR_VERSION" -m "Update $MAJOR_VERSION to $VERSION"
git push --force origin "$MAJOR_VERSION"
echo "Updated and pushed tag: $MAJOR_VERSION -> $VERSION"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ github.event.inputs.version }}"
# Get the previous semver tag (v*.*.*, not v1/v2 major tags)
# This ensures predictable comparisons by excluding major version tags
PREVIOUS_TAG=$(git tag -l 'v*.*.*' --sort=-version:refname | grep -v "^$VERSION$" | head -n 1 || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
echo "No previous tag found, generating notes from all commits"
gh release create "$VERSION" \
--title "$VERSION" \
--generate-notes
else
echo "Generating release notes from $PREVIOUS_TAG to $VERSION"
gh release create "$VERSION" \
--title "$VERSION" \
--generate-notes \
--notes-start-tag "$PREVIOUS_TAG"
fi
echo "Created GitHub release: $VERSION"
- name: Summary
run: |
VERSION="${{ github.event.inputs.version }}"
MAJOR_VERSION=$(echo "$VERSION" | grep -oE '^v[0-9]+')
{
echo "## Release Summary"
echo ""
echo "✅ Successfully released **$VERSION**"
echo ""
echo "### Tags Created"
echo "- \`$VERSION\` (semver tag)"
if [[ "${{ github.event.inputs.update-major }}" == "true" ]]; then
echo "- \`$MAJOR_VERSION\` (major version tag, updated)"
fi
echo ""
echo "### Usage"
echo ""
echo "Users can now reference this action using:"
echo '```yaml'
echo "- uses: useblacksmith/setup-docker-builder@$MAJOR_VERSION"
echo "- uses: useblacksmith/setup-docker-builder@$VERSION"
echo '```'
echo ""
echo "🔗 [View Release](https://github.com/${{ github.repository }}/releases/tag/$VERSION)"
} >> "$GITHUB_STEP_SUMMARY"