Skip to content

Merge pull request #30 from Kushal425/main #47

Merge pull request #30 from Kushal425/main

Merge pull request #30 from Kushal425/main #47

Workflow file for this run

# .github/workflows/dotnet.yml
name: .NET Build, Smoke Test & Docker Publish
on:
push:
branches: [ "main" ]
tags: [ "v*.*.*", "*.*.*" ] # push on semver tags too (v1.2.3 or 1.2.3)
pull_request:
jobs:
build:
name: .NET Build & Run Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Cache NuGet
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore
- name: Build (Release)
run: dotnet build --configuration Release --no-restore
- name: Run (Smoke Test)
run: |
dotnet run --no-build &
APP_PID=$!
sleep 10
kill $APP_PID || true
docker:
name: Docker Build & Push
needs: build
runs-on: ubuntu-latest
# Only publish images on pushes to main or when a tag is pushed (not for pull_request).
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
steps:
- uses: actions/checkout@v4
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract Docker metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_USERNAME }}/aspgoat
tags: |
type=ref,event=branch # e.g. main => :main
type=ref,event=tag # e.g. v1.2.3 => :v1.2.3
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push (no cache)
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64 # add arm64 if you need multi-arch
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
no-cache: true # always build fresh