Skip to content

Commit fd8ac8b

Browse files
authored
Copy over release job to v2 branch (#2329)
1 parent 9efa899 commit fd8ac8b

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

.github/workflows/release.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Release
2+
3+
permissions:
4+
contents: write
5+
pull-requests: write
6+
7+
env:
8+
GIT_AUTHOR_EMAIL: "[email protected]"
9+
GIT_AUTHOR_NAME: "ci.datadog-api-spec"
10+
11+
on:
12+
pull_request:
13+
types: [closed]
14+
branches:
15+
- v2
16+
17+
jobs:
18+
create_release:
19+
name: Create release
20+
runs-on: ubuntu-latest
21+
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')
22+
steps:
23+
- name: Get GitHub App token
24+
id: get_token
25+
uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 #v1.11.1
26+
with:
27+
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
28+
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
29+
30+
- name: Checkout ${{ github.event.pull_request.base.ref }}
31+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
32+
with:
33+
token: ${{ steps.get_token.outputs.token }}
34+
ref: ${{ github.event.pull_request.base.sha }}
35+
fetch-depth: 0
36+
37+
- name: Release packages
38+
env:
39+
HEAD_SHA: ${{ github.event.pull_request.merge_commit_sha }}
40+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
41+
GH_TOKEN: ${{ steps.get_token.outputs.token }}
42+
shell: bash
43+
run: |
44+
CHANGED_PACKAGE_JSON_FILES=$(git diff --diff-filter=MACR --name-only $BASE_SHA...$HEAD_SHA \
45+
| grep -E 'package\.json$' \
46+
| xargs dirname \
47+
| sort \
48+
| uniq)
49+
50+
declare -A versions
51+
for package in $CHANGED_PACKAGE_JSON_FILES; do
52+
base_version=$(git show $BASE_SHA:$package/package.json | jq -r .version)
53+
head_version=$(git show $HEAD_SHA:$package/package.json | jq -r .version)
54+
55+
if [ "$base_version" != "$head_version" ]; then
56+
versions[$package]=$head_version
57+
fi
58+
done
59+
60+
for package in "${!versions[@]}"; do
61+
echo "Releasing $package at version ${versions[$package]}"
62+
63+
# Build the tag name
64+
if [[ "$package" == "." ]]; then
65+
# If the package is the root, use the version as the tag name
66+
tag_name="v${versions[$package]}"
67+
else
68+
# If the package is not the root, use the package name and version as the tag name
69+
tag_name="$package/${versions[$package]}"
70+
fi
71+
72+
# Get the changelog entries since last release
73+
# TODO: Implement this
74+
# changelog_content=$(git diff $BASE_REF...$HEAD_REF -- $package/CHANGELOG.md | grep -A 1000 "^+##" | grep -v "^+++" | sed 's/^+//')
75+
76+
is_prerelease=$(echo "${versions[$package]}" | grep -qvE '^[0-9]+\.[0-9]+\.[0-9]+$' && echo true || echo false)
77+
# Create the tag
78+
gh api repos/{owner}/{repo}/git/refs \
79+
-f ref="refs/tags/$tag_name" \
80+
-f sha=$HEAD_SHA
81+
82+
# Create the release
83+
gh api repos/{owner}/{repo}/releases --input - << EOF
84+
{
85+
"tag_name": "$tag_name",
86+
"name": "$tag_name",
87+
"body": "See $package/CHANGELOG.md for details",
88+
"prerelease": $is_prerelease
89+
}
90+
EOF
91+
done

0 commit comments

Comments
 (0)