Skip to content

Commit 4674e65

Browse files
committed
update workflow
1 parent d6cf483 commit 4674e65

3 files changed

Lines changed: 57 additions & 215 deletions

File tree

.github/workflows/prepare_release.yml

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

.github/workflows/release.yml

Lines changed: 57 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313
types: [closed]
1414
branches:
1515
- master
16+
- v2
1617

1718
jobs:
1819
create_release:
@@ -22,76 +23,70 @@ jobs:
2223
steps:
2324
- name: Get GitHub App token
2425
id: get_token
25-
uses: actions/create-github-app-token@v1
26+
uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 #v1.11.1
2627
with:
2728
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
2829
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
2930

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 = `datadog-api-client-${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
31+
- name: Checkout ${{ github.event.pull_request.base.ref }}
32+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5233
with:
5334
token: ${{ steps.get_token.outputs.token }}
35+
ref: ${{ github.event.pull_request.base.ref }}
36+
fetch-depth: 0
5437

55-
- name: Setup Git
38+
- name: Release packages
39+
env:
40+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
41+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
42+
GH_TOKEN: ${{ steps.get_token.outputs.token }}
43+
shell: bash
5644
run: |
57-
git config user.name "${GIT_AUTHOR_NAME}"
58-
git config user.email "${GIT_AUTHOR_EMAIL}"
45+
CHANGED_PACKAGE_JSON_FILES=$(git diff --diff-filter=MACR --name-only $BASE_SHA...$HEAD_SHA \
46+
| grep -E 'package\.json$' \
47+
| xargs dirname \
48+
| sort \
49+
| uniq)
5950
60-
- name: Install Java
61-
uses: actions/setup-java@v3
62-
with:
63-
java-version: "8"
64-
distribution: "temurin"
65-
cache: "maven"
51+
declare -A versions
52+
for package in $CHANGED_PACKAGE_JSON_FILES; do
53+
base_version=$(git show $BASE_SHA:$package/package.json | jq -r .version)
54+
head_version=$(git show $HEAD_SHA:$package/package.json | jq -r .version)
6655
67-
- name: Bump version
68-
run: |
69-
git switch -c "${POST_RELEASE_BRANCH}"
70-
mvn --batch-mode release:update-versions
71-
git commit -a -m "Post release bump"
72-
git push -f --set-upstream origin "${POST_RELEASE_BRANCH}"
73-
env:
74-
POST_RELEASE_BRANCH: post-${{ github.head_ref }}
56+
if [ "$base_version" != "$head_version" ]; then
57+
versions[$package]=$head_version
58+
fi
59+
done
7560
76-
- name: Create PR
77-
uses: actions/github-script@v6
78-
env:
79-
POST_RELEASE_BRANCH: post-${{ github.head_ref }}
80-
BASE: master
81-
with:
82-
github-token: ${{ steps.get_token.outputs.token }}
83-
script: |
84-
const { data: pr } = await github.rest.pulls.create({
85-
owner: context.repo.owner,
86-
repo: context.repo.repo,
87-
head: process.env.POST_RELEASE_BRANCH,
88-
base: process.env.BASE,
89-
title: "Post release",
90-
body: "Bump to dev version",
91-
});
92-
await github.rest.issues.addLabels({
93-
issue_number: pr.number,
94-
owner: context.repo.owner,
95-
repo: context.repo.repo,
96-
labels: ["changelog/no-changelog"],
97-
});
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="datadog-api-client-${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 & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)