-
Notifications
You must be signed in to change notification settings - Fork 523
86 lines (72 loc) · 2.9 KB
/
manual-backport.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: manual-backport
on:
workflow_dispatch:
inputs:
target_branch:
description: 'Branch to backport to (e.g. 8.0)'
required: true
commit_sha:
description: 'Sha256 hash of the merge commit to use in backporting'
required: true
exceptions:
description: 'Comma seperated list of files to skip staging e.g. detection_rules/etc/packages.yaml,detection_rules/attack.py)'
required: false
jobs:
commit:
runs-on: ubuntu-latest
steps:
- name: Checkout detection-rules
uses: actions/checkout@v4
with:
token: ${{ secrets.WRITE_TRADEBOT_DETECTION_RULES_TOKEN }}
fetch-depth: 0
- name: Set github config
run: |
git config --global user.email "178941316+tradebot-elastic@users.noreply.github.com"
git config --global user.name "tradebot-elastic"
- name: Get branch histories
run: |
git fetch origin main --depth 100
git fetch origin "${{github.event.inputs.target_branch}}" --depth 1
git fetch origin "${{github.event.inputs.commit_sha}}"
git status
git log -1 --format='%H'
- name: Checkout the commit into the staging area
run: |
# Checkout the merged commit
git checkout ${{github.event.inputs.commit_sha}}
# Move it to the staging area
git reset --soft HEAD^
- name: Setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip cache purge
pip install .[dev]
- name: Prune non-"${{github.event.inputs.target_branch}}" rules
env:
UNSTAGED_LIST_FILE: "../unstaged-rules.txt"
run: |
VERSION=$(cat detection_rules/etc/packages.yaml | grep -oP "(?<=name:\s')[\d\.]+[-\w\.]*(?=')")
python -m detection_rules dev unstage-incompatible-rules --target-stack-version "$VERSION" --exception-list "${{github.event.inputs.exceptions}}"
# Track which rules were unstaged
git diff --name-only > $UNSTAGED_LIST_FILE
# Since they've been tracked, remove any untracked files
git checkout -- .
- name: Commit and push to "${{github.event.inputs.target_branch}}"
env:
COMMIT_MSG_FILE: "../commit-message.txt"
UNSTAGED_LIST_FILE: "../unstaged-rules.txt"
TARGET_BRANCH: "${{github.event.inputs.target_branch}}"
COMMIT_SHA: "${{github.event.inputs.commit_sha}}"
run: |
./detection_rules/etc/commit-and-push.sh $TARGET_BRANCH $COMMIT_SHA
- name: "Notify slack on failure"
uses: craftech-io/slack-action@v1
with:
slack_webhook_url: ${{ secrets.READ_DETECTION_RULES_SLACK_WEBHOOK_TOKEN }}
status: failure
if: failure()