Skip to content

Commit efc6f52

Browse files
feat: Improve milestone automation (#7553)
Rewrite milestone update on tag Add workflow testing Update README
1 parent aae44c7 commit efc6f52

File tree

8 files changed

+107
-69
lines changed

8 files changed

+107
-69
lines changed

.github/workflows/README.md

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GitHub Actions Documentation
22

3-
This lists and describes the repository GitHub actions.
3+
This lists and describes the repository GitHub actions, how to maintain and test them.
44

55
## Release Management
66

@@ -18,15 +18,16 @@ _Trigger:_ When a release is published.
1818

1919
_Action:_ Append the new release to the Cloud Foundry repository.
2020

21-
_Recovery:_ Manually edit and push the `index.yml`file from [the cloudfoundry branch](https://github.com/DataDog/dd-trace-java/tree/cloudfoundry).
21+
_Recovery:_ Manually edit and push the `index.yml` file from [the cloudfoundry branch](https://github.com/DataDog/dd-trace-java/tree/cloudfoundry).
2222

2323
### create-next-milestone [🔗](create-next-milestone.yaml)
2424

2525
_Trigger:_ When closing a milestone.
2626

2727
_Action:_ Create a new milestone by incrementing minor version.
2828

29-
_Comment:_ Already done when closing a tag. To delete?
29+
_Comment:_ Disabled as also covered by increment-milestone-on-tag.
30+
This will be removed after some testing.
3031

3132
### draft-release-notes-on-tag [🔗](draft-release-notes-on-tag.yaml)
3233

@@ -40,18 +41,17 @@ _Actions:_
4041

4142
_Recovery:_ Manually trigger the action again on the relevant tag.
4243

43-
### increment-milestones-on-tag [🔗](increment-milestones-on-tag.yaml)
44+
### increment-milestone-on-tag [🔗](increment-milestone-on-tag.yaml)
4445

45-
_Trigger:_ When creating a tag. Release Candidate tags containing "-RC" or "-rc" will skip this.
46+
_Trigger:_ When creating a minor or major version tag.
4647

4748
_Actions:_
4849
* Close the milestone related to the tag,
4950
* Create a new milestone by incrementing minor version.
5051

51-
_Recovery:_ Manually close the related milestone and create a new one.
52+
_Recovery:_ Manually [close the related milestone and create a new one](https://github.com/DataDog/dd-trace-java/milestones).
5253

53-
_Notes:_ This actions will handle _minor_ releases only.
54-
As there is no milestone for _patch_ releases, it won't close and create _patch_ releated milestone.
54+
_Notes:_ This action will not apply to release candidate versions using `-RC` tags.
5555

5656
### update-download-releases [🔗](update-download-releases.yaml)
5757

@@ -117,3 +117,12 @@ Run the following script to get the list of actions to declare according the sta
117117
```bash
118118
find .github/workflows -name "*.yaml" -exec awk '/uses:/{print $2 ","}' {} \; | grep -vE '^(actions|github)/' | sort | uniq
119119
```
120+
121+
## Testing
122+
123+
Workflows can be locally tested using the [`act` CLI](https://github.com/nektos/act/).
124+
The [.github/workflows/tests/](./tests) folder contains test scripts and event payloads to locally trigger workflows.
125+
126+
> [!WARNING]
127+
> Locally running workflows will still query GitHub backend and will update the GitHub project accordingly.
128+
> Pay extra attention to the workflow jobs you trigger to not create development disruption.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Increment milestones on tag
2+
on:
3+
create
4+
permissions:
5+
issues: write # Required to update milestones
6+
7+
jobs:
8+
increment_milestone:
9+
if: github.event.ref_type == 'tag' && contains(github.event.ref,'-RC') == false
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Close current milestone
13+
id: close-milestone
14+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # 7.0.1
15+
with:
16+
script: |
17+
// Get the milestone title ("X.Y.Z") from tag name ("vX.Y.Z")
18+
const match = '${{github.event.ref}}'.match(/v(\d+\.\d+\.\d+)/i)
19+
if (!match) {
20+
core.setFailed('Failed to parse tag name into milestone title: ${{github.event.ref}}')
21+
return
22+
}
23+
const milestoneTitle = match[1]
24+
// Look for the milestone from its title
25+
const response = await github.rest.issues.listMilestones({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
state: 'open'
29+
})
30+
if (!response.data || response.data.length == 0) {
31+
core.setFailed(`Failed to list milestones: ${response.status}`)
32+
return
33+
}
34+
const milestone = response.data.find(milestone => milestone.title == milestoneTitle)
35+
if (!milestone) {
36+
core.setFailed(`Failed to find milestone: ${milestoneTitle}`)
37+
return
38+
}
39+
// Close the milestone
40+
await github.rest.issues.updateMilestone({
41+
owner: context.repo.owner,
42+
repo: context.repo.repo,
43+
state: 'closed',
44+
milestone_number: milestone.number
45+
}).catch(error => {
46+
core.setFailed(`Failed to close milestone: ${error}`)
47+
})
48+
// Compute the next milestone version
49+
const versionNumbers = milestoneTitle.split('.').map(Number)
50+
if (versionNumbers[2] != 0) {
51+
core.info('Closing a patch version milestone. Not opening a new one.')
52+
return
53+
}
54+
versionNumbers[1]++
55+
const nextMilestoneTitle = versionNumbers.join('.')
56+
core.info(`Creating next version milestone: ${nextMilestoneTitle}`)
57+
// Create the next milestone
58+
await github.issues.createMilestone({
59+
owner: context.repo.owner,
60+
repo: context.repo.repo,
61+
title: nextMilestoneTitle
62+
}).catch(error => {
63+
core.setFailed(`Failed to create milestone ${nextMilestoneTitle}: ${error}`)
64+
})

.github/workflows/increment-milestones-on-tag.yaml

-61
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"pull_request": {
3+
"number": 7549,
4+
"base": {
5+
"ref": "master"
6+
},
7+
"merged": true
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
source $(dirname "$0")/../env.sh
3+
act pull_request --workflows .github/workflows/add-milestone-to-pull-requests.yaml --eventpath .github/workflows/tests/add-milestone-to-pull-requests/payload.json $COMMON_ACT_ARGS

.github/workflows/tests/env.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# Move to project root directory
4+
FILE_PATH=$(dirname "$0")
5+
cd $FILE_PATH/../../../../
6+
7+
export COMMON_ACT_ARGS="--container-architecture linux/amd64 --secret GITHUB_TOKEN="$(gh auth token)" --verbose"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ref_type": "tag",
3+
"ref": "v1.40.0"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
source $(dirname "$0")/../env.sh
3+
act create --workflows .github/workflows/increment-milestone-on-tag.yaml --eventpath .github/workflows/tests/increment-milestone-on-tag/payload.json $COMMON_ACT_ARGS

0 commit comments

Comments
 (0)