rsm-hcd / AndcultureCode.Cli

and-cli command-line tool to manage the development of software applications
https://andculture.com
Apache License 2.0
14 stars 15 forks source link

Github Actions: Notify jobs run & fail on forked repositories #170

Closed brandongregoryscott closed 3 years ago

brandongregoryscott commented 3 years ago

Noticed this after I pulled the upstream main into my forked repo, but the notify_start, notify_success and notify_failure jobs are running and attempting to post to Slack, which fails the CI process:

https://github.com/brandongregoryscott/AndcultureCode.Cli/runs/2082422702?check_suite_focus=true

We could probably prevent that job from running by checking to see if the SLACK_BOT_TOKEN is available, or in a similar way we check for the repository owner in the build matrix, using the github context:

if: github.repository_owner == 'AndcultureCode'

The build job may need to be updated to always run with the always() function, despite depending on notify_start: see this comment for reference https://github.com/actions/runner/issues/491#issuecomment-716623031

So the build job would look more like this...

    build:
        env:
            DOTNET_NOLOGO: true
            DOTNET_CLI_TELEMETRY_OPTOUT: true
        runs-on: ${{matrix.os}}
        needs: [notify_start]
        if: always()
        ...

And the notify jobs would have this if:

jobs:
    notify_start:
        runs-on: ubuntu-latest
        # Ideally this condition would be promoted to a workflow-level environment variable and shared
        # but this doesn't seem to be supported yet https://github.community/t/how-to-set-and-access-a-workflow-variable/17335/6
        if: github.repository_owner == 'AndcultureCode'
brandongregoryscott commented 3 years ago

Fixed in https://github.com/AndcultureCode/AndcultureCode.Cli/commit/2278dc296231452a2bd51fac8e0cb483fe5abfff