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
50 changes: 44 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,67 @@
name: Release

on:
pull_request:
types: [closed]
push:
branches:
- main

concurrency:
group: release-${{ github.sha }}
cancel-in-progress: false

jobs:
create_release:
name: Create release
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')
outputs:
is_release: ${{ steps.detect_release.outputs.is_release }}
release_branch: ${{ steps.detect_release.outputs.release_branch }}
permissions:
contents: read
id-token: write
pull-requests: read
steps:
- name: Detect release
id: detect_release
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
try {
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha
});
const releasePRs = prs.data
.filter(pr => pr.merged_at && pr.head.ref.startsWith('release/'))
.sort((a, b) => new Date(b.merged_at) - new Date(a.merged_at));
const releasePR = releasePRs[0];
if (releasePR) {
core.setOutput('is_release', 'true');
core.setOutput('release_branch', releasePR.head.ref);
core.info(`Detected release PR: ${releasePR.head.ref}`);
} else {
core.setOutput('is_release', 'false');
core.setOutput('release_branch', '');
core.info('No release PR detected for this push — skipping release steps');
}
} catch (e) {
core.setFailed(`Failed to detect release PR: ${e.message}`);
}

- name: Get access token
if: steps.detect_release.outputs.is_release == 'true'
uses: DataDog/dd-octo-sts-action@96a25462dbcb10ebf0bfd6e2ccc917d2ab235b9a # v1.0.4
id: octo-sts
with:
scope: DataDog/datadog-sync-cli
policy: self.release.create-release

- name: Create release
if: steps.detect_release.outputs.is_release == 'true'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
RELEASE_BRANCH: ${{ github.head_ref }}
RELEASE_BRANCH: ${{ steps.detect_release.outputs.release_branch }}
with:
github-token: ${{ steps.octo-sts.outputs.token }}
script: |
Expand All @@ -49,7 +85,7 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tagName}`,
sha: context.payload.pull_request.merge_commit_sha,
sha: context.sha,
});
}

Expand All @@ -74,8 +110,10 @@ jobs:
tag_name: tagName,
});
}

build_artifacts:
needs: create_release
if: needs.create_release.outputs.is_release == 'true'
name: Build executables
permissions:
contents: write
Expand All @@ -86,7 +124,7 @@ jobs:
steps:
- name: Set tag
env:
RELEASE_BRANCH: ${{ github.head_ref }}
RELEASE_BRANCH: ${{ needs.create_release.outputs.release_branch }}
run: |
TAG_NAME=$(echo "$RELEASE_BRANCH" | cut -d "/" -f2)
echo "tag_name=$TAG_NAME" >> "$GITHUB_ENV"
Expand Down
Loading