Skip to content

Cache Example

Cache Example #6

Workflow file for this run

on:
workflow_dispatch:
name: Cache Example
jobs:
cache-build:
name: Build - With Cache
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Restore dependencies
run: |
dotnet restore dekoeky.hello-world.tests
- name: Build
run: |
dotnet build dekoeky.hello-world.tests --no-restore -c Release
- uses: actions/cache@v2
id: restore-build
with:
path: dekoeky.hello-world.tests/bin/Release/*
key: ${{ github.sha }}
cache-use-build:
name: Re-use Cache
runs-on: ubuntu-latest
needs: [cache-build]
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- uses: actions/cache@v2
id: restore-build
with:
path: dekoeky.hello-world.tests/bin/Release/*
key: ${{ github.sha }}
- run: tree
- run: |
dotnet test dekoeky.hello-world.tests/bin/Release/net6.0/dekoeky.hello-world.tests.dll --no-restore --no-build
dotnet test dekoeky.hello-world.tests/bin/Release/net7.0/dekoeky.hello-world.tests.dll --no-restore --no-build
dotnet test dekoeky.hello-world.tests/bin/Release/net8.0/dekoeky.hello-world.tests.dll --no-restore --no-build
artifact-build:
name: Build - With Artifact
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Restore dependencies
run: |
dotnet restore dekoeky.hello-world
- name: Build
run: |
dotnet build dekoeky.hello-world --no-restore -c Release
- name: Pack
run: |
dotnet pack dekoeky.hello-world --no-restore -c Release
- run: ls
- run: find . -type f \( -name *.nupkg -or -name *.snupkg \)
- uses: actions/upload-artifact@v2
with:
name: packages
path: |
dekoeky.hello-world/bin/**/*.nupkg
dekoeky.hello-world/bin/**/*.snupkg
upload-nuget-org:
name: Upload to NuGet.org
runs-on: ubuntu-latest
needs: [artifact-build]
steps:
- uses: actions/download-artifact@v2
with:
name: packages
- run: ls .
- run: tree .
- run: |
dotnet nuget push "*.nupkg" \
--skip-duplicate \
-s https://api.nuget.org/v3/index.json \
--api-key ${{ secrets.NUGET_API_KEY }}
upload-github:
name: Upload to GitHub
runs-on: ubuntu-latest
needs: [artifact-build]
steps:
- uses: actions/download-artifact@v2
with:
name: packages
- run: ls .
- run: tree .
- run: |
dotnet nuget push "*.nupkg" \
--skip-duplicate \
-s https://nuget.pkg.github.com/dekoeky/index.json \
--api-key ${{ secrets.GITHUB_TOKEN }}