-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c53a234
commit 2ac7a0f
Showing
3 changed files
with
230 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
name: run tests | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
# TODO: All these inputs are not entirely necessary, they are just there for convenience of "setup Node.js" step, | ||
# where they are required. Making them optional requires additional logic, that might be un-necessary for our purposes | ||
# Best would be if "actions/setup-node" would be able to parse these from .npmrc and .nvmrc (except token of course) | ||
npmAuth: | ||
description: Whether to authenticate to NPM registry | ||
required: false | ||
type: boolean | ||
default: true | ||
nodeVersionFile: | ||
description: Path to node version file | ||
required: false | ||
type: string | ||
default: .nvmrc | ||
npmRegistryUrl: | ||
description: NPM registry url | ||
required: false | ||
type: string | ||
default: https://npm.pkg.github.com/ | ||
npmScope: | ||
description: NPM scope | ||
required: true | ||
type: string | ||
npmTestScript: | ||
description: Script for test in package.json | ||
required: true | ||
type: string | ||
title: | ||
description: Title displayed in slack message | ||
required: false | ||
type: string | ||
default: "integration tests" | ||
revision: | ||
description: Revision that is being tested (This is strictly informative) | ||
required: true | ||
type: string | ||
slackChannelId: | ||
description: Slack Channel ID | ||
required: true | ||
type: string | ||
actorOverride: | ||
description: Override the author of event | ||
required: false | ||
type: string | ||
envVariables: | ||
description: Space separated list of environment variables to be set during test phase | ||
required: false | ||
type: string | ||
# example: | ||
# envVariables: > | ||
# FOO=bar | ||
# BAR=foo | ||
|
||
secrets: | ||
npmToken: | ||
description: NPM token | ||
required: false | ||
slackToken: | ||
description: Slack API token | ||
required: true | ||
|
||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Send notification to slack | ||
uses: slackapi/[email protected] | ||
env: | ||
SLACK_BOT_TOKEN: ${{ secrets.slackToken }} | ||
with: | ||
channel-id: ${{ inputs.slackChannelId }} | ||
payload: | | ||
{ | ||
"text": ":large_blue_circle: *${{ github.repository }} ${{ inputs.title }} started*", | ||
"attachments": [ | ||
{ | ||
"color": "#0066ff", | ||
"blocks": [ | ||
{ | ||
"type": "section", | ||
"fields": [ | ||
{ | ||
"type": "mrkdwn", | ||
"text": "*Author:* ${{ inputs.actorOverride || github.actor }}" | ||
}, | ||
{ | ||
"type": "mrkdwn", | ||
"text": "*Revision:* ${{ inputs.revision }}" | ||
}, | ||
{ | ||
"type": "mrkdwn", | ||
"text": "*Details:* <${{ github.event.pull_request.html_url || github.event.head_commit.url }}|trigger>, <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|workflow run>" | ||
}, | ||
{ | ||
"type": "mrkdwn", | ||
"text": "*Triggered by:* ${{ github.event_name }}" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
- name: clone local repository | ||
uses: actions/checkout@v3 | ||
|
||
# TODO: turn on caching | ||
- name: setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
always-auth: ${{ inputs.npmAuth }} | ||
node-version-file: ${{ inputs.nodeVersionFile }} | ||
registry-url: ${{ inputs.npmRegistryUrl }} | ||
scope: ${{ inputs.npmScope }} | ||
|
||
- name: run tests | ||
run: | | ||
if [ "${{ inputs.envVariables }}" != "" ]; then | ||
export $(echo ${{ inputs.envVariables }}) | ||
fi | ||
if [ "${{ secrets.npmToken }}" != "" ]; then | ||
export NODE_AUTH_TOKEN=${{ secrets.npmToken }} | ||
fi | ||
npm install | ||
npm run ${{ inputs.npmTestScript }} | ||
- name: helper - get slack message formatting | ||
id: helper | ||
if: ${{ always() }} | ||
run: | | ||
if [ "${{ job.status }}" = "success" ] | ||
then | ||
echo ::set-output name=color::#00cc00 | ||
echo ::set-output name=emoji::large_green_circle | ||
else | ||
echo ::set-output name=color::#ff0000 | ||
echo ::set-output name=emoji::red_circle | ||
fi | ||
- name: send result to slack | ||
if: ${{ always() }} | ||
uses: slackapi/[email protected] | ||
env: | ||
SLACK_BOT_TOKEN: ${{ secrets.slackToken }} | ||
with: | ||
channel-id: ${{ inputs.slackChannelId }} | ||
payload: | | ||
{ | ||
"text": ":${{ steps.helper.outputs.emoji }}: *${{ github.repository }} ${{ inputs.title }} result: ${{ job.status }}*", | ||
"attachments": [ | ||
{ | ||
"color": "${{ steps.helper.outputs.color }}", | ||
"blocks": [ | ||
{ | ||
"type": "section", | ||
"fields": [ | ||
{ | ||
"type": "mrkdwn", | ||
"text": "*Author:* ${{ inputs.actorOverride || github.actor }}" | ||
}, | ||
{ | ||
"type": "mrkdwn", | ||
"text": "*Revision:* ${{ inputs.revision }}" | ||
}, | ||
{ | ||
"type": "mrkdwn", | ||
"text": "*Details:* <${{ github.event.pull_request.html_url || github.event.head_commit.url }}|trigger>, <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|workflow run>" | ||
}, | ||
{ | ||
"type": "mrkdwn", | ||
"text": "*Triggered by:* ${{ github.event_name }}" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |