Add job for 'backport: auto' labeled PRs (#1174)

* Add job for 'backport: auto' labeled PRs

* Limit the job to sequential only

* Fix delayed labels and use the right commit

* Add slack webhook integration

(cherry picked from commit 2ceb5b52c9)
This commit is contained in:
Ross Wolf
2021-05-06 20:03:05 -06:00
parent a623e34a9e
commit 67febf3b45
+66
View File
@@ -0,0 +1,66 @@
name: backport
on:
pull_request_target:
branches:
- main
types:
- labeled
- closed
jobs:
backport:
name: on merge
if: |
github.event.pull_request.merged == true
&& contains(github.event.pull_request.labels.*.name, 'backport: auto')
&& (
(github.event.action == 'labeled' && github.event.label.name == 'backport: auto')
|| (github.event.action == 'closed')
)
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
target_branch: [7.13]
steps:
- uses: craftech-io/slack-action@v1
with:
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
status: failure
if: failure()
- name: Checkout repo
uses: actions/checkout@v2
- name: Set github config
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Update branches
run: |
git fetch origin ${{matrix.target_branch}} --unshallow
git checkout -f ${{matrix.target_branch}}
git status
git log -1 --format='%H'
- name: Backport commit
run: |
echo "Cherry-pick from $GITHUB_SHA to ${{matrix.target_branch}}"
git cherry-pick -x ${{github.event.pull_request.merge_commit_sha}}
# See https://github.com/elastic/detection-rules/issues/1171
# Eventually, this cherry pick command will be:
# git-cherry-pick --no-commit
# <python code to remove irrelevant rules>
# git commit --author ... --message ...
echo "Push new commit to ${{matrix.target_branch}}"
git push
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{matrix.target_branch}}