Skip to content

Commit

Permalink
Add the way to build & publish the package.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-khmara committed Aug 1, 2022
1 parent 5dce39f commit fafb840
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# directories
**/bin/
**/obj/
**/out/

# files
Dockerfile*
**/*.md

!README.md
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: docker build --target build .
- name: Test
run: docker build --target test .
19 changes: 19 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
release:
types: [released]
jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set VERSION variable from tag
run: echo "VERSION=${GITHUB_REF/refs\/tags\/}" >> $GITHUB_ENV
- name: Build
run: docker build --target build .
- name: Test
run: docker build --target test .
- name: Pack & Publish
run: docker build --target pack-and-push --build-arg PackageVersion=${VERSION} --build-arg NuGetApiKey=${{secrets.NUGET_API_KEY}} .

25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY src/StrEnum.Dapper/StrEnum.Dapper.csproj ./src/StrEnum.Dapper/StrEnum.Dapper.csproj
COPY test/StrEnum.Dapper.UnitTests/StrEnum.Dapper.UnitTests.csproj ./test/StrEnum.Dapper.UnitTests/StrEnum.Dapper.UnitTests.csproj
RUN dotnet restore

# copy everything else and build app
COPY ./ ./
WORKDIR /source
RUN dotnet build -c release -o /out/package --no-restore /p:maxcpucount=1

FROM build as test
RUN dotnet test /p:maxcpucount=1

FROM build as pack-and-push
WORKDIR /source

ARG PackageVersion
ARG NuGetApiKey

RUN dotnet pack ./src/StrEnum.Dapper/StrEnum.Dapper.csproj -o /out/package -c Release
RUN dotnet nuget push /out/package/StrEnum.Dapper.$PackageVersion.nupkg -k $NuGetApiKey -s https://api.nuget.org/v3/index.json
20 changes: 19 additions & 1 deletion src/StrEnum.Dapper/StrEnum.Dapper.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageId>StrEnum.Dapper</PackageId>
Expand All @@ -20,4 +20,22 @@
<PackageReference Include="Dapper" Version="[2.0.4,3.0.0)" />
</ItemGroup>

<Target Name="SetNuspecProperties" BeforeTargets="GenerateNuspec">
<PropertyGroup>
<NuspecProperties>$(NuspecProperties);config=$(Configuration)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);version=$(PackageVersion)</NuspecProperties>
</PropertyGroup>
<Message Importance="high" Text="NuspecProperties: $(NuspecProperties)" />
</Target>


<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath=""/>
<None Include="..\..\icon.png" Pack="true" PackagePath="" />

<PackageReference Include="MinVer" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

0 comments on commit fafb840

Please sign in to comment.