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

Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}". #170

Open
polina-c opened this issue May 31, 2023 · 21 comments
Open

Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}". #170

polina-c opened this issue May 31, 2023 · 21 comments

Comments

@polina-c
Copy link

My repo: https://github.com/flutter-chat-dev/tic_tac_toe

Error: https://github.com/flutter-chat-dev/tic_tac_toe/actions/runs/5135214398/jobs/9240329007

Workflow:

name: Run layerlens.

on:
  push:
    branches: [ main]

jobs:
  generate_diagrams:
    runs-on: ubuntu-latest

    steps:
    - name: clone the repo
      uses: actions/checkout@v3

    - name: install Flutter sdk
      uses: subosito/flutter-action@48cafc24713cca54bbe03cdc3a423187d413aafa
      with:
        channel: 'stable'

    - name: version
      run: dart --version

    - name: dart pub get
      run: dart pub get

    - name: generate
      run: dart run layerlens

    - name: Commit files
      run: |
        echo ${{ github.ref }}
        git add .
        git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
        git config --local user.name "github-actions[bot]"
        git commit -m "CI: Automated layerlens push" -a | exit 0

    - name: Push changes
      if: github.ref == 'refs/heads/main'
      uses: ad-m/github-push-action@df39337088a4cf2782a73f221bbd33f90e3e091d
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}

Will appreciate help!!!

@ZPascal
Copy link
Collaborator

ZPascal commented May 31, 2023

Hi @polina-c, I'll check that. Do you've tried it with the corresponding ad-m/github-push-action@master version?

@polina-c
Copy link
Author

polina-c commented May 31, 2023

just checked: https://github.com/flutter-chat-dev/tic_tac_toe/actions/runs/5135574184/jobs/9241187446

The issue is different:

remote: error: GH006: Protected branch update failed for refs/heads/main.        
remote: error: At least 1 approving review is required by reviewers with write access.        

Yes, I want approval on main branch from people.
Is it possible to configure the branch to require approvals for people, but not for actions?

@ZPascal
Copy link
Collaborator

ZPascal commented May 31, 2023

@polina-c Is force push an option?

@polina-c
Copy link
Author

Yes, force push is allowed in the repo.
Are you saying I can force push in action? How I should update the workflow for this?

@polina-c
Copy link
Author

polina-c commented Jun 2, 2023

@ZPascal ?

@ZPascal
Copy link
Collaborator

ZPascal commented Jun 3, 2023

@polina-c That was just a guess whether it might work to bypass the branch protection rule. I am in the process of testing this right now. I will report when I have the results of my test.

@ZPascal
Copy link
Collaborator

ZPascal commented Jun 3, 2023

@polina-c I've got a solution for you. You need a personal access token, it's necessary to set up the branch protection rule "Allow force pushes" to "Specify who can force push" and set up your or own user. It's also better to specify the force_with_lease parameter of the push action to true.

FYI: I've tested the solution inside this action run.

@polina-c
Copy link
Author

polina-c commented Jun 3, 2023

Thank you!

Can you outline exact steps in your README.md?

@ZPascal
Copy link
Collaborator

ZPascal commented Jun 3, 2023

@polina-c Sure, I'll adjust the documentation as a follow-up.

@ZPascal
Copy link
Collaborator

ZPascal commented Jun 6, 2023

@polina-c Can we close this issue?

@polina-c
Copy link
Author

polina-c commented Jun 6, 2023

I checked the documentation. Is it correct understanding that I am missing 'force_with_lease: true' in my script?
Let me try it.

@polina-c
Copy link
Author

polina-c commented Jun 6, 2023

It seems personal access token is necessary. Any chance you can outline or link steps?
There are different types of access tokens in github. How exactly they should be created to make it working?

@polina-c
Copy link
Author

polina-c commented Jun 9, 2023

In your test script dummy2 (that succeeded) still uses secrets.GITHUB_TOKEN, that is not custom access token, but is standard githib job access token.

https://github.com/ZPascal/test_origin_push_action/blob/main/.github/workflows/test.yml

Am I missing something?

@ZPascal
Copy link
Collaborator

ZPascal commented Jun 25, 2023

Hi @polina-c,

I checked the documentation. Is it correct understanding that I am missing 'force_with_lease: true' in my script?
Let me try it.

