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

Do not attempt to send screenshots to Pixel Eagle without a token #16655

Conversation

LikeLakers2
Copy link
Contributor

@LikeLakers2 LikeLakers2 commented Dec 5, 2024

Objective

Running Github Actions on forks helps users to reduce the amount of CI errors they get before submitting a PR. However, due to how workflows are set up on the Bevy repository, this can result in errors occurring for jobs that may not be related to their PR - in this case, uploading screenshots to Pixel Eagle.

Solution

The Pixel Eagle workflow is skipped if we aren't running on the Bevy repository.

If we are on the Bevy repository, or the user has set it to run elsewhere, we check if the PIXELEAGLE_TOKEN secret is set. If it isn't, we skip uploading screenshots to Pixel Eagle.

Testing

Lots. And lots. Of trying to get Github Actions to work with me.

jobs:
send-to-pixel-eagle:
name: Send screenshots to Pixel Eagle
runs-on: ubuntu-24.04
steps:
- name: Notify user on non-existent token
if: ${{ ! fromJSON(env.PIXELEAGLE_TOKEN_EXISTS) }}
Copy link
Contributor Author

@LikeLakers2 LikeLakers2 Dec 5, 2024

Choose a reason for hiding this comment

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

In case you're curious:

  • Environment variables are stored as strings. However, the strings 'true' and 'false' are valid JSON, and return booleans when converted to JSON.
  • This if: has to be on the steps - an if: conditional on the job itself cannot access to environment variables for some reason.

@IQuick143 IQuick143 added A-Build-System Related to build systems or continuous integration D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 5, 2024
Copy link
Member

@BD103 BD103 left a comment

Choose a reason for hiding this comment

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

Your current approach works, which is why I'm approving it, but we can improve it by checking what repository this is being run from.

By adding if: ${{ github.repository == "bevyengine/bevy" }}, we can skip saving the secret to an environmental variable and the various other checks.

.github/workflows/send-screenshots-to-pixeleagle.yml Outdated Show resolved Hide resolved
@LikeLakers2 LikeLakers2 requested a review from BD103 December 5, 2024 13:58
Copy link
Member

@BD103 BD103 left a comment

Choose a reason for hiding this comment

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

Could you please remove the old logic, since it no longer has any effect? (Also I'd rather avoid putting secrets in environmental variables if possible.)

@LikeLakers2
Copy link
Contributor Author

LikeLakers2 commented Dec 5, 2024

@BD103

Could you please remove the old logic, since it no longer has any effect?

It does have an effect, though.

In the old version, if secrets.PIXELEAGLE_TOKEN == '', then certain parameters to curl would be given an empty value. This results in an error from curl itself.

With the logic I added, it sets an environment variable PIXELEAGLE_TOKEN_EXISTS to the result of secrets.PIXELEAGLE_TOKEN != ''. If this is 'false', then secrets.PIXELEAGLE_TOKEN == ''. With this, we can prevent some steps from running that would otherwise error out.

(Also I'd rather avoid putting secrets in environmental variables if possible.)

I agree - and this is why the environment variable isn't the secret itself, but rather a boolean, the result of checking if secrets.PIXELEAGLE_TOKEN != ''. That way, if the environment variable is ever exposed, it won't show the token.

Copy link
Member

@BD103 BD103 left a comment

Choose a reason for hiding this comment

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

Oh, you're right! I misread:

PIXELEAGLE_TOKEN_EXISTS: ${{ secrets.PIXELEAGLE_TOKEN != '' }}

as

PIXELEAGLE_TOKEN_EXISTS: ${{ secrets.PIXELEAGLE_TOKEN }}

so I thought the environmental variable stored the secret directly. Sorry for confusion, approved!

@BD103 BD103 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 5, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 5, 2024
Merged via the queue into bevyengine:main with commit ec39f6b Dec 5, 2024
29 checks passed
@LikeLakers2 LikeLakers2 deleted the fix/disable-pixel-eagle-upload-job-without-token branch December 6, 2024 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Build-System Related to build systems or continuous integration D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants