Backport #22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 push to PR branch | |
| runs-on: ubuntu-latest | |
| steps: | |
| - run: | | |
| if [[ ! $GITHUB_REF_NAME =~ ^release/v[0-9]+\.[0-9]+\.x$ ]]; then | |
| echo this workflow should only be run against release branches | |
| exit 1 | |
| fi | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| # history is needed to run git cherry-pick below | |
| fetch-depth: 0 | |
| - name: Use CLA approved bot | |
| run: .github/scripts/use-cla-approved-bot.sh | |
| - uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4 | |
| 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 | |
| GH_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 checkout -b $branch | |
| git cherry-pick $commit | |
| if git diff --name-only HEAD~1 HEAD | grep -q '^\.github/workflows/'; then | |
| echo "::error::This PR contains changes to workflow files (.github/workflows/)." | |
| echo "::error::Workflow files cannot be automatically backported because the standard" | |
| echo "::error::GitHub token doesn't have the required 'workflow' write permission." | |
| echo "::error::Please backport this PR manually." | |
| exit 1 | |
| fi | |
| 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 |