Skip to content

Commit 387f552

Browse files
authored
Add milestones workflow for Merged PRs (DataDog#23049)
* add release.json to track current_milestone * add milestone workflow for merged PRs to master and release branches * move to dd-octo-sts * apply dd-octo-sts claude skill recommendations
1 parent 3364f3e commit 387f552

3 files changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Trust policy for the add-milestone workflow in DataDog/integrations-core
2+
#
3+
# This policy grants the workflow permission to set a milestone on merged pull
4+
# requests targeting master or release branches.
5+
#
6+
# Naming convention:
7+
# self: Only this repository (DataDog/integrations-core) can use this policy
8+
# add-milestone: Grants permissions to update pull request milestones
9+
# pull-request: Intended for workflows triggered by pull_request events
10+
#
11+
# Security model:
12+
# - Workflow runs on pull_request (closed) events targeting protected branches
13+
# - ref restricts to master and protected X.Y.x release branches (protected by org rulesets)
14+
# - job_workflow_ref is matched by pattern since PR events reference refs/pull/N/merge
15+
#
16+
# Permissions granted:
17+
# - pull_requests: write - Set the milestone on the merged pull request
18+
#
19+
# Usage in workflows:
20+
# - uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
21+
# with:
22+
# scope: DataDog/integrations-core
23+
# policy: self.add-milestone.pull-request
24+
25+
issuer: https://token.actions.githubusercontent.com
26+
27+
subject: repo:DataDog/integrations-core:pull_request
28+
29+
claim_pattern:
30+
event_name: pull_request
31+
job_workflow_ref: DataDog/integrations-core/\.github/workflows/add-milestone\.yml@.*
32+
ref: refs/heads/(master|\d+\.\d+\.x)
33+
repository: DataDog/integrations-core
34+
35+
permissions:
36+
pull_requests: write
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Add Milestone on a Merged PR
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
branches:
8+
- master
9+
- "[0-9]+.[0-9]+.x"
10+
11+
permissions: {}
12+
13+
jobs:
14+
add-milestone-pr:
15+
name: Add Milestone on PR
16+
if: github.event.pull_request.merged == true
17+
runs-on: ubuntu-latest
18+
permissions:
19+
id-token: write # Required for OIDC token federation with dd-octo-sts
20+
contents: read
21+
env:
22+
GH_REPO: ${{ github.repository }}
23+
steps:
24+
- name: Checkout integrations-core repository
25+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
26+
with:
27+
persist-credentials: false
28+
29+
- name: Get GitHub token via dd-octo-sts
30+
uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
31+
id: octo-sts
32+
with:
33+
scope: DataDog/integrations-core
34+
policy: self.add-milestone.pull-request
35+
36+
- name: Get repo current milestone
37+
id: current-milestone
38+
run: |
39+
# Use the current_milestone field in the release.json file.
40+
MILESTONE=$(cat release.json | jq -r .current_milestone)
41+
if [ -z "$MILESTONE" ]; then
42+
echo "Error: Couldn't find the current_milestone field in the release.json file."
43+
exit 1
44+
fi
45+
46+
if [[ ! $MILESTONE =~ ^7\.[0-9]+\.[0-9]+$ ]]; then
47+
echo "Error: Malformed milestone $MILESTONE. It should be of the form '7.x.y'."
48+
exit 1
49+
fi
50+
echo "MILESTONE=$MILESTONE" >> "$GITHUB_OUTPUT"
51+
52+
- name: Set the merged PR milestone to current_milestone from release.json
53+
run: |
54+
echo "Setting milestone $MILESTONE to PR $NUMBER."
55+
gh issue edit "$NUMBER" --milestone "$MILESTONE"
56+
env:
57+
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
58+
NUMBER: ${{ github.event.number }}
59+
MILESTONE: ${{ steps.current-milestone.outputs.MILESTONE }}
60+

release.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"current_milestone": "7.79.0"
3+
}

0 commit comments

Comments
 (0)