Skip to content

Commit 3af5fd6

Browse files
feat: use labels for test execution on PRs to main (#208)
## Context So far, PRs to `main` by default have all the tests enabled. Applying labels to enable particular tests is available only for PRs that are not to `main`. Our team doesn't use `develop` branch, thus we need to be able to skip some tests on PRs to `main` - to get feedback quickly. ## Summary of changes - This PR makes it possible to use labels for enabling/disabling tests also on PRs to `main`. - apart from test labels (`execute_knowledge`, etc.), `use_labels` label has to be applied to the PR before (re)opening it to make test labels work - this is to ensure that execution of all tests is still the default option for PRs to `main` ## Sample CI/CD runs for PR PR: splunk/splunk-add-on-for-microsoft-cloud-services#993 Workflow runs: - with `use_labels` label: https://github.com/splunk/splunk-add-on-for-microsoft-cloud-services/actions/runs/7338668760 - with `use_labels` and `execute_knowledge` labels: https://github.com/splunk/splunk-add-on-for-microsoft-cloud-services/actions/runs/7338999846/job/19982527979 - with no labels: https://github.com/splunk/splunk-add-on-for-microsoft-cloud-services/actions/runs/7339852310/job/19984825125 --------- Co-authored-by: Artem Rys <rysartem@gmail.com>
1 parent 4f3fa4d commit 3af5fd6

File tree

2 files changed

+31
-77
lines changed

2 files changed

+31
-77
lines changed

.github/workflows/reusable-build-test-release.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,18 @@ jobs:
157157
158158
case "${{ github.event_name }}" in
159159
"pull_request")
160-
if ${{ github.base_ref == 'main' }} || ${{ contains(github.event.pull_request.labels.*.name, 'execute_all_tests') }}; then
160+
labels=$(echo '${{ toJSON(github.event.pull_request.labels) }}' | jq -r '.[] | .name')
161+
if ${{ github.base_ref == 'main' }} && ${{ contains(github.event.pull_request.labels.*.name, 'use_labels') }}; then
162+
for test_type in "${TESTSET[@]}"; do
163+
if [[ "$labels" =~ $test_type ]]; then
164+
EXECUTE_LABELED["$test_type"]="true"
165+
fi
166+
done
167+
elif ${{ github.base_ref == 'main' }} || ${{ contains(github.event.pull_request.labels.*.name, 'execute_all_tests') }}; then
161168
for test_type in "${TESTSET[@]}"; do
162169
EXECUTE_LABELED["$test_type"]="true"
163170
done
164171
else
165-
labels=$(echo '${{ toJSON(github.event.pull_request.labels) }}' | jq -r '.[] | .name')
166172
for test_type in "${TESTSET[@]}"; do
167173
if [[ "$labels" =~ $test_type ]]; then
168174
EXECUTE_LABELED["$test_type"]="true"
@@ -2699,7 +2705,7 @@ jobs:
26992705
- name: exit without publish
27002706
if: ${{ steps.check.outputs.run-publish == 'false' || ( github.event.action == 'labeled' && github.event.label.name == 'preserve_infra' ) }}
27012707
run: |
2702-
echo " Some test job failed or Workflow has triggred on preserve_infra label. "
2708+
echo "Some test job failed or Workflow has triggered on preserve_infra label."
27032709
exit 1
27042710
27052711
publish:

README.md

