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

MY_GITHUB_TOKEN not defined #80

Open
TheFlyer1983 opened this issue Sep 2, 2021 · 14 comments
Open

MY_GITHUB_TOKEN not defined #80

TheFlyer1983 opened this issue Sep 2, 2021 · 14 comments
Labels
help wanted Extra attention is needed

Comments

@TheFlyer1983
Copy link

TheFlyer1983 commented Sep 2, 2021

Hi,

I am trying to create an issue in a personal repo, but the add it to a user project board (https://github.com/users/TheFlyer1983/projects/5) for example. I keep getting an error in my action saying:
MY_GITHUB_TOKEN not defined.

I have created a PAT named MY_GITHUB_TOKEN but whenever I run it I get the error, and my job fails.

My workflow is detailed below.

name: Add Issues
on: 
  issues:
    types:
      - opened
env:
  MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
  
jobs:
  add_issues:
    runs-on: ubuntu-latest
    steps:
      - name: Assign to One Project
        uses: srggrs/assign-one-project-github-action@1.2.1
        if: github.event.action == 'opened'
        with:
          project: https://github.com/users/TheFlyer1983/projects/1
          column_name: 'Backlog'

I was wondering if you could help resolve my issue?

@zkoppert
Copy link

zkoppert commented Oct 1, 2021

@TheFlyer1983 Is that PAT called MY_GITHUB_TOKEN added to your repository as a repository secret?
Check out this doc on how to do that. Make sure you name the secret MY_GITHUB_TOKEN and then put your PAT in as the secret value.

I should also add that you shouldn't need to create a PAT and add the secret if you are operating the automation in the same repo as the issues and project board. just use the built in secret as shown here.

Hope that helps!

@ayakalauova
Copy link

@zkoppert the PAT was called MY_GITHUB_TOKEN and added to a repository as a repository secret (with all the possible permissions and added as a repo secret to all the needed repositories) but still doesn't work. Cannot figure out why. Is the action working?

@TheFlyer1983 any success? were you able to set it up?

@TheFlyer1983
Copy link
Author

@zkoppert Thank you for your help.

I've just tried this on a test Repo and it's working. Just one further question. I have Beta access to the new projects. I'm assuming there is no real difference between adding cards to the projects, so this action should still work as expected?

@ayakalauova Yes I have managed to get this working properly on my test repo. I will now be looking at moving it over to the actual repo I need it for.

I started by creating a PAT with every permission, and then took that PAT and added into a repo secret in my repo where the issue is as MY_GITHUB_TOKEN, then used the following code in my action to access this:

Screenshot 2021-10-14 at 15 17 04

Created an issue and the action was successful. I then went through the PAT and removed all permission that weren't needed, and created a new issue and the action was successful.

After testing I found that the only permissions that I needed were:

Screenshot 2021-10-14 at 15 20 14

I hope this works for you.

@ayakalauova
Copy link

@zkoppert @TheFlyer1983 Thank you so much! It really helps. But one thing that I noticed is that after my job fails it gives me "GITHUB_TOKEN not defined" error instead of "MY_GITHUB_TOKEN not defined". Any clue what might be the reason? (I'm attempting cross private repository option inside an organization)

@zkoppert
Copy link

@ayakalauova The GITHUB_TOKEN is an automatically generated secret that lets you make authenticated calls to the GitHub API in your workflow runs. Actions generates a new token for each job and expires the token when a job completes.
Check out https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/ for details.

In order to get permissions for other repos you need to create a new token named something else. Here is the way to do that. https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-token

@ayakalauova
Copy link

@zkoppert that's something I already did (I followed all the instructions above) and that is the reason I'm a bit confused

@zkoppert
Copy link

Did you name your token GITHUB_TOKEN ?

@ayakalauova
Copy link

@zkoppert nope, it's MY_GITHUB_TOKEN (in the action itself and in the secret)

@zkoppert
Copy link

Can you post what your workflow file looks like?

@ayakalauova
Copy link

name: Auto Assign to Project(s)

on:
  issues:
    types: [created, labeled]
env:
  MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}

jobs:
  assign_one_project:
    runs-on: ubuntu-latest
    name: Assign to One Project
    steps:
    - name: Assign issues from Business to Bi Team Board
      uses: srggrs/assign-one-project-github-action@1.2.1
      if: |
        contains(github.event.issue.labels.*.name, 'bi-issue')
      with:
        project: 'https://github.com/Test12345667t743895739/bi/projects/1'
        column_name: 'To Do'

@zkoppert
Copy link

Hmm that doesn't make much sense to me. I'm not sure what is happening.

@arist0v
Copy link

arist0v commented May 25, 2022

name: Auto Assign to Project(s)

on:
  issues:
    types: [created, labeled]
env:
  MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}

jobs:
  assign_one_project:
    runs-on: ubuntu-latest
    name: Assign to One Project
    steps:
    - name: Assign issues from Business to Bi Team Board
      uses: srggrs/assign-one-project-github-action@1.2.1
      if: |
        contains(github.event.issue.labels.*.name, 'bi-issue')
      with:
        project: 'https://github.com/Test12345667t743895739/bi/projects/1'
        column_name: 'To Do'

env:
MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

if you try like this?

@whitneymeredith
Copy link

I'm also receiving this error. Has anyone found a solution?

@arist0v
Copy link

arist0v commented Feb 28, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants