Skip to content

Commit 5f2ae4c

Browse files
committed
Add a Dockerfile to build, test, and publish to NuGet. Add GitHub Actions workflows.
1 parent af36c22 commit 5f2ae4c

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# directories
2+
**/bin/
3+
**/obj/
4+
**/out/
5+
6+
# files
7+
Dockerfile*
8+
**/*.md
9+
10+
!README.md

.github/workflows/build.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
pull_request:
6+
branches:
7+
- master
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 15
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
- name: Build
16+
run: docker build --target build .
17+
- name: Test
18+
run: docker build --target test .

.github/workflows/publish.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
on:
2+
release:
3+
types: [released]
4+
jobs:
5+
publish:
6+
runs-on: ubuntu-latest
7+
timeout-minutes: 15
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v2
11+
- name: Set VERSION variable from tag
12+
run: echo "VERSION=${GITHUB_REF/refs\/tags\/}" >> $GITHUB_ENV
13+
- name: Build
14+
run: docker build --target build .
15+
- name: Test
16+
run: docker build --target test .
17+
- name: Pack & Publish
18+
run: docker build --target pack-and-push --build-arg PackageVersion=${VERSION} --build-arg NuGetApiKey=${{secrets.NUGET_API_KEY}} .
19+

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
2+
WORKDIR /source
3+
4+
# copy csproj and restore as distinct layers
5+
COPY *.sln .
6+
COPY src/StrEnum.EntityFrameworkCore/StrEnum.EntityFrameworkCore.csproj ./src/StrEnum.EntityFrameworkCore/StrEnum.EntityFrameworkCore.csproj
7+
COPY test/StrEnum.EntityFrameworkCore.UnitTests/StrEnum.EntityFrameworkCore.UnitTests.csproj ./test/StrEnum.EntityFrameworkCore.UnitTests/StrEnum.EntityFrameworkCore.UnitTests.csproj
8+
RUN dotnet restore
9+
10+
# copy everything else and build app
11+
COPY ./ ./
12+
WORKDIR /source
13+
RUN dotnet build -c release -o /out/package --no-restore
14+
15+
FROM build as test
16+
RUN dotnet test
17+
18+
FROM build as pack-and-push
19+
WORKDIR /source
20+
21+
ARG PackageVersion
22+
ARG NuGetApiKey
23+
24+
RUN dotnet pack ./src/StrEnum.EntityFrameworkCore/StrEnum.EntityFrameworkCore.csproj -o /out/package -c Release
25+
RUN dotnet nuget push /out/package/StrEnum.EntityFrameworkCore.$PackageVersion.nupkg -k $NuGetApiKey -s https://api.nuget.org/v3/index.json

0 commit comments

Comments
 (0)