test automatically prevent future merges when a backport fails (#1909)

automatically prevent future merges when a backport fails

(cherry picked from commit 4fdd978183)
This commit is contained in:
Mika Ayenson
2022-06-23 14:59:25 -04:00
committed by github-actions[bot]
parent fafe1e0ab6
commit 6c5e101e6f
5 changed files with 93 additions and 7 deletions
+5 -1
View File
@@ -11,6 +11,9 @@ on:
- closed
jobs:
get-branches:
uses: ./.github/workflows/get-target-branches.yml
label:
runs-on: ubuntu-latest
if: |
@@ -51,12 +54,13 @@ jobs:
(github.event.action == 'labeled' && github.event.label.name == 'backport: auto')
|| (github.event.action == 'closed')
)
needs: get-branches
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
# 7.17 was intentionally skipped because it was added late and was bug fix only
target_branch: [7.16, '8.0', 8.1, 8.2, 8.3]
target_branch: ${{ fromJSON(needs.get-branches.outputs.branches) }}
steps:
- name: Checkout repo
@@ -0,0 +1,37 @@
name: Branch Version Status Checks
on:
push:
branches: [ "main", "7.*", "8.*" ]
pull_request:
branches: [ "*" ]
jobs:
get-branches:
uses: ./.github/workflows/get-target-branches.yml
branch-status-checks:
needs: get-branches
runs-on: ubuntu-latest
strategy:
matrix:
target_branch: ${{ fromJSON(needs.get-branches.outputs.branches) }}
steps:
- name: Get Backport Status
id: get_backport_status
uses: fjogeleit/http-request-action@v1
with:
url: "https://api.github.com/repos/elastic/detection-rules/actions/workflows/pythonpackage.yml/runs?per_page=1&branch=${{matrix.target_branch}}"
method: 'GET'
- name: Check Backport Status
uses: actions/github-script@v6
with:
script: |
const workflow_status = ${{ toJSON(fromJSON(steps.get_backport_status.outputs.response).workflow_runs[0].status) }}
const workflow_conclusion = ${{ toJSON(fromJSON(steps.get_backport_status.outputs.response).workflow_runs[0].conclusion) }}
if (workflow_status != 'completed' ||
workflow_conclusion != 'success') {
core.setFailed('Recent Backport status: ' + workflow_status + ', conclusion: ' + workflow_conclusion)
}
+32
View File
@@ -0,0 +1,32 @@
name: List Target Branches
on:
workflow_call:
# Map the workflow outputs to job outputs
outputs:
branches:
description: "List of target branches"
value: ${{ jobs.list-target-branches.outputs.matrix }}
jobs:
list-target-branches:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.get-branch-list.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- id: get-branch-list
run: |
python -m detection_rules dev utils get-branches
echo "::set-output name=matrix::$(cat ./detection_rules/etc/target-branches.yml)"
+5 -5
View File
@@ -31,7 +31,11 @@ jobs:
- name: Python License Check
run: |
python -m detection_rules dev license-check
- name: Unit tests
run: |
python -m detection_rules test
- name: Build release package
env:
# only generate the navigator files on push events to main
@@ -48,10 +52,6 @@ jobs:
path: |
releases
- name: Unit tests
run: |
python -m detection_rules test
- name: Update navigator gist files
env:
GITHUB_TOKEN: "${{ secrets.NAVIGATOR_GIST_TOKEN }}"