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

CI: report failures on discord #19801

Merged
merged 25 commits into from
Nov 14, 2022
Merged
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
37 changes: 36 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ executors:
orbs:
git-shallow-clone: guitarrapc/[email protected]
browser-tools: circleci/[email protected]
discord: antonioned/[email protected]

commands:
# Forked off from https://github.com/guitarrapc/git-shallow-clone-orb
Expand Down Expand Up @@ -175,6 +176,30 @@ commands:
echo "Canceling workflow as previous step resulted in failure."
echo "To execute all checks locally, please run yarn ci-tests"
curl -X POST --header "Content-Type: application/json" "https://circleci.com/api/v2/workflow/${CIRCLE_WORKFLOW_ID}/cancel?circle-token=${WORKFLOW_CANCELER}"
list-recent-merges:
description: 'Lists the merge commits from the past 24 hours'
steps:
- run:
name: Listing merge commits from the past 24 hours
when: on_fail
command: |
git log --merges --since="24 hours ago" --pretty=format:"\`%h\` %<(12)%ar | %s [%an]" | grep "Merge pull request" | sed "s/Merge pull request #/https:\/\/github.com\/storybookjs\/storybook\/pull\//g"
report-workflow-on-failure:
description: 'Reports failures to discord'
parameters:
template:
description: |
Which template to report in discord
type: string
steps:
- run:
when: on_fail
command: git fetch --unshallow
- list-recent-merges
- discord/status:
only_for_branches: next,alpha
fail_only: true
failure_message: 'Oh no! The **$CIRCLE_JOB** job has failed for **<< parameters.template >>**.\n\n**Relevant PRs of the last 24h:**\n$(git log --merges --since="24 hours ago" --pretty=format:"\`%h\` %<(12)%ar %s [%an]" | grep "Merge pull request" | sed "s/Merge pull request #/https:\/\/github.com\/storybookjs\/storybook\/pull\//g" | tr "\\n" "\\\\n" | sed "s/\\\\/\\\\n/g")'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tr and sed are used to replace line breaks with literal \n so they can display multiline results in discord:

image

jobs:
build:
executor:
Expand Down Expand Up @@ -410,7 +435,9 @@ jobs:
at: .
- run:
name: Creating Sandboxes
command: yarn task --task sandbox --template $(yarn get-template << pipeline.parameters.workflow >> create) --no-link --start-from=never --junit
command: yarn task --task sandbox --template $(yarn get-template << pipeline.parameters.workflow >> sandbox) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> sandbox)
- persist_to_workspace:
root: .
paths:
Expand All @@ -434,6 +461,8 @@ jobs:
- run:
name: Smoke Testing Sandboxes
command: yarn task --task smoke-test --template $(yarn get-template << pipeline.parameters.workflow >> smoke-test) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> smoke-test)
- store_test_results:
path: test-results
build-sandboxes:
Expand All @@ -453,6 +482,8 @@ jobs:
- run:
name: Building Sandboxes
command: yarn task --task build --template $(yarn get-template << pipeline.parameters.workflow >> build) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> build)
- store_test_results:
path: test-results
- persist_to_workspace:
Expand All @@ -476,6 +507,8 @@ jobs:
- run:
name: Running Test Runner
command: yarn task --task test-runner --template $(yarn get-template << pipeline.parameters.workflow >> test-runner) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> test-runner)
- store_test_results:
path: test-results
chromatic-sandboxes:
Expand Down Expand Up @@ -513,6 +546,8 @@ jobs:
- run:
name: Running E2E Tests
command: yarn task --task e2e-tests --template $(yarn get-template << pipeline.parameters.workflow >> e2e-tests) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> e2e-tests)
- store_test_results:
path: test-results
- store_artifacts: # this is where playwright puts more complex stuff
Expand Down