Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add options to download test suites #37

Merged
merged 15 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ dist/**/*
yarn.lock

/.cache_ggshield
/reports/src/
/test/runner.iff.test.ts
43 changes: 39 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,53 @@ steps:
depends_on: my-test
allow_dependency_failure: true
plugins:
- iress/junit-slack-notification#v1.0.3:
- iress/junit-slack-notification#v1.0.4b:
artifacts: "**/*.xml"
SLACK_TOKEN: "xoxb-xxxxxxxxxxx-xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx"
SLACK_CHANNEL: "#junit_bot_testing"
```
or
```yml
steps:
- label: Run unit tests
key: my-unit-test
command: ...
- label: Run Verification tests
key: my-verification-test
command: ...

- label: ":slack: :memo: to #junit_bot_testing"
depends_on: my-test
allow_dependency_failure: true
plugins:
- iress/junit-slack-notification#v1.0.4b:
test_suites:
- name: "Unit tests"
artifacts: "unit-test/**/*.xml"
- name: "Verification tests"
artifacts: "verification-test/**/*.xml"
SLACK_TOKEN: "xoxb-xxxxxxxxxxx-xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx"
SLACK_CHANNEL: "#junit_bot_testing"
```

## Configuration

### `artifacts` (Required, string)
### `artifacts` (Use if no `test_suites`, string, default `**/*.xml` )

The file pattern to use to retrieve JUnit XML reports

### `test_suites` (object)

The file pattern to use to retrieve JUnit XML reports
e.g. **/*.xml
The object containing the JUnit XML reports. The object should be in the following format:

```yml
test_suites:
- name: "Test Suite 1"
artifacts: "test-suite-1/**/*.xml"
- name: "Test Suite 2"
artifacts: "test-suite-1/**/*.xml"

```

### `SLACK_CHANNEL` (Required, string)

Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ services:
BUILDKITE_BUILD_AUTHOR: ${BUILDKITE_BUILD_AUTHOR}
NPM_REGISTRY: ${NPM_REGISTRY}
NPM_TOKEN: ${NPM_TOKEN}
ARTIFACTS: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_ARTIFACTS}
TEST_SUITES_0_ARTIFACTS: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_TEST_SUITES_0_ARTIFACTS}
TEST_SUITES_0_NAME: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_TEST_SUITES_0_NAME}
TEST_SUITES_1_ARTIFACTS: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_TEST_SUITES_1_ARTIFACTS}
TEST_SUITES_1_NAME: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_TEST_SUITES_1_NAME}
TEST_SUITES_2_ARTIFACTS: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_TEST_SUITES_2_ARTIFACTS}
TEST_SUITES_2_NAME: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_TEST_SUITES_2_NAME}
TEST_SUITES_3_ARTIFACTS: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_TEST_SUITES_3_ARTIFACTS}
TEST_SUITES_3_NAME: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_TEST_SUITES_3_NAME}
TEST_SUITES_4_ARTIFACTS: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_TEST_SUITES_4_ARTIFACTS}
TEST_SUITES_4_NAME: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_TEST_SUITES_4_NAME}
TEST_SUITES_5_ARTIFACTS: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_TEST_SUITES_5_ARTIFACTS}
TEST_SUITES_5_NAME: ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_TEST_SUITES_5_NAME}
command: /app/scripts/run.sh
volumes:
- $ARTIFACTS_DIR:/app/reports
Expand Down
43 changes: 33 additions & 10 deletions hooks/command
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
# Add excecuting permission to run
# git update-index --chmod=+x hooks/command

TOKEN_ENV_NAME="${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_SLACK_TOKEN_ENV_NAME:-SLACK_TOKEN}"
if [ -z "$DIR" ]; then
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
fi

# shellcheck source=lib/shared.bash
. "$DIR/../lib/shared.bash"

TOKEN_ENV_NAME="$(plugin_read_config SLACK_TOKEN_ENV_NAME "SLACK_TOKEN")"

TOKEN_VALUE=$(eval "echo \${$TOKEN_ENV_NAME:-}")

if [[ -z "${TOKEN_VALUE}" ]]; then
echo "Missing \$SLACK_TOKEN_ENV_NAME environment variable... looking for alternative"
TOKEN_VALUE="${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_SLACK_TOKEN}"
TOKEN_VALUE="$(plugin_read_config SLACK_TOKEN "")"
fi

export TOKEN_VALUE
Expand All @@ -18,8 +26,6 @@ fi

PLUGIN_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)/.."

echo "--- :junit: Download the junits XML"

ARTIFACTS_DIR="$(pwd)/$(mktemp -d "junits-slack-notification-plugin-artifacts-tmp.XXXXXXXXXX")"
export ARTIFACTS_DIR

Expand All @@ -31,13 +37,30 @@ trap cleanup EXIT

cd "$PLUGIN_DIR"

# Allows files download to fail (FATAL Failed to download artifacts: No artifacts found for downloading)
# and send "No tests data generated!" message to slack in this scenario
buildkite-agent artifact download \
"${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_ARTIFACTS}" \
"$ARTIFACTS_DIR"
if [[ -n "$(plugin_read_list TEST_SUITES_0_ARTIFACTS)" ]] ; then
echo "--- :junit: Download each junits XML from the Test suites"
i=0
while true; do
var="TEST_SUITES_${i}_ARTIFACTS"
if [[ -n "$(plugin_read_list $var)" ]] ; then
buildkite-agent artifact download \
"$(plugin_read_config "${var}" "")" \
"$ARTIFACTS_DIR"
i=$((i+1))
else
break
fi
done
else
echo "--- :junit: Download the junits XML"
# Allows files download to fail (FATAL Failed to download artifacts: No artifacts found for downloading)
# and send "No tests data generated!" message to slack in this scenario
buildkite-agent artifact download \
"$(plugin_read_config ARTIFACTS "**/*.xml")" \
"$ARTIFACTS_DIR"
fi

set -euo pipefail

echo "--- Send message to ${BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_SLACK_CHANNEL}"
echo "--- Send message to $(plugin_read_config SLACK_CHANNEL "???")"
make run
31 changes: 31 additions & 0 deletions lib/shared.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Shorthand for reading env config
function plugin_read_config() {
local var="BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_${1}"
local default="${2:-}"
echo "${!var:-$default}"
}

# Reads either a value or a list from plugin config
function plugin_read_list() {
prefix_read_list "BUILDKITE_PLUGIN_JUNIT_SLACK_NOTIFICATION_$1"
}

# Reads either a value or a list from the given env prefix
function prefix_read_list() {
local prefix="$1"
local parameter="${prefix}_0"

if [[ -n "${!parameter:-}" ]]; then
local i=0
local parameter="${prefix}_${i}"
while [[ -n "${!parameter:-}" ]]; do
echo "${!parameter}"
i=$((i+1))
parameter="${prefix}_${i}"
done
elif [[ -n "${!prefix:-}" ]]; then
echo "${!prefix}"
fi
}
Loading
Loading