Skip to content

Automate build, publish and releases #146

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

Merged
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
19 changes: 19 additions & 0 deletions .github/actions/dotnet/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: build
description: 'Restore and build the dotnet solution'

inputs:
dotnet-build-configuration:
default: Release
description: 'Defines the build configuration. The default for most projects is Release.'
required: true

runs:
using: "composite"
steps:
- name: Restore dependencies
shell: bash
run: dotnet restore

- name: Build solutions
shell: bash
run: dotnet build --no-restore --configuration ${{ inputs.dotnet-build-configuration }}
32 changes: 32 additions & 0 deletions .github/actions/dotnet/nuget/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: nuget
description: 'Publish NuGet packages'

inputs:
dotnet-version:
description: 'The dotnet framework and SDK version.'
default: 7.0.x
required: true
nuget-api-key:
description: 'The NuGet API key to publish artifacts'
default: 'nuget-api-key'
required: true
packages-directory:
description: 'The root directory of the NuGet packages that should be published'
server-url:
description: 'Specifies the NuGet server URL'
required: true
default: 'https://api.nuget.org/v3/index.json'

runs:
using: "composite"
steps:
- name: Setup dotnet environment
uses: actions/setup-dotnet@v3
id: setup
with:
dotnet-version: ${{ inputs.dotnet-version }}

- name: Publish to NuGet
working-directory: ${{ inputs.packages-directory }}
shell: bash
run: 'dotnet nuget push "*.nupkg" --skip-duplicate --api-key ${{ inputs.nuget-api-key }} --source ${{ inputs.server-url }}'
33 changes: 33 additions & 0 deletions .github/actions/dotnet/pack/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: pack
description: 'Packs and sign the code into a NuGet package'

inputs:
dotnet-build-configuration:
default: Release
description: 'Defines the build configuration. The default for most projects is Release.'
required: true
pre-release-version:
description: 'The semantic version to be used for pre-release artifacts'
required: true
release-version:
description: 'The semantic version to be used for release artifacts'
required: true

runs:
using: "composite"
steps:
- name: Pack pre-release version ${{steps.version.outputs.nuGetVersionV2}}
shell: bash
run: dotnet pack --configuration ${{ inputs.dotnet-build-configuration }} --verbosity normal --no-restore -p:PackageVersion=${{ inputs.pre-release-version }} --output ./packages/preview

- name: Pack release version ${{steps.version.outputs.majorMinorPatch}}
shell: bash
run: dotnet pack --configuration ${{ inputs.dotnet-build-configuration }} --verbosity normal --no-restore -p:PackageVersion=${{ inputs.release-version }} --output ./packages/release

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: packages
path: |
./packages/preview
./packages/release
36 changes: 36 additions & 0 deletions .github/actions/dotnet/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: test
description: 'Execute the unit tests and parse results report'

inputs:
dotnet-build-configuration:
default: Release
description: 'Defines the build configuration. The default for most projects is Release.'
required: true
results-directory:
description: 'The test results output directory'
default: './test-results'
github-token:
description: 'GitHub personal access token'
required: true

runs:
using: "composite"
steps:

- name: Execute unit tests
shell: bash
run: dotnet test --logger trx --results-directory ${{ inputs.results-directory }} --no-build --configuration ${{ inputs.dotnet-build-configuration }} --verbosity normal

- name: Parse the unit test files
uses: nasamin/[email protected]
with:
TRX_PATH: ${{ github.workspace }}/test-results
REPO_TOKEN: ${{ inputs.github-token }}

- name: Upload artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: unit-test-logs
path: |
./test-logs
51 changes: 51 additions & 0 deletions .github/actions/dotnet/version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: version
description: 'Use the git tools to calculate the semantic version and update the dotnet project files'
inputs:
dotnet-version:
description: 'The dotnet framework and SDK version.'
default: 7.0.x
required: true
git-tools-version:
description: 'The version specification to be used of the git tools '
default: 5.x
required: true
config-file-path:
description: 'Tha path of the git version configuration file'
default: GitVersion.yml
required: true