This relates to your case. I had the problem that it was not possible for me to push directly to the repository, and I had to use the force_with_lease option.

It seems personal access token is necessary. Any chance you can outline or link steps?
There are different types of access tokens in github. How exactly they should be created to make it working?

Yes, that is correct, the PAT is necessary for your case. I will create documentation on how to create the token and also publish it in the documentation of the action itself as a follow-up.

In your test script dummy2 (that succeeded) still uses secrets.GITHUB_TOKEN, that is not custom access token, but is standard githib job access token.
https://github.com/ZPascal/test_origin_push_action/blob/main/.github/workflows/test.yml
Am I missing something?

Yes, that's right, I've used the classical token to perform a checkout of the repository, but I've used the PAT for the push itself.

If you have any further questions, please feel free to ping me.

@nriss
Copy link

nriss commented Jul 4, 2023

Hi @ZPascal,

I think we've got the same problem there:
https://github.com/ansforge/IG-documentation/actions/runs/5455795460

We created an organization secret that isn't recognized apparently

@ZPascal
Copy link
Collaborator

ZPascal commented Jul 4, 2023

Hi @nriss,

it's necessary that you've specified the corresponding custom token inside triggered workflow file or forward it to the other action inside the other repository. The default token ${{ secrets.GITHUB_TOKEN }} can only be used inside the triggered repository.

It's in general necessary that you set up an custom personal access token and specify it as described in the following code sample or forward it to the executed GH Action at the end.

    - name: Push changes
      if: github.ref == 'refs/heads/main'
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.PAT }}

@zhu-xiaowei
Copy link

zhu-xiaowei commented Aug 21, 2023

https://github.com/ansforge/IG-documentation/actions/runs/5455795460

Hi~ I also meets this error, after I try to add PAT token when checkout, the push action is works well.

- uses: actions/checkout@v3
  with:
    ref: main
    token : ${{ secrets.PAT }}

and also i tried without setting PAT token in actions/checkout@v3 the ad-m/github-push-action@master action also will be failed with above error. @ZPascal this might be the root cause of the problem, might consider adding it to README.md

@ZPascal
Copy link
Collaborator

ZPascal commented Aug 22, 2023

@zhu-xiaowei I'm a bit surprised, because I've tested it my test case the mixture between default token and PAT. I'll set up a new test case to further investigate the topic.

@zhu-xiaowei
Copy link

zhu-xiaowei commented Aug 22, 2023

@ZPascal the Test1 with default GitHub token is failed with above error, and the Test2 with PAT is successful, the only difference of this two test is the token set in the checkout action.

for more background information:

  1. The protected branch is main, and checked Require a pull request before merging
  2. Added Allow specified actors to bypass required pull requests to my account.
  3. Checked Require status checks to pass before merging
  4. Unchecked Do not allow bypassing the above settings
  5. The PAT is generated in my account with required permission, and tested to push to main branch is successful in terminal.

So, I think there may be some difference between my settings and your test case settings.

@zhu-xiaowei
Copy link

@ZPascal I also test this case for only set the PAT as token in checkout@v3 action, that is also successful, and I found the description of token in checkout action:

# Personal access token (PAT) used to fetch the repository. The PAT is configured
# with the local git config, which enables your scripts to run authenticated git
# commands. The post-job step removes the PAT.

So, I think the reason is that the checkout action will set the PAT to the local git configuration and allow the following git commands to authenticate with the correct permissions. I don't know if github-push-action has changed the local git configuration with the set PAT token and made it allow authorization.

@ZPascal
Copy link
Collaborator

ZPascal commented Aug 27, 2023

Hi @zhu-xiaowei,

So, I think there may be some difference between my settings and your [test case](https://github.com/ZPascal/test_origin_push_action/actions/runs/5165266723/workflow#L49) settings.

Yes, there is a difference. Unfortunately, I failed to specify the right branch inside my test case, which was in the end not protected. Especially for the --force-with-lease flag we need the corresponding valid branch already inside the checkout action.

I don't know if github-push-action has changed the local git configuration with the set PAT token and made it allow authorization.

The github-push-action does not overwrite the local git config. It only adjusts the used URL.

FYI: I've already documented the corresponding hint inside the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants