3

Tip: How to CI/CD .NET Open Source library with GitHub Actions

 2 years ago
source link: https://medium.com/weknow-network/tip-how-to-ci-cd-net-open-source-library-with-github-actions-4dcf59927654
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Tip: How to CI/CD .NET Open Source library with GitHub Actions

If you write open source of .NET library, you can benefit from this post.

This post will use GitHub Actions workflow to CI/CD your open sourc.

It will cover:

It assumes you’re handling the project variations at the solution level using ‘Directory.Build.props’.

Setting this workflow is supper easy.
Follow these steps to complete it.

1*Usc2dNFHRTw4IFIqtYgJ4Q.png?q=20
tip-how-to-ci-cd-net-open-source-library-with-github-actions-4dcf59927654
  • Navigate to your GitHub repo.
  • Add a secret named [NUGET_PUBLISH] for the nuget.org access key (you’d created).
  • Select the ‘Actions’ tab
  • Click ‘Set up this workflow’
  • Replace the yaml content with the following yaml:
    within the yaml, replace the following parts:
    - BUILD_CONFIG: 6.0.x
    - INCLUDE_PRERELEASE: true
    - Check that the test pattern [**/*Tests] match your file structure.
name: Deploy

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: false
default: 'warning'env: # https://docs.github.com/en/actions/learn-github-actions/environment-variables
BUILD_CONFIG: Release
DOTNET_VER: 6.0.x
INCLUDE_PRERELEASE: true

jobs:
build:name: build
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v2

- name: Increment Version
run: |
perl -pi -e 's/([0-9]+)\.([0-9]+)\.([0-9]+)/"$1.$2.${\( $3+1 )}"/eg' Directory.Build.props
- name: Commit changes
uses: EndBug/add-and-commit@v7
with:
author_name: CI/CD
author_email: [email protected]
message: 'Increment Version'
add: 'Directory.Build.props'

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VER }}
include-prerelease: ${{ env.INCLUDE_PRERELEASE }}

- name: Restore dependencies
run: dotnet restore /property:Configuration=${{ env.BUILD_CONFIG }}
- name: Build
run: dotnet build --configuration ${{ env.BUILD_CONFIG }} --no-restore -o out
- name: Test
run: dotnet test **/*Tests --configuration ${{ env.BUILD_CONFIG }} --no-restore --no-build --verbosity normal -o out- name: Push generated package to GitHub registry
run: dotnet nuget push ./**/out/*.nupkg -k ${{ secrets.NUGET_PUBLISH }} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols true

That’s all.

I hope it was useful.

You can take a look at Event Source Backbone repo to see how to use it with nuget.org.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK