Skip to content

Commit

Permalink
test: add ecosystem_ci_notify
Browse files Browse the repository at this point in the history
  • Loading branch information
9aoy committed Oct 14, 2024
1 parent 2fdda6c commit 65c717e
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 20 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/ecosystem-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Ecosystem CI

on:
push:
branches: [main]

pull_request:
branches: [main]

merge_group:

workflow_dispatch:

jobs:
ecosystem_ci_notify:
name: Run Ecosystem CI
runs-on: ubuntu-latest
if: github.repository == 'web-infra-dev/rsbuild' && github.event_name != 'workflow_dispatch'
steps:
- name: Run Ecosystem CI with notify
id: eco_ci
uses: convictional/[email protected]
with:
owner: "rspack-contrib"
repo: "rsbuild-ecosystem-ci"
workflow_file_name: "ecosystem-ci-from-commit.yml"
github_token: ${{ secrets.REPO_SCOPED_TOKEN }}
ref: "main"
client_payload: '{"commitSHA":"${{ github.sha }}","updateComment":${{ github.ref_name == 'main'}},"repo":"web-infra-dev/rsbuild","suite":"-","suiteRefType":"precoded","suiteRef":"precoded"}'

- if: steps.eco_ci.outcome == 'failure'
uses: actions/checkout@v4
- if: steps.eco_ci.outcome == 'failure'
uses: actions/setup-node@v4
with:
node-version: 20
- name: Send Failure Notification
if: steps.eco_ci.outcome == 'failure'
shell: bash
run: ./scripts/alert/lark.js
env:
TITLE: Rsbuild Ecosystem CI failed
DESCRIPTION: |
commitID: [${{github.sha}}](${{github.server_url}}/${{github.repository}}/commit/${{github.sha}})
URL: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}
LARK_WEBHOOK_URL: ${{secrets.LARK_WEBHOOK_URL}}

ecosystem_ci:
name: Run Ecosystem CI
runs-on: ubuntu-latest
if: github.repository == 'web-infra-dev/rsbuild' && github.event_name == 'workflow_dispatch'
steps:
- name: Run Ecosystem CI
id: eco_ci
uses: convictional/[email protected]
with:
owner: "rspack-contrib"
repo: "rsbuild-ecosystem-ci"
workflow_file_name: "ecosystem-ci-selected.yml"
github_token: ${{ secrets.REPO_SCOPED_TOKEN }}
ref: ${{ github.event.inputs.branch }}
client_payload: '{"commitSHA":"${{ github.sha }}","repo":"web-infra-dev/rsbuild","suite":"-","suiteRefType":"precoded","suiteRef":"precoded"}'
20 changes: 0 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,3 @@ jobs:
- name: E2E Test
if: steps.changes.outputs.changed == 'true'
run: pnpm run e2e

# ======== ecosystem_ci ========
ecosystem_ci:
name: Run Ecosystem CI
runs-on: ubuntu-latest
if: github.repository_owner == 'web-infra-dev'
# if: github.ref_name == 'main' && github.repository_owner == 'web-infra-dev'
steps:
- name: Run Ecosystem CI
id: eco_ci
uses: convictional/[email protected]
with:
owner: "rspack-contrib"
repo: "rsbuild-ecosystem-ci"
workflow_file_name: "ecosystem-ci-from-commit.yml"
propagate_failure: false
wait_workflow: false
github_token: ${{ secrets.REPO_SCOPED_TOKEN }}
ref: "main"
client_payload: '{"commitSHA":"${{ github.sha }}","repo":"web-infra-dev/rsbuild","suite":"-","suiteRefType":"precoded","suiteRef":"precoded"}'
61 changes: 61 additions & 0 deletions scripts/alert/lark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/env node

const TITLE = process.env.TITLE;
const DESCRIPTION = process.env.DESCRIPTION;
const URL = process.env.URL;
const LARK_WEBHOOK_URL = process.env.LARK_WEBHOOK_URL;
const TPL_COLOR = process.env.TPL_COLOR || 'red';
const TPL_BTN_TYPE = process.env.TPL_BTN_TYPE || 'danger'; // default primary danger

if (!TITLE || !DESCRIPTION) {
throw new Error('please input title and description');
}

if (!LARK_WEBHOOK_URL) {
console.log('missing LARK_WEBHOOK_URL, will exit');
process.exit(0);
}

const res = await fetch(LARK_WEBHOOK_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
msg_type: 'interactive',
card: {
header: {
template: TPL_COLOR,
title: {
content: TITLE,
tag: 'plain_text',
},
},
elements: [
{
tag: 'markdown',
content: DESCRIPTION,
},
URL && {
tag: 'action',
actions: [
{
tag: 'button',
text: {
content: 'Details',
tag: 'plain_text',
},
url: URL,
type: TPL_BTN_TYPE,
},
],
},
].filter(Boolean),
},
}),
});

if (!res.ok) {
const data = await res.text();
throw new Error(`send alert failed with ${data}`);
}

0 comments on commit 65c717e

Please sign in to comment.