Skip to content

Create basic CI/CD for interface package #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto
*.cs text
*.csproj text
103 changes: 103 additions & 0 deletions .github/workflows/Harp.Behavior.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Harp.Behavior
on:
push:
# This prevents tag pushes from triggering this workflow
branches: ['**']
pull_request:
release:
types: [published]
workflow_dispatch:
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
ContinuousIntegrationBuild: true
CiBuildVersion: ${{github.event.release.tag_name || 'api42.42.42'}}
jobs:
build:
strategy:
fail-fast: false
matrix:
configuration: ['Release']
include:
- configuration: Release
collect-packages: true
name: Build
runs-on: windows-latest
if: github.event_name != 'release' || startsWith(github.event.release.tag_name, 'api')
steps:
# ----------------------------------------------------------------------- Checkout
- name: Checkout
uses: actions/checkout@v4

# ----------------------------------------------------------------------- Set up tools
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Set up T4
run: dotnet tool install -g dotnet-t4 --version 3.0.0

# ----------------------------------------------------------------------- Regenerate
- name: Restore generators
run: dotnet restore Generators

- name: Run generators
run: dotnet build Generators --no-restore --configuration ${{matrix.configuration}}

- name: Verify pre-generated code was up-to-date
id: verify-dist
run: |
git add . --intent-to-add --ignore-removal
git diff --name-status --exit-code

# ----------------------------------------------------------------------- Build interface package
- name: Restore interface
run: dotnet restore Interface

- name: Build interface
run: dotnet build Interface --no-restore --configuration ${{matrix.configuration}}

- name: Pack interface
id: pack
run: dotnet pack Interface --no-restore --no-build --configuration ${{matrix.configuration}}

# ----------------------------------------------------------------------- Collect artifacts
- name: Collect NuGet packages
uses: actions/upload-artifact@v4
if: matrix.collect-packages && steps.pack.outcome == 'success' && always()
with:
name: Packages
if-no-files-found: error
path: Interface/bin/${{matrix.configuration}}/**

publish-packages-nuget-org:
name: Publish packages to NuGet.org
runs-on: ubuntu-latest
permissions:
# Needed to attach files to releases
contents: write
environment: public-release
needs: build
if: github.event_name == 'release'
steps:
# ----------------------------------------------------------------------- Set up .NET
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

# ----------------------------------------------------------------------- Download built packages
- name: Download built packages
uses: actions/download-artifact@v4
with:
name: Packages
path: artifacts/packages/

# ----------------------------------------------------------------------- Push to NuGet.org
- name: Push to NuGet.org
run: dotnet nuget push "artifacts/packages/*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source ${{vars.NUGET_API_URL}}
env:
# This is a workaround for https://github.com/NuGet/Home/issues/9775
DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER: 0
15 changes: 15 additions & 0 deletions Interface/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project>
<PropertyGroup>
<!-- Force malformed versions to be an error -->
<WarningsAsErrors>$(WarningsAsErrors);CS7035</WarningsAsErrors>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(ContinuousIntegrationBuild)' == 'true'">
<Version Condition="$(CiBuildVersion.StartsWith('api'))">$(CiBuildVersion.Substring(3))</Version>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>
<Target Name="VersionSanityChecks" BeforeTargets="build;restore">
<Error Condition="'$(ContinuousIntegrationBuild)' == 'true' and '$(CiBuildVersion)' == ''" Text="CI version info not configured." />
<Error Condition="'api$(Version)' != '$(CiBuildVersion)'" Text="CI version info was not applied correctly." />
</Target>
</Project>
Loading