Skip to content
Merged
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
91 changes: 91 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Release

permissions:
contents: write
pull-requests: write

env:
GIT_AUTHOR_EMAIL: "packages@datadoghq.com"
GIT_AUTHOR_NAME: "ci.datadog-api-spec"

on:
pull_request:
types: [closed]
branches:
- v2

jobs:
create_release:
name: Create release
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')
steps:
- name: Get GitHub App token
id: get_token
uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 #v1.11.1
with:
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}

- name: Checkout ${{ github.event.pull_request.base.ref }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
token: ${{ steps.get_token.outputs.token }}
ref: ${{ github.event.pull_request.base.sha }}
fetch-depth: 0

- name: Release packages
env:
HEAD_SHA: ${{ github.event.pull_request.merge_commit_sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
GH_TOKEN: ${{ steps.get_token.outputs.token }}
shell: bash
run: |
CHANGED_PACKAGE_JSON_FILES=$(git diff --diff-filter=MACR --name-only $BASE_SHA...$HEAD_SHA \
| grep -E 'package\.json$' \
| xargs dirname \
| sort \
| uniq)

declare -A versions
for package in $CHANGED_PACKAGE_JSON_FILES; do
base_version=$(git show $BASE_SHA:$package/package.json | jq -r .version)
head_version=$(git show $HEAD_SHA:$package/package.json | jq -r .version)

if [ "$base_version" != "$head_version" ]; then
versions[$package]=$head_version
fi
done

for package in "${!versions[@]}"; do
echo "Releasing $package at version ${versions[$package]}"

# Build the tag name
if [[ "$package" == "." ]]; then
# If the package is the root, use the version as the tag name
tag_name="v${versions[$package]}"
else
# If the package is not the root, use the package name and version as the tag name
tag_name="$package/${versions[$package]}"
fi

# Get the changelog entries since last release
# TODO: Implement this
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove TODO?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will keep this here for now. It is not supported at the moment.

# changelog_content=$(git diff $BASE_REF...$HEAD_REF -- $package/CHANGELOG.md | grep -A 1000 "^+##" | grep -v "^+++" | sed 's/^+//')

is_prerelease=$(echo "${versions[$package]}" | grep -qvE '^[0-9]+\.[0-9]+\.[0-9]+$' && echo true || echo false)
# Create the tag
gh api repos/{owner}/{repo}/git/refs \
-f ref="refs/tags/$tag_name" \
-f sha=$HEAD_SHA

# Create the release
gh api repos/{owner}/{repo}/releases --input - << EOF
{
"tag_name": "$tag_name",
"name": "$tag_name",
"body": "See $package/CHANGELOG.md for details",
"prerelease": $is_prerelease
}
EOF
done