-
Notifications
You must be signed in to change notification settings - Fork 1
221 lines (184 loc) · 7.61 KB
/
release.yml
File metadata and controls
221 lines (184 loc) · 7.61 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
209
210
211
212
213
214
215
216
217
218
219
220
221
name: Release PR
on:
workflow_dispatch:
inputs:
version_type:
description: 'Version type (used by create-release-pr only)'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
release_notes:
description: 'Release notes (used by create-release-pr only)'
required: false
type: string
publish_directly:
description: 'Skip PR creation and publish the version already in version.rb directly'
required: false
default: false
type: boolean
prerelease:
description: 'Mark the GitHub Release as a pre-release (used when publish_directly is true)'
required: false
default: false
type: boolean
push:
branches: [ main, master ]
jobs:
create-release-pr:
name: Create Release PR
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' && github.event.inputs.publish_directly != 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1.0'
- name: Install dependencies
run: bundle install --jobs 4 --retry 3
- name: Get current version
id: current_version
run: |
CURRENT_VERSION=$(ruby -r "./lib/getstream_ruby/version.rb" -e "puts GetStreamRuby::VERSION")
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
- name: Calculate new version
id: new_version
run: |
CURRENT_VERSION="${{ steps.current_version.outputs.current_version }}"
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
case "${{ github.event.inputs.version_type }}" in
"major")
NEW_VERSION="$((major + 1)).0.0"
;;
"minor")
NEW_VERSION="$major.$((minor + 1)).0"
;;
"patch")
NEW_VERSION="$major.$minor.$((patch + 1))"
;;
esac
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Create release branch
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
RELEASE_BRANCH="release/v$NEW_VERSION"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git checkout -b "$RELEASE_BRANCH"
echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> $GITHUB_ENV
- name: Update version files
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
sed -i "s/VERSION = '[^']*'/VERSION = '$NEW_VERSION'/" "lib/getstream_ruby/version.rb"
- name: Update CHANGELOG
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
VERSION_TYPE="${{ github.event.inputs.version_type }}"
RELEASE_NOTES="${{ github.event.inputs.release_notes }}"
if [ ! -f "CHANGELOG.md" ]; then
echo "# Changelog" > "CHANGELOG.md"
echo "" >> "CHANGELOG.md"
echo "All notable changes to this project will be documented in this file." >> "CHANGELOG.md"
echo "" >> "CHANGELOG.md"
echo "The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)," >> "CHANGELOG.md"
echo "and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)." >> "CHANGELOG.md"
echo "" >> "CHANGELOG.md"
fi
TEMP_FILE=$(mktemp)
echo "## [$NEW_VERSION] - $(date +%Y-%m-%d)" >> "$TEMP_FILE"
echo "" >> "$TEMP_FILE"
if [ -n "$RELEASE_NOTES" ]; then
echo "$RELEASE_NOTES" >> "$TEMP_FILE"
else
echo "### $VERSION_TYPE^2 changes" >> "$TEMP_FILE"
echo "- " >> "$TEMP_FILE"
fi
echo "" >> "$TEMP_FILE"
cat "CHANGELOG.md" >> "$TEMP_FILE"
mv "$TEMP_FILE" "CHANGELOG.md"
- name: Commit and push changes
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
VERSION_TYPE="${{ github.event.inputs.version_type }}"
RELEASE_NOTES="${{ github.event.inputs.release_notes }}"
git add lib/getstream_ruby/version.rb CHANGELOG.md
git commit -m "Bump version to $NEW_VERSION
Version type: $VERSION_TYPE
Release notes: ${RELEASE_NOTES:-'Standard $VERSION_TYPE release'}"
git push -u origin "$RELEASE_BRANCH" --force
- name: Create Pull Request
uses: actions/github-script@v7
with:
script: |
const NEW_VERSION = '${{ steps.new_version.outputs.new_version }}';
const VERSION_TYPE = '${{ github.event.inputs.version_type }}';
const RELEASE_NOTES = '${{ github.event.inputs.release_notes }}';
const RELEASE_BRANCH = '${{ env.RELEASE_BRANCH }}';
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Release v${NEW_VERSION}`,
head: RELEASE_BRANCH,
base: 'master',
body: `## Release v${NEW_VERSION}
**Version Type:** ${VERSION_TYPE}
**Release Notes:**
${RELEASE_NOTES || 'Standard ' + VERSION_TYPE + ' release'}
This PR will automatically create a release when merged.
### Changes
- [x] Bumped version to ${NEW_VERSION}
- [x] Updated CHANGELOG.md
- [x] Updated version.rb (gemspec loads version dynamically)
**⚠️ Only repository admins should merge this PR**`
});
release:
name: Release
runs-on: ubuntu-latest
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_directly == 'true')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1.0'
- name: Install dependencies
run: bundle install --jobs 4 --retry 3
- name: Get version
id: version
run: |
VERSION=$(ruby -r "./lib/getstream_ruby/version.rb" -e "puts GetStreamRuby::VERSION")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Run tests
run: make test
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.version }}
release_name: Release v${{ steps.version.outputs.version }}
body: |
## Changes in v${{ steps.version.outputs.version }}
See CHANGELOG.md for details.
draft: false
prerelease: ${{ github.event.inputs.prerelease == 'true' }}
- name: Build and publish gem
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: |
gem build getstream-ruby.gemspec
gem push getstream-ruby-${{ steps.version.outputs.version }}.gem --key $GEM_HOST_API_KEY