Lines changed: 22 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,34 @@
1-
# addonfactory-workflow-addon-release
2-
Repository to store reusable `build-test-release` workflow, which is used to release Splunk add-ons.
3-
Worklow is used by add-ons created and managed by [addonfactory repository template](https://github.com/splunk/addonfactory-repository-template)
4-
Workflow defines jobs which perform security code scanning, execute different types of tests, build add-on package, make github release.
5-
6-
## Example usage
7-
```yaml
8-
name: build-test-release
9-
on:
10-
push:
11-
branches:
12-
- "main"
13-
tags:
14-
- "v[0-9]+.[0-9]+.[0-9]+"
15-
pull_request:
16-
branches:
17-
- "**"
18-
# explicitly configure permissions, in case your GITHUB_TOKEN workflow permissions are set to read-only in repository settings
19-
permissions:
20-
actions: read
21-
checks: write
22-
contents: write
23-
deployments: read
24-
packages: write
25-
pull-requests: read
26-
statuses: write
27-
jobs:
28-
call-workflow:
29-
uses: splunk/addonfactory-workflow-addon-release/.github/workflows/reusable-build-test-release.yml@v1.2.0
30-
secrets:
31-
GH_TOKEN_ADMIN: ${{ secrets.GH_TOKEN_ADMIN }}
32-
SEMGREP_PUBLISH_TOKEN: ${{ secrets.SEMGREP_KEY }}
33-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
34-
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
35-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
36-
VT_API_KEY: ${{ secrets.VT_API_KEY }}
37-
OTHER_TA_REQUIRED_CONFIGS: ${{ secrets.OTHER_TA_REQUIRED_CONFIGS }}
38-
FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }}
39-
SA_GH_USER_NAME: ${{ secrets.SA_GH_USER_NAME }}
40-
SA_GH_USER_EMAIL: ${{ secrets.SA_GH_USER_EMAIL }}
41-
SA_GPG_PRIVATE_KEY: ${{ secrets.SA_GPG_PRIVATE_KEY }}
42-
SA_GPG_PASSPHRASE: ${{ secrets.SA_GPG_PASSPHRASE }}
43-
SPL_COM_USER: ${{ secrets.SPL_COM_USER }}
44-
SPL_COM_PASSWORD: ${{ secrets.SPL_COM_PASSWORD }}
45-
```
46-
47-
***
1+
# Reusable workflow
482

49-
# Troubleshooting for different workflow stages in Github Actions
50-
51-
General troubleshooting
52-
=======================
3+
This repository stores reusable `build-test-release` workflow, which is used to build, test and release Splunk add-ons.
534

54-
- For each stage there are logs which provides list of failures or link the test report for the stage or more details like error code regarding what caused the stage to fail.
5+
Workflow is used by add-ons created and managed by [addonfactory repository template](https://github.com/splunk/addonfactory-repository-template).
556

56-
- If execution of stage takes longer than expected and we can re-trigger a workflow with an empty commit to check is the issue with the stage is consistent.
7+
Workflow defines jobs which perform security code scanning, execute different types of tests, build add-on package and make a GitHub release.
578

58-
- If the stage starts failing without any code change we can check the version of action used in the Github actions pipeline and check the behaviour with previous releases.
9+
# Troubleshooting for different workflow stages in GitHub Actions
5910

60-
- Check if there is any similar issue reported to Github repo for the action by other users.
11+
## General troubleshooting
6112

62-
- Validate If the failure is caused by a code change in the action which modified behaviour in the latest release causing the stage to fail.
13+
* For each stage there are logs which provides list of failures or link the test report for the stage or more details like error code regarding what caused the stage to fail.
14+
* Check if there is any similar issue reported to GitHub repo for the action by other users.
15+
* If you are not sure what to do, please use `go/addon/help`.
6316

17+
## setup-workflow
6418

65-
setup-workflow
66-
=======================
67-
68-
**Description:**
69-
- Job that is scanning pull_request and based on PR body or included labels defining tests to be executed or infrastructures to be preserved.
70-
- To preserve infrastructure:
71-
- add to PR label `preserve_infra`
72-
- add to PR description add `preserve: {comma separated list of test type}`
73-
- available choices: `knowledge ui modinput_functional scripted_inputs escu requirement_test`
74-
- to trigger tests again, reapply `preserve_infra` label
75-
- To trigger specified test type
76-
- add to PR one or multiple labels
77-
- available choices: `execute_knowledge execute_ui execute_modinput_functional execute_scripted_inputs execute_escu execute_requirement_test execute_all_tests`
78-
- adding labels will result retriggering job
79-
- All tests are executed by default when:
80-
- PR target branch is 'main'
81-
- PUSH event on branches 'main', 'develop' and on tags (on release)
82-
- SCHEDULE event
19+
Job that is scanning PR and based on PR body or included labels defining tests to be executed or infrastructures to be preserved.
8320

21+
* To preserve infrastructure
22+
* add to PR label `preserve_infra`
23+
* add to PR description add `preserve: {comma separated list of test type}`, available choices: `knowledge ui modinput_functional scripted_inputs requirement_test`
24+
* to trigger tests again, reapply `preserve_infra` label
25+
* All tests are executed by default when (controlled from [here](https://github.com/splunk/addonfactory-repository-template/blob/main/enforce/.github/workflows/build-test-release.yml))
26+
* PR target branch is `main` (unless `use_labels` label is used then specific test labels (see below) should be added to execute specific test types)
27+
* push event on branches `main`, `develop` and on `tags` (on release)
28+
* schedule event (controlled from [here](https://github.com/splunk/addonfactory-repository-template/blob/main/tools/jinja_parameters.yml))
29+
* To trigger specific test type
30+
* add to PR one or multiple labels, available choices can be found [here](https://github.com/splunk/addonfactory-workflow-addon-release/blob/4f3fa4d779b6ec7649f0dc6b973eb4d68e5fcc48/.github/workflows/reusable-build-test-release.yml#L153)
31+
* there is no need to add labels when PR's target branch is `main`
8432

8533
meta stage
8634
=======================

0 commit comments

Comments
 (0)