Skip to content

sync-rtd-redirects: Skip when RTD_TOKEN is empty - #33

Closed
victorlin wants to merge 1 commit into
masterfrom
victorlin/sync-rtd-redirects/conditional-sync
Closed

victorlin wants to merge 1 commit into
masterfrom
victorlin/sync-rtd-redirects/conditional-sync

Conversation

@victorlin

@victorlin victorlin commented Nov 30, 2022 •

Copy link
Copy Markdown
Member

Description of proposed changes

RTD redirects can only be synced with a valid RTD_TOKEN. If it is an empty string, it must be invalid. Ideally, making the secret required would catch all invalid token errors, however an empty string still passes the requirement. This job-level condition is the next best thing.

When called with an empty token, the workflow will still be triggered as configured but the job will be skipped instead of failing due to an invalid RTD token.

Related issue(s)

Testing

  • Checks pass (but they don't test this reusable workflow)
  • Skips job on a repo that doesn't have RTD_TOKEN available
  • Runs job on a repo with RTD_TOKEN available

@victorlin victorlin self-assigned this Nov 30, 2022
@victorlin
victorlin force-pushed the victorlin/sync-rtd-redirects/conditional-sync branch from 68eece8 to e70fdf5 Compare November 30, 2022 23:30
@victorlin
victorlin marked this pull request as ready for review November 30, 2022 23:39
@victorlin
victorlin requested a review from a team November 30, 2022 23:39

jobs:
sync:
if: ${{ !(inputs.run-on-nextstrain-only) || github.repository_owner == 'nextstrain' }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Though I agree we only intend/expect this workflow to run on our repos, there's nothing specific to Nextstrain about it, and I wouldn't begrudge anyone from using it outside of Nextstrain (though I'd probably just make a copy myself). The run-on-nextstrain-only option as a bypass aligns with that too. So if the sole goal is to prevent errors on forks that aren't configured with a token, then what about skipping the job when RTD_TOKEN isn't defined/available instead of checking repo owner?

Separately, the reason ${{ }} is "required" despite the docs saying it isn't is because the file still has to be valid YAML syntax. While strings in YAML can normally be unquoted, there are exceptions where quotes are required, such as when specific YAML metachars are present in the string. The leading !... | construct here in the condition is the culprit that requires quoting, as it's a type tag (!...) and block scalar start (|). So the ${{ }} changes that by making the !... no longer a type tag, and thus the | no longer a block scalar start. The point is that using normal YAML quoted strings:

if: "!(inputs.run-on-nextstrain-only) || github.repository_owner == 'nextstrain'"

works just as well as an unquoted ${{ ... }}.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

what about skipping the job when RTD_TOKEN isn't defined/available instead of checking repo owner?

This sounds better 👍 I'll rework this PR with that approach.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Wow, nice explanation! I wasn't aware of that YAML stuff and was only thinking in terms of the GitHub Actions Expressions doc. I'll quote you in the GitHub docs issue I created yesterday when I thought it was a bug.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tried 56037a0 but it's not that simple... secrets can't be used in if 🫤 actions/runner#520

So there's no way to condition on the job level, but there might be a way to conditionally skip the steps that use RTD_TOKEN. I'll try that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ahh, hmm. The (un)availability of secrets in job.if is indeed noted in the docs.

RTD redirects can only be synced with a valid RTD_TOKEN. If it is an
empty string, it must be invalid. Ideally, making the secret required
would catch all invalid token errors, however an empty string still
passes the requirement. This job-level condition is the next best thing.

When called with an empty token, the workflow will still be triggered as
configured but the job will be skipped instead of failing due to an
invalid RTD token.
@victorlin victorlin changed the title sync-rtd-redirects: Skip on fork repositories sync-rtd-redirects: Skip when RTD_TOKEN is empty Dec 1, 2022
@victorlin
victorlin force-pushed the victorlin/sync-rtd-redirects/conditional-sync branch from e70fdf5 to 56037a0 Compare December 1, 2022 18:59
@victorlin
victorlin marked this pull request as draft December 1, 2022 19:12
@tsibley

tsibley commented Jun 12, 2024

Copy link
Copy Markdown
Contributor

Closing this as it stalled out and doesn't seem necessary. We can always re-open/re-visit it if we find ourselves hung up by missing/empty tokens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants