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

Handle missing token on Rector CI workflow on forks #3433

Merged
merged 5 commits into from
Mar 1, 2023

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Mar 1, 2023

@TomasVotruba @jackbentley this is to avoid error on running on fork, see https://github.com/rectorphp/rector-src/actions/runs/4305120316/jobs/7507111232#step:2:1 on PR #3430

@jackbentley please rebase your PRs after this merged.

@samsonasik samsonasik enabled auto-merge (squash) March 1, 2023 22:08
@samsonasik samsonasik merged commit 4bd93ba into main Mar 1, 2023
@samsonasik samsonasik deleted the handle-missing-token-on-rector-workflow branch March 1, 2023 22:17
# in forks, the token is not available - so we cannot use it
-
if: github.event.pull_request.head.repo.full_name != github.repository
uses: actions/checkout@v3
Copy link
Member

Choose a reason for hiding this comment

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

This should never run, as this conditoin is never met:

if: github.repository == '__CURRENT_REPOSITORY__'

If that condition is wrong, it should be fixed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@TomasVotruba looking at other repo implementation, the if seems before steps instead of before strategy

https://github.com/PostHog/posthog/blob/e5c44a044f316c41223da3ee6aad2234746a2522/.github/workflows/storybook-deploy.yml#L12

That's seems the reason why steps was always executed

Copy link
Member

Choose a reason for hiding this comment

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

These miss-steps should be prevent by the if. How does the Google Acitons docs address this?

Maybe we have to define it on the more parent configuration?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so, strategy and steps is inlined, so it is something like code:

if 1 < 0
echo "foo" <- strategy
echo "bar" <- steps

above code, "bar" is shown as not belong to if, so if we want "bar" is not executed, the if need to before echo "bar"

echo "foo"<- strategy
if 1 < 0
echo "bar"<- steps

if I understand correctly, strategy is definition, steps is the execution.

Copy link
Member

Choose a reason for hiding this comment

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

So what is the best way to disable whole workflow with one condition?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the issue is that when GitHub runs a pull_request event it actually runs it in the base repository on a temporary branch which I think is a merge of the target and the head. Thus the github.repository == 'rectorphp/rector-src' returns true. e.g. refs/remotes/pull/3430/merge

You need to check the repository or the head branch specifically - as has been done in the individual steps github.event.pull_request.head.repo.full_name. I'm not sure if there's a shorter variable to get it or not

Copy link
Member

Choose a reason for hiding this comment

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

@jackbentley Thanks for the tip, I'll try that 👍

Is there a way to dump all the github metadata in workflow? It might be easier to just see the values there :)

Copy link
Member

Choose a reason for hiding this comment

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

@jackbentley Seem it's not the right value, the Rector workflow is skipped:
#3439

Copy link
Contributor

Choose a reason for hiding this comment

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

I know if you enable debug it will output/let you download a dump of the entire github variable. I've seen you might be able to enable it on re-run via the action page also. I think it gives you the option of "re running with debug enabled" or something like that - haven't used that way myself though

https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging

Edit: If you click the "Re-run all jobs" button there's a checkbox in the bottom left of the modal to "Enable debug logging"

samsonasik added a commit that referenced this pull request May 8, 2023
* Handle missing token on Rector CI workflow

* test add unused property to run rectify

* update templates workflow for require token

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants