Skip to content

Post release automation #4354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 134 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
attestations: false # PENDING decision for attestations

github-release:
name: Attach gem to GitHub release and publish
name: Attach gem to Github Release and publish
runs-on: ubuntu-24.04
needs:
- verify-checks
Expand All @@ -138,15 +138,147 @@ jobs:
gh release upload "v${GEM_VERSION}" *.gem --clobber
gh release edit "v${GEM_VERSION}" --draft=false

update-document:
update-gem-version:
if: github.ref_name == 'master'
name: Pull request to update gem version
runs-on: ubuntu-24.04
needs:
- verify-checks
- rubygems-release
env:
GITHUB_TOKEN: ${{ secrets.GHA_PAT }}
GEM_VERSION: ${{ needs.verify-checks.outputs.version }}
outputs:
next_version: ${{ steps.next_version.outputs.next_version }}
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- run: bundle install
- run: |
git checkout -b version-bump-from-${{ github.job }}
- id: next_version
run: |
echo "next_version=$(bundle exec rake version:bump)" >> $GITHUB_OUTPUT
- name: Commit and push changes
run: |
git add .
git commit -m "Bump version to ${{ steps.next_version.outputs.next_version }}"
git push origin
- name: Create Pull Request
run: |
JOB_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs/${{ github.job }}"

gh pr create \
--title "Bump version to ${{ steps.next_version.outputs.next_version }}" \
--body "This is an auto-generated PR for bumping version from [here](${JOB_URL}). Please merge (with a merge commit) when ready." \
--base master \
--head version-bump-from-${{ github.job }}

# https://docs.github.com/en/rest/issues/milestones?apiVersion=2022-11-28
milestone:
if: github.ref_name == 'master'
name: Open/Close Github milestones
runs-on: ubuntu-24.04
needs:
- verify-checks
- rubygems-release
- update-gem-version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GEM_VERSION: ${{ needs.verify-checks.outputs.version }}
NEXT_VERSION: ${{ needs.update-gem-version.outputs.next_version }}
permissions:
issues: write
pull-requests: write
steps:
- name: list milestones
id: milestones
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
// https://octokit.github.io/rest.js/v21/#issues-list-milestones
// https://docs.github.com/en/rest/issues/milestones?apiVersion=2022-11-28#list-milestones
const milestones = await github.rest.issues.listMilestones({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
});
return milestones.data;

- name: Close milestone
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const milestones = ${{steps.milestones.outputs.result}}

const milestone = milestones.data.find(
m => m.title === process.env.GEM_VERSION
);

if (!milestone) {
console.log(`No open milestone found with version ${process.env.GEM_VERSION} - skipping close operation`);
return;
}

// https://octokit.github.io/rest.js/v21/#issues-update-milestone
// https://docs.github.com/en/rest/issues/milestones?apiVersion=2022-11-28#update-a-milestone
try {
await github.rest.issues.updateMilestone({
owner: context.repo.owner,
repo: context.repo.repo,
milestone_number: milestone.number,
state: 'closed'
});
console.log(`Successfully closed milestone: ${process.env.GEM_VERSION}`);
} catch (error) {
core.setFailed(`Failed to close milestone: ${error.message}`);
}

- name: Create milestone
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const milestones = ${{steps.milestones.outputs.result}}

const milestone = milestones.data.find(
m => m.title === process.env.NEXT_VERSION
);

if (milestone) {
console.log(`Milestone "${process.env.NEXT_VERSION}" already exists - skipping creation`);
return;
}

// https://octokit.github.io/rest.js/v21/#issues-create-milestone
// https://docs.github.com/en/rest/issues/milestones?apiVersion=2022-11-28#create-a-milestone
try {
await github.rest.issues.createMilestone({
owner: context.repo.owner,
repo: context.repo.repo,
title: process.env.NEXT_VERSION
});
console.log(`Successfully created milestone: ${process.env.NEXT_VERSION}`);
} catch (error) {
core.setFailed(`Failed to create milestone: ${error.message}`);
}

update-release-branch:
if: github.ref_name == 'master'
name: Pull request to update 'release' branch
runs-on: ubuntu-24.04
needs:
- verify-checks
- rubygems-release
permissions:
issues: write
pull-requests: write
env:
GITHUB_TOKEN: ${{ secrets.GHA_PAT }}
GEM_VERSION: ${{ needs.verify-checks.outputs.version }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
Expand All @@ -160,5 +292,3 @@ jobs:
--title "Update document v${GEM_VERSION}" \
--body "This is an auto-generated PR to update documentation from [here](${JOB_URL}). Please merge (with a merge commit) when ready." \
--label "docs"

# TODO: Close existing milestone and create next milestone
42 changes: 42 additions & 0 deletions tasks/version.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace :version do
task :bump do
gemspec = Gem::Specification.load(Dir.glob('*.gemspec').first)

gem_name = gemspec.name
current_version = gemspec.version

next_version =
if current_version.prerelease?
# If prerelease, return the release version (ie. 2.0.0.beta1 -> 2.0.0)
current_version.release
else
# When releasing from `master` branch, return the next minor version (ie. 2.0.0 -> 2.1.0)
major, minor, = current_version.segments
Gem::Version.new([major, minor.succ, 0].join(".")).to_s
end

major, minor, patch, pre = next_version.to_s.split(".")

replace_version(/MAJOR = \d+/, "MAJOR = #{major}") if major
replace_version(/MINOR = \d+/, "MINOR = #{minor}") if minor
replace_version(/PATCH = \d+/, "PATCH = #{patch}") if patch
# If we allows double quote string without interpolation in style => use "PRE = #{pre.inspect}" instead
if pre
replace_version(/PRE = \S+/, "PRE = '#{pre}'")
else
replace_version(/PRE = \S+/, "PRE = nil")
end

# Update the versions under gemfiles/
sh "perl -p -i -e 's/\\b#{gem_name} \\(\\d+\\.\\d+\\.\\d+[^)]*\\)/#{gem_name} (#{next_version})/' gemfiles/*.lock"

$stdout.puts next_version
end

def replace_version(find_pattern, replace_str)
version_file = 'lib/datadog/version.rb'
content = File.read(version_file)
content.sub!(find_pattern, replace_str)
File.write(version_file, content)
end
end
Loading