Skip to content

Commit 20e57c5

Browse files
authored
[AAWF-420] Update release workflow (#2423)
* Update release workflow * fix version * update workflow * fix publish and release * fix workflow
1 parent 313bb5b commit 20e57c5

File tree

5 files changed

+71
-222
lines changed

5 files changed

+71
-222
lines changed

.github/workflows/prepare_release.yml

Lines changed: 0 additions & 112 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,26 @@ jobs:
1919
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
2020
contents: write # IMPORTANT: this permission is required for `rake release` to push the release tag
2121

22-
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'release' && github.event.action == 'published')
2322
steps:
24-
- uses: actions/checkout@v3
23+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2524
with:
26-
ref: ${{ github.event.release.tag_name }}
25+
fetch-depth: 1
2726

2827
- name: Set up Ruby 3.4.3
2928
uses: ruby/setup-ruby@eaecf785f6a34567a6d97f686bbb7bccc1ac1e5c # v1.237.0
3029
with:
3130
ruby-version: 3.4.3
3231

33-
- run: bundle install
32+
- name: Install dependencies ${{ github.event.release.tag_name }}
33+
run: |
34+
# Get tag name from event
35+
tag_name="${{ github.event.release.tag_name }}"
3436
35-
- name: Publish to RubyGems
37+
if [[ ! "$tag_name" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
38+
cd $(echo $tag_name | rev | cut -d'/' -f2- | rev)
39+
fi
40+
41+
bundle install
42+
43+
- name: Publishing tag ${{ github.event.release.tag_name }} to RubyGems
3644
uses: rubygems/release-gem@a25424ba2ba8b387abc8ef40807c2c85b96cbe32 # v1.1.1

.github/workflows/release.yml

Lines changed: 57 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -22,75 +22,71 @@ jobs:
2222
steps:
2323
- name: Get GitHub App token
2424
id: get_token
25-
uses: actions/create-github-app-token@v1
25+
uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 #v1.11.1
2626
with:
2727
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
2828
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
2929

30-
- name: Create release
31-
uses: actions/github-script@v6
32-
env:
33-
RELEASE_BRANCH: ${{ github.head_ref }}
34-
with:
35-
github-token: ${{ steps.get_token.outputs.token }}
36-
script: |
37-
const tagName = `v${process.env.RELEASE_BRANCH.split("/")[1]}`;
38-
await github.rest.git.createRef({
39-
owner: context.repo.owner,
40-
repo: context.repo.repo,
41-
ref: `refs/tags/${tagName}`,
42-
sha: context.payload.pull_request.merge_commit_sha,
43-
});
44-
await github.rest.repos.createRelease({
45-
owner: context.repo.owner,
46-
repo: context.repo.repo,
47-
generate_release_notes: true,
48-
tag_name: tagName,
49-
});
50-
51-
- uses: actions/checkout@v3
30+
- name: Checkout ${{ github.event.pull_request.base.ref }}
31+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5232
with:
53-
fetch-depth: 0
5433
token: ${{ steps.get_token.outputs.token }}
34+
ref: ${{ github.event.pull_request.base.ref }}
35+
fetch-depth: 0
5536

56-
- name: Setup Git
37+
- name: Release packages
38+
env:
39+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
40+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
41+
GH_TOKEN: ${{ steps.get_token.outputs.token }}
42+
shell: bash
5743
run: |
58-
git config user.name "${GIT_AUTHOR_NAME}"
59-
git config user.email "${GIT_AUTHOR_EMAIL}"
44+
CHANGED_VERSION_RB_FILES=$(git diff --diff-filter=MACR --name-only $BASE_SHA...$HEAD_SHA \
45+
| grep -E 'version\.rb$' \
46+
| xargs dirname | xargs dirname | xargs dirname \
47+
| sort \
48+
| uniq)
6049
61-
- name: Set up Ruby 2.7
62-
uses: ruby/setup-ruby@v1
63-
with:
64-
ruby-version: 2.7
50+
declare -A versions
51+
for package in $CHANGED_VERSION_RB_FILES; do
52+
version_dir=$(find $package/lib/*/version.rb -name "version.rb" | head -n 1)
53+
base_version=$(git show $BASE_SHA:$version_dir | grep "VERSION =" | sed "s/.*'\(.*\)'.*/\1/")
54+
head_version=$(git show $HEAD_SHA:$version_dir | grep "VERSION =" | sed "s/.*'\(.*\)'.*/\1/")
6555
66-
- name: Bump Gem version
67-
run: |
68-
git switch -c "${POST_RELEASE_BRANCH}"
69-
bundle install
70-
bundle exec gem bump -v dev
71-
git push -f --set-upstream origin "${POST_RELEASE_BRANCH}"
72-
env:
73-
POST_RELEASE_BRANCH: post-${{ github.head_ref }}
56+
if [ "$base_version" != "$head_version" ]; then
57+
versions[$package]=$head_version
58+
fi
59+
done
7460
75-
- name: Create PR
76-
uses: actions/github-script@v6
77-
env:
78-
POST_RELEASE_BRANCH: post-${{ github.head_ref }}
79-
BASE: master
80-
with:
81-
github-token: ${{ steps.get_token.outputs.token }}
82-
script: |
83-
const { data: pr } = await github.rest.pulls.create({
84-
owner: context.repo.owner,
85-
repo: context.repo.repo,
86-
head: process.env.POST_RELEASE_BRANCH,
87-
base: process.env.BASE,
88-
title: "Post release",
89-
body: "Bump to dev version",
90-
});
91-
await github.rest.issues.addLabels({
92-
issue_number: pr.number,
93-
owner: context.repo.owner,
94-
repo: context.repo.repo,
95-
labels: ["changelog/no-changelog"],
96-
});
61+
for package in "${!versions[@]}"; do
62+
echo "Releasing $package at version ${versions[$package]}"
63+
64+
# Build the tag name
65+
if [[ "$package" == "." ]]; then
66+
# If the package is the root, use the version as the tag name
67+
tag_name="v${versions[$package]}"
68+
else
69+
# If the package is not the root, use the package name and version as the tag name
70+
tag_name="$package/${versions[$package]}"
71+
fi
72+
73+
# Get the changelog entries since last release
74+
# TODO: Implement this
75+
# changelog_content=$(git diff $BASE_REF...$HEAD_REF -- $package/CHANGELOG.md | grep -A 1000 "^+##" | grep -v "^+++" | sed 's/^+//')
76+
77+
is_prerelease=$(echo $package | grep -q "beta" && echo true || echo false)
78+
# Create the tag
79+
gh api repos/{owner}/{repo}/git/refs \
80+
-f ref="refs/tags/$tag_name" \
81+
-f sha=$HEAD_SHA
82+
83+
# Create the release
84+
gh api repos/{owner}/{repo}/releases --input - << EOF
85+
{
86+
"tag_name": "$tag_name",
87+
"name": "$tag_name",
88+
"body": "See $package/CHANGELOG.md for details",
89+
"prerelease": $is_prerelease
90+
}
91+
EOF
92+
done

RELEASING.md

Lines changed: 0 additions & 43 deletions
This file was deleted.

lib/datadog_api_client/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Define library version.
22

33
module DatadogAPIClient
4-
VERSION = '2.33.0.dev.1'
4+
VERSION = '2.33.0-dev.1'
55
end

0 commit comments

Comments
 (0)