Search code examples
githubyamlgithub-actionsbuilding-github-actionsgithub-token

Github actions token workflow not set error


Hello everyone I am currently writing a workflow to auto merge when a pull request is made but I am stuck at an error telling me my token is not set more specifically: 2023-02-19T02:09:08.581Z ERROR environment variable GITHUB_TOKEN not set!. I have set all my tokens in my repo and settings tab. Any help would be appreciated.

name: CI/CD 

on: 
  pull_request: 
    branches: [ master ]  
    
jobs: 
  super-linter:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Super-Linter
        uses: github/[email protected]
        with:    
          files: ${{ join(github.event.pull_request.changed_files, ',') }}
          
  Merge:       
    runs-on: ubuntu-latest       
    needs: super-linter
    steps:   
      - name: Checkout Code 
        uses: actions/checkout@v2 
      - name: Merge pull requests 
        uses: pascalgn/[email protected]   
        with: 
          GITHUB_TOKEN: ${{ secrets.TOKEN }}
      
        
  deploy: 
    runs-on: self-hosted   
    needs: Merge
    steps: 
      #- uses: actions/checkout@v2  #this is used for if you want to push all source code into runner       
      - name: update code base 
        working-directory: /test_pipe/www/html 
        run: sudo git pull origin master        
      - name: restart   
        working-directory: /test_pipe/www/html
        run: sudo systemctl restart nginx  

image of error


Solution

  • pascalgn/automerge-action accepts GITHUB_TOKEN as an env variable, not as an argument. So it should be:

      - name: Merge pull requests 
        uses: pascalgn/[email protected]   
        env: 
          GITHUB_TOKEN: ${{ secrets.TOKEN }}
    

    Refer to the documentation: https://github.com/pascalgn/automerge-action#usage