Skip to content

Commit 6e274ae

Browse files
authored
[AAWF-420] Update release workflow (#2580)
* update workflow * use version file * use hard coded version file * update re * fix workflow * fix workflow
1 parent b0d250d commit 6e274ae

File tree

7 files changed

+93
-191
lines changed

7 files changed

+93
-191
lines changed

.github/workflows/prepare_release.yml

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

.github/workflows/publish.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,30 @@ jobs:
1515
name: Upload release
1616
runs-on: ubuntu-20.04
1717
steps:
18-
- uses: actions/checkout@v3
19-
# Include all history and tags, needed for building the right version
18+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2019
with:
21-
ref: ${{ github.event.release.tag_name }}
22-
fetch-depth: 0
20+
fetch-depth: 1
2321

2422
- uses: actions/setup-python@v4
2523
name: Install Python
2624
with:
2725
python-version: "3.11"
2826
cache: "pip"
2927

30-
- name: Install pypa/build
31-
run: python -m pip install build --user
28+
- name: Releasing tag ${{ github.event.release.tag_name }}
29+
run: |
30+
# Get tag name from event
31+
tag_name="${{ github.event.release.tag_name }}"
3232
33-
- name: Build a binary wheel and a source tarball
34-
run: python -m build --sdist --wheel --outdir dist/ .
33+
if [[ ! "$tag_name" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
34+
cd $(echo $tag_name | rev | cut -d'/' -f2- | rev)
35+
fi
36+
37+
# Install pypa/build
38+
python -m pip install build --user
39+
40+
# Build a binary wheel and a source tarball
41+
python -m build --sdist --wheel --outdir dist/ .
3542
3643
- name: Publish a Python distribution to PyPI
3744
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/release.yml

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ permissions:
44
contents: write
55
pull-requests: write
66

7+
env:
8+
GIT_AUTHOR_EMAIL: "[email protected]"
9+
GIT_AUTHOR_NAME: "ci.datadog-api-spec"
10+
711
on:
812
pull_request:
913
types: [closed]
1014
branches:
1115
- master
16+
- v2
1217

1318
jobs:
1419
create_release:
@@ -18,27 +23,70 @@ jobs:
1823
steps:
1924
- name: Get GitHub App token
2025
id: get_token
21-
uses: actions/create-github-app-token@v1
26+
uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 #v1.11.1
2227
with:
2328
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
2429
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
25-
- name: Create release
26-
uses: actions/github-script@v6
27-
env:
28-
RELEASE_BRANCH: ${{ github.head_ref }}
30+
31+
- name: Checkout ${{ github.event.pull_request.base.ref }}
32+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2933
with:
30-
github-token: ${{ steps.get_token.outputs.token }}
31-
script: |
32-
const tagName = process.env.RELEASE_BRANCH.split("/")[1];
33-
await github.rest.git.createRef({
34-
owner: context.repo.owner,
35-
repo: context.repo.repo,
36-
ref: `refs/tags/${tagName}`,
37-
sha: context.payload.pull_request.merge_commit_sha,
38-
});
39-
await github.rest.repos.createRelease({
40-
owner: context.repo.owner,
41-
repo: context.repo.repo,
42-
generate_release_notes: true,
43-
tag_name: tagName,
44-
});
34+
token: ${{ steps.get_token.outputs.token }}
35+
ref: ${{ github.event.pull_request.base.ref }}
36+
fetch-depth: 0
37+
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
44+
run: |
45+
CHANGED_VERSION_FILES=$(git diff --diff-filter=MACR --name-only $BASE_SHA...$HEAD_SHA \
46+
| grep -E 'version\.py$' \
47+
| xargs dirname | xargs dirname | xargs dirname \
48+
| sort \
49+
| uniq)
50+
51+
declare -A versions
52+
for package in $CHANGED_VERSION_FILES; do
53+
base_version=$(git show $BASE_SHA:$package/src/datadog_api_client/version.py | grep "__version__ = " | sed 's/.*"\(.*\)".*/\1/')
54+
head_version=$(git show $HEAD_SHA:$package/src/datadog_api_client/version.py | grep "__version__ = " | sed 's/.*"\(.*\)".*/\1/')
55+
56+
if [ "$base_version" != "$head_version" ]; then
57+
versions[$package]=$head_version
58+
fi
59+
done
60+
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="${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

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
src/datadog_api_client/version.py
21
site
32
docs/.sphinx
43

RELEASING.md

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

setup.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,14 @@
44
# Copyright 2019 Datadog, Inc.
55

66
import os
7+
import re
78

89
from setuptools import setup
910

10-
version_template = """\
11-
# Unless explicitly stated otherwise all files in this repository are licensed
12-
# under the 3-clause BSD style license (see LICENSE).
13-
# This product includes software developed at Datadog (https://www.datadoghq.com/).
14-
# Copyright 2020-Present Datadog, Inc.
15-
16-
__version__ = "{version}"
17-
"""
18-
19-
# Allows the fetching of tags even from shallow clones
20-
# https://github.com/pypa/setuptools_scm/pull/118#issuecomment-255381535
21-
def parse_fetch_on_shallow(*args, **kwargs):
22-
from setuptools_scm.git import parse, fetch_on_shallow
23-
24-
kwargs["pre_parse"] = fetch_on_shallow
25-
26-
return parse(*args, **kwargs)
11+
ROOT = os.path.dirname(__file__)
12+
VERSION_RE = re.compile(r'''__version__ = ['"]([0-9]+\.[0-9]+\.[0-9]+.*)['"]''')
2713

2814

2915
setup(
30-
use_scm_version={
31-
"local_scheme": "dirty-tag",
32-
"write_to": os.path.join("src", "datadog_api_client", "version.py"),
33-
"write_to_template": version_template,
34-
"parse": parse_fetch_on_shallow,
35-
}
16+
version=VERSION_RE.search(open(os.path.join(ROOT, "src", "datadog_api_client", "version.py")).read()).group(1),
3617
)

src/datadog_api_client/version.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Unless explicitly stated otherwise all files in this repository are licensed
2+
# under the 3-clause BSD style license (see LICENSE).
3+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
# Copyright 2020-Present Datadog, Inc.
5+
6+
__version__ = "2.34.0"

0 commit comments

Comments
 (0)