ekolis
ekolis

Reputation: 6796

GitHub Actions tells me the token is unspecified when I try to create a release, even though I did specify it

I have this action:

name: .NET

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.x
    - name: Install dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore
    #- name: github-action-publish-binaries
    #  uses: skx/[email protected]
    #- name: Test
    #  run: dotnet test --no-restore --verbosity normal
    - name: Create Artifact
      shell: bash
      run: |
        mkdir Artifact
        mkdir Artifact/FrEee.WinForms
        mkdir Artifact/FrEee.WinForms/FrEee
        mv FrEee.WinForms/bin/Release/net5.0-windows/* Artifact/FrEee.WinForms/FrEee/
    - name: Upload Artifact
      uses: actions/upload-artifact@v2
      with:
        name: FrEee.WinForms
        path: Artifact/FrEee.WinForms
    - name: Create Release
      uses: actions/create-release@v1
      with:
        tag_name: ${{github.ref}}
        release_name: ${{github.ref}}
        body: Auto-generated prerelease build
        prerelease: true
        token: ${{secrets.GITHUB_TOKEN}}  
    - name: Upload a Release Asset
      uses: actions/[email protected]
      with:
          upload_url: ${{steps.create_release.outputs.upload_url}} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps 
          asset_path: ./FrEee.WinForms.zip
          asset_name: FrEee.WinForms.zip
          asset_content_type: application/zip
          token: ${{secrets.GITHUB_TOKEN}}

I'm setting the token to the value from secrets which should automatically be populated, if I understand correctly. However I get this error on the create-release step:

Error: Parameter token or opts.auth is required

Why is the token not being set?

I also tried with GITHUB_TOKEN in place of token; that gave me the same error.

Upvotes: 4

Views: 4625

Answers (1)

Benjamin W.
Benjamin W.

Reputation: 52162

According to the README for the upload-release-asset action, the token has to be set in the environment:

      - name: Upload Release Asset
        id: upload-release-asset 
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }}
          asset_path: ./my-artifact.zip
          asset_name: my-artifact.zip
          asset_content_type: application/zip

Upvotes: 2

Related Questions