runs:
using: "composite"
steps:
- name: Setup dotnet environment
uses: actions/setup-dotnet@v3
id: setup
with:
dotnet-version: ${{ inputs.dotnet-version }}

- name: Setup the git version tools
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: ${{ inputs.git-tools-version }}

- name: Update the semantic version of the projects
uses: gittools/actions/gitversion/[email protected]
id: version
with:
useConfigFile: true
configFilePath: ${{ inputs.config-file-path }}
additionalArguments: '/updateprojectfiles'

outputs:
dotnet-version:
description: 'The dotnet framework and sdk version'
value: ${{ steps.setup.outputs.dotnet-version }}
pre-release-version:
description: 'The semantic version to be used for pre-release artifacts'
value: ${{steps.version.outputs.nuGetVersionV2}}
release-version:
description: 'The semantic version to be used for release artifacts'
value: ${{steps.version.outputs.majorMinorPatch}}



36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: build
on:
workflow_call:
inputs:
pack:
default: false
required: true
type: boolean

jobs:
build-and-sign:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Semantic version
uses: './.github/actions/dotnet/version'
id: version

- name: Restore and build
uses: './.github/actions/dotnet/build'

- name: Execute unit test and publish reports
uses: './.github/actions/dotnet/test'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Pack and sign NuGet packages
uses: './.github/actions/dotnet/pack'
if: ${{ inputs.pack }}
with:
pre-release-version: ${{steps.version.outputs.pre-release-version}}
release-version: ${{steps.version.outputs.release-version}}
68 changes: 68 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: continuous-delivery
run-name: Publish pipeline after ${{github.event_name}} by @${{ github.actor }}

on:
push:
branches:
- release/**

jobs:
continuous-integration:
uses: ./.github/workflows/build.yml
with:
pack: true
secrets: inherit

publish-preview-packages:
uses: ./.github/workflows/publish.yml
needs: [ continuous-integration ]
with:
environment: preview
secrets: inherit

publish-release-packages:
uses: ./.github/workflows/publish.yml
needs: [ publish-preview-packages ]
with:
environment: release
secrets: inherit

tag-and-release:
runs-on: ubuntu-latest
needs: [ publish-release-packages ]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Semantic version
uses: './.github/actions/dotnet/version'
id: version

- name: Create tag
uses: rickstaa/action-create-tag@v1
id: tag
with:
tag: 'v${{steps.version.outputs.release-version}}'
tag_exists_error: true
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Create pull request
uses: devops-infra/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
target_branch: master
title: Release v${{steps.version.outputs.release-version}}
draft: false
get_diff: true
ignore_users: "dependabot"
allow_no_diff: true

- name: Create the release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
generateReleaseNotes: true
name: 'v${{steps.version.outputs.release-version}}'
tag: 'v${{steps.version.outputs.release-version}}'
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: continuous-integration
run-name: Build pipeline after ${{github.event_name}} by @${{ github.actor }}

on:
workflow_dispatch:

push:
branches:
- master
- feature/**
- bugfix/**

pull_request:
branches:
- feature/**
- bugfix/**

jobs:
continuous-integration:
uses: ./.github/workflows/build.yml
with:
pack: false
secrets: inherit
27 changes: 0 additions & 27 deletions .github/workflows/dotnet-core.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: publish
on:
workflow_call:
inputs:
environment:
type: string
required: true

jobs:
publish:
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download artifacts
uses: actions/download-artifact@v3
id: download
with:
name: 'packages'
path: './packages'

- name: Publish packages
uses: './.github/actions/dotnet/nuget'
with:
nuget-api-key: ${{ secrets.NUGET_API_KEY }}
packages-directory: '${{steps.download.outputs.download-path}}/${{ inputs.environment }}'
11 changes: 11 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mode: ContinuousDeployment
branches:
master:
prevent-increment-of-merged-branch-version: false
source-branches: ['feature']
tag: master
feature:
tag: 'feature.{BranchName}'
source-branches: ['master']
release:
tag: 'release'