Skip to content

Commit

Permalink
ci: implementing new workflow using kash repository
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-greffe committed Mar 11, 2024
1 parent 063005e commit b6f4cde
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 33 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,14 @@ jobs:
- name: Run tests
env:
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
run: bash ./scripts/run_tests.sh -n ${{ matrix.node }}
slack_notification:
runs-on: ubuntu-latest
if: ${{ always() }}
needs: [run_tests]
steps:
- name: Run tests
env:
TEST_RESULT: ${{ needs.run_tests.result }}
SLACK_WEBHOOK_LIBS: ${{ secrets.SLACK_WEBHOOK_LIBS }}
run: bash ./scripts/run_tests.sh -n ${{ matrix.node }} -m ${{ matrix.mongo }}
run: bash ./scripts/slack_notification.sh
33 changes: 1 addition & 32 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,4 @@ yarn && yarn test
##

install_cc_test_reporter ~
send_coverage_to_cc 8e87a996279373f05f01ce8166aac1bc9dda990e9a2f936af25e5aa11326b127

## Notify on slack
##
get_git_commit_url() {
local ROOT_DIR="$1"
local REPO_NAME="$2"
local COMMIT_SHA
COMMIT_SHA=$(get_git_commit_sha "$ROOT_DIR")

local GITHUB_REPO_URL="https://github.com/kalisio/$REPO_NAME"
local COMMIT_URL="$GITHUB_REPO_URL/commit/$COMMIT_SHA"

echo "$COMMIT_URL"
}

generate_slack_message() {
local ROOT_DIR="$1"
local APP="$2"
local COMMIT_SHA
local COMMIT_URL
local AUTHOR
COMMIT_SHA=$(get_git_commit_sha "$ROOT_DIR")
COMMIT_URL=$(get_git_commit_url "$ROOT_DIR")
AUTHOR=$(get_git_commit_author_name "$THIS_DIR")

echo "Build ([$COMMIT_SHA]($COMMIT_URL)) of $APP by $AUTHOR passed"
}

message=$(generate_slack_message "$ROOT_DIR" "$APP")

slack_color_log "$SLACK_WEBHOOK_LIBS" "$message" "#008000"
send_coverage_to_cc 8e87a996279373f05f01ce8166aac1bc9dda990e9a2f936af25e5aa11326b127
52 changes: 52 additions & 0 deletions scripts/slack_notification.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -euo pipefail
# set -x

THIS_FILE=$(readlink -f "${BASH_SOURCE[0]}")
THIS_DIR=$(dirname "$THIS_FILE")
ROOT_DIR=$(dirname "$THIS_DIR")

## Notify on slack
##
get_git_commit_url() {
local ROOT_DIR="$1"
local REPO_NAME="$2"
local COMMIT_SHA
COMMIT_SHA=$(get_git_commit_sha "$ROOT_DIR")
local GITHUB_REPO_URL="https://github.com/kalisio/$REPO_NAME"
local COMMIT_URL="$GITHUB_REPO_URL/commit/$COMMIT_SHA"
echo "$COMMIT_URL"
}

generate_slack_message() {
local ROOT_DIR="$1"
local APP="$2"
local TEST_RESULT="$3"
local COMMIT_SHA
local COMMIT_URL
local AUTHOR
local BUILD_STATUS
COMMIT_SHA=$(get_git_commit_sha "$ROOT_DIR")
COMMIT_URL=$(get_git_commit_url "$ROOT_DIR")
AUTHOR=$(get_git_commit_author_name "$THIS_DIR")
if [ "$TEST_RESULT" = "failure" ]; then
BUILD_STATUS="failed"
else
BUILD_STATUS="passed"
fi
echo "Build ([${COMMIT_SHA}](${COMMIT_URL})) of $APP by $AUTHOR $BUILD_STATUS"
}

get_slack_color() {
local TEST_RESULT="$1"
if [ "$TEST_RESULT" = "failure" ]; then
echo "#a30200"
else
echo "#2eb886"
fi
}

MESSAGE=$(generate_slack_message "$ROOT_DIR" "$APP" "$TEST_RESULT")
COLOR=$(get_slack_color "$TEST_RESULT")

slack_color_log "$SLACK_WEBHOOK_LIBS" "$MESSAGE" "$COLOR"

0 comments on commit b6f4cde

Please sign in to comment.