Skip to content
Latchkey

Cherry-Pick workflow (NVIDIA/k8s-device-plugin)

The Cherry-Pick workflow from NVIDIA/k8s-device-plugin, explained and optimized by Latchkey.

A

CI health: A - excellent

Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: NVIDIA/k8s-device-plugin.github/workflows/cherrypick.ymlLicense Apache-2.0View source

What it does

This is the Cherry-Pick workflow from the NVIDIA/k8s-device-plugin 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

workflow (.yml)
# Copyright 2025 NVIDIA CORPORATION
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Cherry-Pick

on:
  issue_comment:
    types: [created]
  pull_request_target:
    types: [closed]

permissions:
  contents: write
  pull-requests: write
  issues: write

jobs:
  add-labels:
    name: Add Cherry-Pick Labels from Comment
    runs-on: ubuntu-latest
    # Run on /cherry-pick comments on PRs
    if: |
      github.event_name == 'issue_comment' &&
      github.event.issue.pull_request && 
      startsWith(github.event.comment.body, '/cherry-pick')
    
    steps:
      - name: Checkout repository
        uses: actions/checkout@v7
        with:
          fetch-depth: 0
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Configure git
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

      - name: Add labels and handle backport
        uses: actions/github-script@v8
        with:
          script: |
            const run = require('./.github/scripts/add-labels-from-comment.js');
            return await run({ github, context, core });

  backport:
    name: Backport PR
    runs-on: ubuntu-latest
    # Run when PR is merged and has cherry-pick labels
    if: |
      github.event_name == 'pull_request_target' &&
      github.event.pull_request.merged == true &&
      contains(join(github.event.pull_request.labels.*.name, ','), 'cherry-pick/')
    
    steps:
      - name: Checkout base branch repository
        uses: actions/checkout@v7
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.base.ref }}
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Extract target branches from PR labels
        id: extract-branches
        uses: actions/github-script@v8
        with:
          script: |
            const run = require('./.github/scripts/extract-branches.js');
            return await run({ github, context, core });

      - name: Configure git
        if: steps.extract-branches.outputs.result != '[]'
        run: |
          git config user.name "nvidia-backport-bot"
          git config user.email "noreply@nvidia.com"

      - name: Backport to release branches
        id: backport
        if: steps.extract-branches.outputs.result != '[]'
        uses: actions/github-script@v8
        env:
          BRANCHES_JSON: ${{ steps.extract-branches.outputs.result }}
        with:
          script: |
            const run = require('./.github/scripts/backport.js');
            return await run({ github, context, core });

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

# Copyright 2025 NVIDIA CORPORATION
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
 
name: Cherry-Pick
 
on:
  issue_comment:
    types: [created]
  pull_request_target:
    types: [closed]
 
permissions:
  contents: write
  pull-requests: write
  issues: write
 
jobs:
  add-labels:
    timeout-minutes: 30
    name: Add Cherry-Pick Labels from Comment
    runs-on: latchkey-small
    # Run on /cherry-pick comments on PRs
    if: |
      github.event_name == 'issue_comment' &&
      github.event.issue.pull_request && 
      startsWith(github.event.comment.body, '/cherry-pick')
    
    steps:
      - name: Checkout repository
        uses: actions/checkout@v7
        with:
          fetch-depth: 0
          token: ${{ secrets.GITHUB_TOKEN }}
 
      - name: Configure git
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
 
      - name: Add labels and handle backport
        uses: actions/github-script@v8
        with:
          script: |
            const run = require('./.github/scripts/add-labels-from-comment.js');
            return await run({ github, context, core });
 
  backport:
    timeout-minutes: 30
    name: Backport PR
    runs-on: latchkey-small
    # Run when PR is merged and has cherry-pick labels
    if: |
      github.event_name == 'pull_request_target' &&
      github.event.pull_request.merged == true &&
      contains(join(github.event.pull_request.labels.*.name, ','), 'cherry-pick/')
    
    steps:
      - name: Checkout base branch repository
        uses: actions/checkout@v7
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.base.ref }}
          token: ${{ secrets.GITHUB_TOKEN }}
 
      - name: Extract target branches from PR labels
        id: extract-branches
        uses: actions/github-script@v8
        with:
          script: |
            const run = require('./.github/scripts/extract-branches.js');
            return await run({ github, context, core });
 
      - name: Configure git
        if: steps.extract-branches.outputs.result != '[]'
        run: |
          git config user.name "nvidia-backport-bot"
          git config user.email "noreply@nvidia.com"
 
      - name: Backport to release branches
        id: backport
        if: steps.extract-branches.outputs.result != '[]'
        uses: actions/github-script@v8
        env:
          BRANCHES_JSON: ${{ steps.extract-branches.outputs.result }}
        with:
          script: |
            const run = require('./.github/scripts/backport.js');
            return await run({ github, context, core });
 

What changed

This workflow runs 2 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow