Józef Podlecki
Józef Podlecki

Reputation: 11283

GitHub Actions: every step must define a `uses` or `run` key

I would like to set up github action which

I managed to get the second and third step is working but it's now a problem to combine following first step.

 - name: Cache Nuget
    - uses: actions/cache@v1
      with:
        path: ~/.nuget/packages
        key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
        restore-keys: |
          ${{ runner.os }}-nuget-

I tried to put that after - uses: actions/checkout@v2 but It throws following error.

every step must define a `uses` or `run` key
   ...
   steps:
    - uses: actions/checkout@v2
    - name: Cache Nuget
    - uses: actions/cache@v1
      with:
        path: ~/.nuget/packages
        key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
        restore-keys: |
          ${{ runner.os }}-nuget-
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
    ...

What am I doing wrong?

Thanks for help.

Here's the full config.

name: Build and Tests

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Cache Nuget
    - uses: actions/cache@v1
      with:
        path: ~/.nuget/packages
        key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
        restore-keys: |
          ${{ runner.os }}-nuget-
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.x
    - name: Restore dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore
    - name: Run Tests
      run: dotnet test --configuration Release --no-build --verbosity minimal /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov
    - name: Publish coverage report to coveralls.io   
      uses: coverallsapp/github-action@master   
      with:
       github-token: ${{ secrets.GITHUB_TOKEN }} 
       path-to-lcov: Tests/App.Tests/TestResults/coverage.info 

Upvotes: 4

Views: 6219

Answers (1)

rethab
rethab

Reputation: 8413

Your formatting is off. Use the dash only on the first line, like so:

- uses: actions/checkout@v2
- name: Cache Nuget
  uses: actions/cache@v1

If you also prefix the last line with a dash (-), then GitHub thinks the name is a separate step and it doesn't know what to do with it. Not using a dash, however, means the uses belongs to the same step as name.

Upvotes: 15

Related Questions