Ask for code reviews workflow (DataDog/datadog-agent)
The Ask for code reviews 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 Ask for code reviews 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: "Ask for code reviews"
on:
pull_request:
types: [labeled, review_requested]
permissions: {}
jobs:
ask-reviews:
if: github.triggering_actor != 'dd-devflow[bot]' && (github.event.action != 'labeled' || github.event.label.name == 'ask-review')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Install dda
uses: ./.github/actions/install-dda
with:
features: legacy-tasks
- name: Ask for code reviews
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_DATADOG_AGENT_BOT_TOKEN: ${{ secrets.SLACK_DATADOG_AGENT_BOT_TOKEN }}
REQUESTED_TEAMS: ${{ toJSON(github.event.pull_request.requested_teams) }}
run: |
options=()
if [ "${{ github.event.action }}" == "labeled" ] && [ "${{ github.event.label.name }}" == "ask-review" ]; then
# ask_reviews uses @task(iterable=["team_slugs"]) so we pass --team-slugs multiple times
mapfile -t slugs < <(jq -r '.[].slug' <<< "$REQUESTED_TEAMS")
for slug in "${slugs[@]}"; do
options+=(--team-slugs "$slug")
done
elif [ "${{ github.event.action }}" == "review_requested" ]; then
# Only handle team review requests; ignore user review requests (requested_team is empty in that case)
if [ -n "${{ github.event.requested_team.slug }}" ]; then
options+=(--team-slugs "${{ github.event.requested_team.slug }}")
else
echo "review_requested for a user (no requested_team); skipping."
exit 0
fi
fi
dda inv -- -e issue.ask-reviews -p "${{ github.event.pull_request.number }}" -a "${{ github.event.action }}" "${options[@]}"
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
--- name: "Ask for code reviews" on: pull_request: types: [labeled, review_requested] permissions: {} concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: ask-reviews: timeout-minutes: 30 if: github.triggering_actor != 'dd-devflow[bot]' && (github.event.action != 'labeled' || github.event.label.name == 'ask-review') runs-on: latchkey-small steps: - name: Checkout repository uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 with: persist-credentials: false - name: Install dda uses: ./.github/actions/install-dda with: features: legacy-tasks - name: Ask for code reviews env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SLACK_DATADOG_AGENT_BOT_TOKEN: ${{ secrets.SLACK_DATADOG_AGENT_BOT_TOKEN }} REQUESTED_TEAMS: ${{ toJSON(github.event.pull_request.requested_teams) }} run: | options=() if [ "${{ github.event.action }}" == "labeled" ] && [ "${{ github.event.label.name }}" == "ask-review" ]; then # ask_reviews uses @task(iterable=["team_slugs"]) so we pass --team-slugs multiple times mapfile -t slugs < <(jq -r '.[].slug' <<< "$REQUESTED_TEAMS") for slug in "${slugs[@]}"; do options+=(--team-slugs "$slug") done elif [ "${{ github.event.action }}" == "review_requested" ]; then # Only handle team review requests; ignore user review requests (requested_team is empty in that case) if [ -n "${{ github.event.requested_team.slug }}" ]; then options+=(--team-slugs "${{ github.event.requested_team.slug }}") else echo "review_requested for a user (no requested_team); skipping." exit 0 fi fi dda inv -- -e issue.ask-reviews -p "${{ github.event.pull_request.number }}" -a "${{ github.event.action }}" "${options[@]}"
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.