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

Support for github actions #980

Open
vrknetha opened this issue Mar 24, 2021 · 13 comments
Open

Support for github actions #980

vrknetha opened this issue Mar 24, 2021 · 13 comments
Labels
enhancement New feature or request

Comments

@vrknetha
Copy link

Send the message support for Github actions and bitbucket pipelines

@heidi-patrick
Copy link

+1 would be great

@YOU54F
Copy link
Owner

YOU54F commented Apr 12, 2021

Hey @vrknetha @heidi-patrick

Sounds like a good idea, I've not had a play with github actions yet, happy for contributions

@YOU54F YOU54F added the enhancement New feature or request label Apr 12, 2021
@bennymeade
Copy link

bennymeade commented May 11, 2021

I would love github actions support too. I did test it just to see what happens:

- name: Slack notification with total pass/fail
        if: always()
        run: |
          npx cypress-slack-reporter --report-dir mochawesome-report --ci-provider none

and SLACK_WEBHOOK_URL set in GitHub secrets.

Erroring I guess because it cannot fetch the webhook URL:

(node:901) UnhandledPromiseRejectionWarning: Error: TypeError: Cannot read property 'split' of undefined
    at Object.exports.slackRunner (/__w/cypress-reporting-gh-pages/cypress-reporting-gh-pages/node_modules/cypress-slack-reporter/bin/slack/slack-alert.js:167:15)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:901) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

@YOU54F
Copy link
Owner

YOU54F commented May 11, 2021

Hey @bennymeade, thanks for taking a look!

How do env vars get set, the script is using PROCESS.env. Are the github secrets automatically set an env vars in the runner?

@bennymeade
Copy link

Yes I believe so, in a GH Actions workflow the synatx for calling a secret is like this:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TEST_AUTOMATION }}

... and it behaves the same as an global variable.

@YOU54F
Copy link
Owner

YOU54F commented May 11, 2021

weird, could you try echoing it out on a step, you might need to export it in your ci runner like

export SLACK_WEBHOOK_URL = ${{ secrets.SLACK_WEBHOOK_TEST_AUTOMATION }} ?

@bennymeade
Copy link

echo "SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TEST_AUTOMATION }}" but obviously for security they mask the output.

SLACK_WEBHOOK_URL: ***

@YOU54F
Copy link
Owner

YOU54F commented May 11, 2021

Just looking at the docs

https://docs.github.com/en/actions/reference/encrypted-secrets#using-encrypted-secrets-in-a-workflow

steps:
  - name: Hello world action
    with: # Set the secret as an input
      super_secret: ${{ secrets.SuperSecret }}
    env: # Or as an environment variable
      super_secret: ${{ secrets.SuperSecret }}

So I think you will need something like


steps:
-  name: Slack notification with total pass/fail
   env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TEST_AUTOMATION }}
   if: always()
       run: |
         npx cypress-slack-reporter --report-dir mochawesome-report --ci-provider none

@bennymeade
Copy link

Bravo, that worked : )
image

@YOU54F
Copy link
Owner

YOU54F commented May 11, 2021

Result my mate!

How would you feel about sticking something in the readme to cover that for other github actions users, and maybe we can follow this up with a later ticket to support it as a supported --ci-provider option!

@bennymeade
Copy link

Yes definitely, I'm happy to do that @YOU54F Thanks again for your speedy responses.

@bennymeade
Copy link

bennymeade commented May 12, 2021

Here's my GH workflow for others benefit:

name: Cypress Slack notify
on:
  workflow_dispatch:

jobs:
  cypress-test:
    name: Run on Chrome 89
    runs-on: ubuntu-18.04
    container: cypress/browsers:node14.16.0-chrome89-ff86
    steps:
      - uses: actions/checkout@v2

      - name: Install Cypress with a clean slate
        run: |
          npm ci
          $(npm bin)/cypress cache path
          $(npm bin)/cypress cache list
          $(npm bin)/cypress verify

      - name: Run Cypress tests
        run: npm run cy:run

      - name: Slack notification with cypress-slack-reporter
        if: always()
        env: 
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        run: |
          npx cypress-slack-reporter --report-dir mochawesome-report --ci-provider none

with minimalist repo sample here: https://github.com/bennymeade/cypress-slack-reporter-gh-actions

@nmip
Copy link

nmip commented Jun 22, 2022

Hi @bennymeade, I followed your example and got it to work. Thanks for that!

In the Slack message, the commit link is pointing to https://github.com/undefined/undefined/commit/undefined. Did you have the same problem?

I need to pass --ci-provider github.

But the issue is I have to use a command like this:

GITHUB_REPOSITORY=my_repo npx cypress-slack-reporter --report-dir mochawesome-merged --ci-provider github

Otherwise, the commit link would have duplicated owners.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants