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

Skip “Percy screenshots” when secrets are unavailable on forks (fix) #3075

Merged
merged 1 commit into from
Dec 21, 2022

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Dec 6, 2022

Looks like our "local branches only" check for Percy screenshots didn't work

I'd forgotten that workflows for fork PRs identify our repo making this check always pass: 🙈

Use the github.repository_owner context

if: ${{ github.repository_owner == 'alphagov' }}

Use the github.event context to identify forks

if: ${{ !github.event.pull_request.head.repo.fork }}

For example, this PR (fork) has passed the incorrect check and tried to run Percy

But others (my fork) use the new check and Percy has been skipped:

Unlike the old fix, Percy is not skipped when run directly from the fork:

This allows contributors to add their own ${{ secrets.PERCY_TOKEN }} but with a warning if not provided:

Percy secret warning

@colinrotherham colinrotherham added 🐛 bug Something isn't working the way it should (including incorrect wording in documentation) Frontend squad labels Dec 6, 2022
@colinrotherham colinrotherham requested a review from a team as a code owner December 6, 2022 12:16
@colinrotherham colinrotherham force-pushed the percy-pr-filter branch 2 times, most recently from a92fae6 to a6a3cd4 Compare December 7, 2022 17:23
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3075 December 15, 2022 11:21 Inactive
@colinrotherham colinrotherham force-pushed the percy-pr-filter branch 7 times, most recently from 339def3 to 2f1c6f8 Compare December 21, 2022 12:59
@@ -18,7 +18,14 @@ jobs:
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
PORT: 8888

# Skip when secrets are unavailable on forks
if: ${{ !github.event.pull_request.head.repo.fork }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For our typical "PRs from forks" scenario this line skips the Percy screenshots

steps:
- name: Check secrets
if: ${{ !env.PERCY_TOKEN }}
run: echo "::warning title=GitHub Actions secrets::Workflow requires 'PERCY_TOKEN' secret"
Copy link
Contributor Author

@colinrotherham colinrotherham Dec 21, 2022

Choose a reason for hiding this comment

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

But for more advanced contributors that might run the GitHub Actions workflows manually (on their fork) we add a warning message alongside the error output to explain why the Percy run failed:

Percy secret warning

@colinrotherham
Copy link
Contributor Author

Ready for review again @domoscargin

Copy link
Contributor

@domoscargin domoscargin left a comment

Choose a reason for hiding this comment

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

Nice, I think this looks good now!

@colinrotherham colinrotherham merged commit a930cb0 into main Dec 21, 2022
@colinrotherham colinrotherham deleted the percy-pr-filter branch December 21, 2022 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working the way it should (including incorrect wording in documentation)
Projects
Development

Successfully merging this pull request may close these issues.

3 participants