Skip to content

Backport

Backport #90

Workflow file for this run

name: Backport
on:
workflow_dispatch:
inputs:
number:
description: "The pull request # to backport"
required: true
permissions:
contents: read
jobs:
backport:
permissions:
contents: write # for Git to git push
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
# history is needed to run git cherry-pick below
fetch-depth: 0
- uses: actions/create-github-app-token@136412a57a7081aa63c935a2cc2918f76c34f514 # v1.11.2
id: app-token
with:
app-id: ${{ secrets.OPENTELEMETRY_BASIC_AUTOMATION_CLIENT_ID }}
private-key: ${{ secrets.OPENTELEMETRY_BASIC_AUTOMATION_PRIVATE_KEY }}
- name: Use CLA approved author
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
user_name=${{ steps.app-token.outputs.app-slug }}[bot]
user_id=$(gh api "/users/$user_name" --jq .id)
git config user.name "$user_name"
git config user.email "${user_id}+${user_name}@users.noreply.github.com"
- 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
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
commit=$(gh pr view $NUMBER --json mergeCommit --jq .mergeCommit.oid)
title=$(gh pr view $NUMBER --json title --jq .title)
branch="opentelemetrybot/backport-${NUMBER}-to-${GITHUB_REF_NAME//\//-}"
git checkout -b $branch
git cherry-pick $commit
git push --set-upstream origin $branch
gh pr create --title "[$GITHUB_REF_NAME] $title" \
--body "Clean cherry-pick of #$NUMBER to the \`$GITHUB_REF_NAME\` branch." \
--base $GITHUB_REF_NAME