feat: add `backport.yml` (#13163)

* feat: add `backport.yml`

* feat: check releases over labels for latest

* chore: Do not automerge for non `stable-website`

* chore: Do not automerge to not `stable-website`

* Update .github/workflows/backport.yml

Co-authored-by: Meggie <meggie@hashicorp.com>

Co-authored-by: Meggie <meggie@hashicorp.com>
This commit is contained in:
Kevin Wang 2021-12-15 18:16:35 -05:00 committed by GitHub
parent 62ecf23c2c
commit fafeb3717f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 52 additions and 0 deletions

52
.github/workflows/backport.yml vendored Normal file
View File

@ -0,0 +1,52 @@
---
name: Backport Assistant Runner
on:
pull_request_target:
types:
- closed
- labeled
jobs:
backport:
if: github.event.pull_request.merged
runs-on: ubuntu-latest
container: hashicorpdev/backport-assistant:0.2.3
steps:
- name: Backport changes to stable-website
run: |
backport-assistant backport -automerge
env:
BACKPORT_LABEL_REGEXP: "backport/(?P<target>website)"
BACKPORT_TARGET_TEMPLATE: "stable-{{.target}}"
GITHUB_TOKEN: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
- name: Backport changes labeled website to latest release branch
run: |
resp=$(curl -f -s "https://api.github.com/repos/$GITHUB_REPOSITORY/releases?per_page=100")
ret="$?"
if [[ "$ret" -ne 0 ]]; then
echo "The GitHub API returned $ret"
exit $ret
fi
# find the latest non-rc release
latest_version=$(echo "$resp" | tr '\r\n' ' ' | jq -r '.[] | select(.name|test("^v\\d+\\.\\d+\\.\\d+$")) | .name' | sort -rV | head -n1)
echo "Latest non-rc version: $latest_version"
# strip leading "v" &
target="${latest_version#v}"
# replace patch version with "x"
target="${target%.*}.x"
export BACKPORT_TARGET_TEMPLATE="release/$target"
backport-assistant backport
env:
BACKPORT_LABEL_REGEXP: "backport/(?P<target>website)"
GITHUB_TOKEN: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
- name: Backport changes to targeted release branch
run: |
backport-assistant backport
env:
BACKPORT_LABEL_REGEXP: "backport/(?P<target>\\d+\\.\\d+\\.\\w+)"
BACKPORT_TARGET_TEMPLATE: "release/{{.target}}"
GITHUB_TOKEN: ${{ secrets.ELEVATED_GITHUB_TOKEN }}