forked from demisto/content
-
Notifications
You must be signed in to change notification settings - Fork 1
141 lines (123 loc) · 4.89 KB
/
pre-commit-reuse.yml
File metadata and controls
141 lines (123 loc) · 4.89 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: pre-commit
on:
workflow_call:
jobs:
pre-commit:
runs-on: ubuntu-22.04
permissions:
checks: write
pull-requests: write
contents: write
steps:
- name: Install poetry
uses: Gr1N/setup-poetry@48b0f77c8c1b1b19cb962f0f00dff7b4be8f81ec # v9
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 0
- name: Set PYTHONPATH
run: echo "PYTHONPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
- name: Setup python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: '3.10'
cache: 'poetry'
- name: Install dependencies
run: poetry install
- name: Cleanup Disk
run: |
USAGE=$(df / | tail -1 | awk '{print $5}' | sed 's/%//')
df -h
echo "Disk usage: ${USAGE}%"
if [ "$USAGE" -gt 75 ]; then
echo "Cleaning old Docker images"
docker image prune -af --filter "until=24h" || true
echo "Disk usage after cleanup:"
df -h
else
echo "Disk usage below threshold, skipping cleanup."
fi
- name: Cache Pre commit
id: cache-pre-commit
uses: actions/cache@6f8efc29b200d32929f49075959781ed54ec270c # v3
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit
- name: run pre-commit
env:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
BRANCH_NAME: ${{ github.head_ref }}
PR_LABELS_JSON: ${{ toJson(github.event.pull_request.labels) }}
run: |
LABEL_NAMES=$(echo "$PR_LABELS_JSON" | jq -r '.[].name')
if echo "$LABEL_NAMES" | grep -q "Contribution"; then
echo "Label 'Contribution' found!"
export DEMISTO_SDK_XSOAR_LINTER_WARNING_ANNOTATIONS=true
else
echo "Label 'Contribution' not found."
fi
source .venv/bin/activate
if [[ "$BRANCH_NAME" =~ ^AUD-demisto/.* ]]; then
echo "In docker auto update branch, pre commit on docker_autoupdate mode."
demisto-sdk pre-commit -g --mode=docker_autoupdate --show-diff-on-failure --verbose
elif [[ "$BRANCH_NAME" =~ ^packwise/.* ]]; then
echo "In packwise branch, pre commit with ignore flag."
demisto-sdk pre-commit -g --mode=packwise --show-diff-on-failure --verbose
else
echo "Not in docker auto update or packwise branch, pre-commit on CI mode."
echo "GITHUB_ACTIONS is: ${GITHUB_ACTIONS:-unset}"
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
echo "Detected GitHub Actions"
demisto-sdk pre-commit -g --validate --show-diff-on-failure --verbose --mode=check_private_packs
else
echo "Not in GitHub Actions mode"
demisto-sdk pre-commit -g --validate --show-diff-on-failure --verbose --mode=ci
fi
fi
- name: "Check coverage.xml exists"
if: always()
id: check-coverage-xml-exists
uses: andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2
with:
files: "coverage_report/coverage.xml"
- name: "Check pytest report exists"
if: always()
id: check-pytest-junit-exists
uses: andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2
with:
files: "report_pytest.xml"
- name: Create pack-wise pytest report
run: poetry run python .github/github_workflow_scripts/parse_junit_per_pack.py
if: |
always() &&
steps.check-pytest-junit-exists.outputs.files_exists == 'true' &&
github.event.pull_request.head.repo.fork == false
- name: Upload junit & pack-wise pytest report
uses: PaloAltoNetworks/upload-secure-artifact@63ccdaa66407a7684b429eac22cd0e773308d2a9 # v1.0.6
if: |
always() &&
steps.check-pytest-junit-exists.outputs.files_exists == 'true' &&
github.event.pull_request.head.repo.fork == false
with:
name: pytest
path: |
packwise_pytest_time.csv
report_pytest.xml
if-no-files-found: error
- name: Pytest coverage comment
if: |
always() &&
steps.check-coverage-xml-exists.outputs.files_exists == 'true' &&
steps.check-pytest-junit-exists.outputs.files_exists == 'true' &&
! github.event.pull_request.head.repo.fork
uses: MishaKav/pytest-coverage-comment@ef975f05ff4ca5a053e7d42ceb31000a085d17e4 # main
continue-on-error: true # may fail on output > 65k chars
with:
pytest-xml-coverage-path: coverage_report/coverage.xml
junitxml-path: report_pytest.xml
- uses: actions/cache/save@6f8efc29b200d32929f49075959781ed54ec270c # v3
if: always()
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit