Skip to content
Latchkey

Backport workflow (open-telemetry/opentelemetry-python)

The Backport workflow from open-telemetry/opentelemetry-python, 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: open-telemetry/opentelemetry-python.github/workflows/backport.ymlLicense Apache-2.0View source

What it does

This is the Backport workflow from the open-telemetry/opentelemetry-python 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)
name: Backport
on:
  workflow_dispatch:
    inputs:
      number:
        description: "The pull request # to backport"
        required: true

permissions:
  contents: read

jobs:
  backport:
    runs-on: ubuntu-latest
    permissions:
      contents: write  # required for pushing changes
    steps:
      - run: |
          if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x-0\.[0-9]+bx$ ]]; then
            echo this workflow should only be run against long-term release branches
            exit 1
          fi

      - uses: actions/checkout@v4
        with:
          # history is needed to run git cherry-pick below
          fetch-depth: 0

      - name: Use CLA approved github bot
        run: .github/scripts/use-cla-approved-github-bot.sh

      - uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
        id: otelbot-token
        with:
          app-id: ${{ vars.OTELBOT_APP_ID }}
          private-key: ${{ secrets.OTELBOT_PRIVATE_KEY }}

      - name: Create pull request
        env:
          NUMBER: ${{ github.event.inputs.number }}
          # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
          GITHUB_TOKEN: ${{ steps.otelbot-token.outputs.token }}
        run: |
          commit=$(gh pr view $NUMBER --json mergeCommit --jq .mergeCommit.oid)
          title=$(gh pr view $NUMBER --json title --jq .title)

          branch="otelbot/backport-${NUMBER}-to-${GITHUB_REF_NAME//\//-}"

          git cherry-pick $commit
          git push origin HEAD:$branch
          gh pr create --title "[$GITHUB_REF_NAME] $title" \
                       --body "Clean cherry-pick of #$NUMBER to the \`$GITHUB_REF_NAME\` branch." \
                       --head $branch \
                       --base $GITHUB_REF_NAME

The same workflow, on Latchkey

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

name: Backport
on:
  workflow_dispatch:
    inputs:
      number:
        description: "The pull request # to backport"
        required: true
 
permissions:
  contents: read
 
jobs:
  backport:
    timeout-minutes: 30
    runs-on: latchkey-small
    permissions:
      contents: write  # required for pushing changes
    steps:
      - run: |
          if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x-0\.[0-9]+bx$ ]]; then
            echo this workflow should only be run against long-term release branches
            exit 1
          fi
 
      - uses: actions/checkout@v4
        with:
          # history is needed to run git cherry-pick below
          fetch-depth: 0
 
      - name: Use CLA approved github bot
        run: .github/scripts/use-cla-approved-github-bot.sh
 
      - uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
        id: otelbot-token
        with:
          app-id: ${{ vars.OTELBOT_APP_ID }}
          private-key: ${{ secrets.OTELBOT_PRIVATE_KEY }}
 
      - name: Create pull request
        env:
          NUMBER: ${{ github.event.inputs.number }}
          # not using secrets.GITHUB_TOKEN since pull requests from that token do not run workflows
          GITHUB_TOKEN: ${{ steps.otelbot-token.outputs.token }}
        run: |
          commit=$(gh pr view $NUMBER --json mergeCommit --jq .mergeCommit.oid)
          title=$(gh pr view $NUMBER --json title --jq .title)
 
          branch="otelbot/backport-${NUMBER}-to-${GITHUB_REF_NAME//\//-}"
 
          git cherry-pick $commit
          git push origin HEAD:$branch
          gh pr create --title "[$GITHUB_REF_NAME] $title" \
                       --body "Clean cherry-pick of #$NUMBER to the \`$GITHUB_REF_NAME\` branch." \
                       --head $branch \
                       --base $GITHUB_REF_NAME
 

What changed

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

Actions used in this workflow