Add Milestone on a Merged PR workflow (DataDog/datadog-agent)
The Add Milestone on a Merged PR workflow from DataDog/datadog-agent, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Add Milestone on a Merged PR workflow from the DataDog/datadog-agent repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Add Milestone on a Merged PR
on:
pull_request:
types:
- closed
branches:
- main
- "[0-9]+.[0-9]+.x"
permissions: {}
jobs:
add-milestone-pr:
name: Add Milestone on PR
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
pull-requests: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
steps:
- name: Checkout datadog-agent repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Get repo current milestone
id: current-milestone
run: |
# Use the current_milestone field in the release.json file.
MILESTONE=$(cat release.json | jq -r .current_milestone)
if [ -z "$MILESTONE" ]; then
echo "Error: Couldn't find the current_milestone field in the release.json file."
exit 1
fi
if [[ ! $MILESTONE =~ ^7\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Malformed milestone $MILESTONE. It should be of the form '7.x.y'."
exit 1
fi
echo "MILESTONE=$MILESTONE" >> "$GITHUB_OUTPUT"
- name: Set the merged PR milestone to current_milestone from release.json
run: |
echo "Setting milestone $MILESTONE to PR $NUMBER."
gh issue edit "$NUMBER" --milestone "$MILESTONE"
env:
NUMBER: ${{ github.event.number }}
MILESTONE: ${{ steps.current-milestone.outputs.MILESTONE }}
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Add Milestone on a Merged PR on: pull_request: types: - closed branches: - main - "[0-9]+.[0-9]+.x" permissions: {} concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: add-milestone-pr: timeout-minutes: 30 name: Add Milestone on PR if: github.event.pull_request.merged == true runs-on: latchkey-small permissions: pull-requests: write env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} steps: - name: Checkout datadog-agent repository uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 with: persist-credentials: false - name: Get repo current milestone id: current-milestone run: | # Use the current_milestone field in the release.json file. MILESTONE=$(cat release.json | jq -r .current_milestone) if [ -z "$MILESTONE" ]; then echo "Error: Couldn't find the current_milestone field in the release.json file." exit 1 fi if [[ ! $MILESTONE =~ ^7\.[0-9]+\.[0-9]+$ ]]; then echo "Error: Malformed milestone $MILESTONE. It should be of the form '7.x.y'." exit 1 fi echo "MILESTONE=$MILESTONE" >> "$GITHUB_OUTPUT" - name: Set the merged PR milestone to current_milestone from release.json run: | echo "Setting milestone $MILESTONE to PR $NUMBER." gh issue edit "$NUMBER" --milestone "$MILESTONE" env: NUMBER: ${{ github.event.number }} MILESTONE: ${{ steps.current-milestone.outputs.MILESTONE }}
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.