Skip to content

Commit dc1058b

Browse files
committed
Bump version
1 parent e1c3be1 commit dc1058b

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

.github/workflows/publish.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,49 @@ jobs:
138138
gh release upload "v${GEM_VERSION}" *.gem --clobber
139139
gh release edit "v${GEM_VERSION}" --draft=false
140140
141-
update-document:
141+
bump-version-pull-request:
142+
if: github.ref_name == 'master'
143+
runs-on: ubuntu-24.04
144+
needs:
145+
- verify-checks
146+
- rubygems-release
147+
env:
148+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149+
GEM_VERSION: ${{ needs.verify-checks.outputs.version }}
150+
151+
permissions:
152+
contents: write
153+
pull-requests: write
154+
155+
steps:
156+
- uses: actions/checkout@v4
157+
with:
158+
fetch-depth: 0
159+
- run: bundle install
160+
- run: |
161+
git config user.name "${{ github.actor }}"
162+
git config user.email "${{ github.actor }}@users.noreply.github.com"
163+
- run: |
164+
git checkout -b version-bump-from-${{ github.job }}
165+
- id: next_version
166+
run: |
167+
echo "next_version=$(bundle exec rake version:bump)" >> $GITHUB_OUTPUT
168+
- name: Commit and push changes
169+
run: |
170+
git add .
171+
git commit -m "Bump version to ${{ steps.next_version.outputs.next_version }}"
172+
git push origin
173+
- name: Create Pull Request
174+
run: |
175+
JOB_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs/${{ github.job }}"
176+
177+
gh pr create \
178+
--title "Bump version to ${{ steps.next_version.outputs.next_version }}" \
179+
--body "This is an auto-generated PR for bumping version from [here](${JOB_URL}). Please merge (with a merge commit) when ready." \
180+
--base master \
181+
--head version-bump-from-${{ github.job }}
182+
183+
document-pull-request:
142184
if: github.ref_name == 'master'
143185
runs-on: ubuntu-24.04
144186
needs:

tasks/version.rake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace :version do
2+
task :bump do
3+
gemspec = Gem::Specification.load(Dir.glob('*.gemspec').first)
4+
5+
gem_name = gemspec.name
6+
current_version = gemspec.version
7+
8+
next_version =
9+
if current_version.prerelease?
10+
# If prerelease, return the release version (ie. 2.0.0.beta1 -> 2.0.0)
11+
current_version.release
12+
else
13+
# When releasing from `master` branch, return the next minor version (ie. 2.0.0 -> 2.1.0)
14+
major, minor, = current_version.segments
15+
Gem::Version.new([major, minor.succ, 0].join(".")).to_s
16+
end
17+
18+
major, minor, patch, pre = next_version.to_s.split(".")
19+
20+
replace_version(/MAJOR = \d+/, "MAJOR = #{major}") if major
21+
replace_version(/MINOR = \d+/, "MINOR = #{minor}") if minor
22+
replace_version(/PATCH = \d+/, "PATCH = #{patch}") if patch
23+
# If we allows double quote string without interpolation in style => use "PRE = #{pre.inspect}" instead
24+
if pre
25+
replace_version(/PRE = \S+/, "PRE = '#{pre}'")
26+
else
27+
replace_version(/PRE = \S+/, "PRE = nil")
28+
end
29+
30+
# Update the versions under gemfiles/
31+
sh "perl -p -i -e 's/\\b#{gem_name} \\(\\d+\\.\\d+\\.\\d+[^)]*\\)/#{gem_name} (#{next_version})/' gemfiles/*.lock"
32+
33+
$stdout.puts next_version
34+
end
35+
36+
def replace_version(find_pattern, replace_str)
37+
version_file = 'lib/datadog/version.rb'
38+
content = File.read(version_file)
39+
content.sub!(find_pattern, replace_str)
40+
File.write(version_file, content)
41+
end
42+
end

0 commit comments

Comments
 (0)