Build / Publish .NET WebAPI Project #130
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: webapi | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
paths: | |
- "src/api/**" | |
- "src/Directory.Packages.props" | |
pull_request: | |
branches: | |
- main | |
paths: | |
- "src/api/**" | |
- "src/Directory.Packages.props" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: setup dotnet | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 9.x | |
- name: restore dependencies | |
run: dotnet restore ./src/api/server/Server.csproj | |
- name: build | |
run: dotnet build ./src/api/server/Server.csproj --no-restore | |
- name: test | |
run: dotnet test ./src/api/server/Server.csproj --no-build --verbosity normal | |
publish: | |
needs: build | |
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: setup dotnet | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 9.x | |
- name: docker login | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: publish to github container registry | |
working-directory: ./src/api/server/ | |
run: | | |
dotnet publish -c Release -p:ContainerRepository=ghcr.io/${{ github.repository_owner}}/webapi -p:RuntimeIdentifier=linux-x64 | |
docker push ghcr.io/${{ github.repository_owner}}/webapi --all-tags |