-
Notifications
You must be signed in to change notification settings - Fork 0
193 lines (163 loc) · 6.97 KB
/
Copy pathrelease.yml
File metadata and controls
193 lines (163 loc) · 6.97 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
name: Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 1.0.0)'
required: true
type: string
env:
MIX_ENV: prod
jobs:
# Create GitHub release
release:
name: Create Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
permissions:
contents: write
outputs:
version: ${{ steps.version.outputs.version }}
tag_version: ${{ steps.version.outputs.tag_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for changelog generation
- name: Extract version
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag_version=v$VERSION" >> $GITHUB_OUTPUT
else
TAG_VERSION="${GITHUB_REF#refs/tags/}"
VERSION="${TAG_VERSION#v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag_version=$TAG_VERSION" >> $GITHUB_OUTPUT
fi
- name: Install mise and tools
uses: jdx/mise-action@v3
with:
install: true
cache: true
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
deps/
_build/
key: ${{ runner.os }}-mix-prod-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ hashFiles('mise.toml') }}
restore-keys: |
${{ runner.os }}-mix-prod-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-
${{ runner.os }}-mix-prod-
- name: Install dependencies
run: mix deps.get
- name: Generate changelog
id: changelog
run: |
VERSION="${{ steps.version.outputs.version }}"
# Find previous tag or use initial commit for first release
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || git rev-list --max-parents=0 HEAD)
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "## What's Changed in v$VERSION" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
# Group commits by type
echo "### ✨ Features" >> $GITHUB_OUTPUT
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD | grep -E "^- (feat|add)" || echo "- No new features" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "### 🐛 Bug Fixes" >> $GITHUB_OUTPUT
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD | grep -E "^- (fix|bug)" || echo "- No bug fixes" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "### 📚 Documentation" >> $GITHUB_OUTPUT
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD | grep -E "^- (docs|doc)" || echo "- No documentation changes" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "### 🔧 Other Changes" >> $GITHUB_OUTPUT
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD | grep -vE "^- (feat|add|fix|bug|docs|doc)" || echo "- No other changes" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "### Installation" >> $GITHUB_OUTPUT
echo "\`\`\`elixir" >> $GITHUB_OUTPUT
echo "def deps do" >> $GITHUB_OUTPUT
echo " [{:turso, \"~> $VERSION\"}]" >> $GITHUB_OUTPUT
echo "end" >> $GITHUB_OUTPUT
echo "\`\`\`" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "**Full Changelog**: [$PREVIOUS_TAG...v$VERSION](https://github.com/${{ github.repository }}/compare/$PREVIOUS_TAG...v$VERSION)" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag_version }}
name: Turso Elixir Client v${{ steps.version.outputs.version }}
body: ${{ steps.changelog.outputs.CHANGELOG }}
draft: false
prerelease: ${{ contains(steps.version.outputs.version, '-') }}
make_latest: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Publish to Hex.pm
publish:
name: Publish to Hex
runs-on: ubuntu-latest
needs: release
if: (startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch') && !contains(needs.release.outputs.version, '-')
env:
MIX_ENV: dev # Override to dev so ex_doc is available
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install mise and tools
uses: jdx/mise-action@v3
with:
install: true
cache: true
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
deps/
_build/
key: ${{ runner.os }}-mix-prod-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ hashFiles('mise.toml') }}
restore-keys: |
${{ runner.os }}-mix-prod-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-
${{ runner.os }}-mix-prod-
- name: Install dependencies
run: mix deps.get
- name: Compile application
run: mix compile --warnings-as-errors
- name: Verify package can be built
run: mix hex.build
- name: Publish to Hex
run: mix hex.publish --yes
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
# Notification and cleanup
notify:
name: Release Notification
runs-on: ubuntu-latest
needs: [release, publish]
if: always() && (startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch')
steps:
- name: Notify release status
run: |
VERSION="${{ needs.release.outputs.version }}"
if [[ "${{ needs.release.result }}" == "success" && "${{ needs.publish.result }}" == "success" ]]; then
echo "✅ Turso Elixir Client v$VERSION successfully released!"
echo "📦 Hex package: https://hex.pm/packages/turso/$VERSION"
echo "📋 GitHub release: https://github.com/${{ github.repository }}/releases/tag/v$VERSION"
echo "📚 Documentation: https://hexdocs.pm/turso/$VERSION"
elif [[ "${{ needs.release.result }}" == "success" && "${{ needs.publish.result }}" == "skipped" ]]; then
echo "✅ Pre-release v$VERSION created on GitHub (Hex publishing skipped for pre-release)"
echo "📋 GitHub release: https://github.com/${{ github.repository }}/releases/tag/v$VERSION"
else
echo "❌ Release pipeline failed for v$VERSION"
echo "Release result: ${{ needs.release.result }}"
echo "Publish result: ${{ needs.publish.result }}"
exit 1
fi