Skip to content

Commit 9dfc809

Browse files
committed
Update CI workflow to support releasing packages
[ci skip]
1 parent e0b6a2c commit 9dfc809

File tree

3 files changed

+93
-28
lines changed

3 files changed

+93
-28
lines changed

.github/workflows/ci.yml

Lines changed: 91 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,107 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
inputs:
8+
is_stable_build:
9+
description: Use a version number indicating this is a stable release
10+
required: true
11+
default: "false"
12+
release:
13+
description: Create a release
14+
required: true
15+
default: "false"
16+
branches:
17+
- main
18+
- release/*
419

520
env:
21+
IS_STABLE_BUILD: ${{ github.event.inputs.is_stable_build }}
622
BUILD_NUMBER: ${{ github.run_number }}
723

824
jobs:
925
build:
10-
if: "!contains(github.event.head_commit.message, 'ci skip')"
26+
if: "!contains(github.event.head_commit.message, 'ci skip') || github.event_name == 'workflow_dispatch'"
1127
strategy:
1228
fail-fast: false
1329
matrix:
1430
os: [windows-latest, ubuntu-latest, macos-latest]
1531

1632
runs-on: ${{ matrix.os }}
1733

34+
outputs:
35+
package_version: ${{ steps.build_script.outputs.package_version }}
36+
37+
steps:
38+
- uses: actions/checkout@v2
39+
- name: Setup .NET Core 2.1
40+
uses: actions/setup-dotnet@v1
41+
with:
42+
dotnet-version: "2.1.x"
43+
- name: Setup .NET Core 3.1
44+
uses: actions/setup-dotnet@v1
45+
with:
46+
dotnet-version: "3.1.x"
47+
- name: Setup .NET 5
48+
uses: actions/setup-dotnet@v1
49+
with:
50+
dotnet-version: "5.0.x"
51+
- name: Run build script
52+
id: build_script
53+
run: ./build.ps1 -ci
54+
- uses: actions/upload-artifact@v2
55+
if: ${{ matrix.os == 'windows-latest' }}
56+
with:
57+
name: packages
58+
path: artifacts/
59+
if-no-files-found: error
60+
- uses: codecov/codecov-action@v1
61+
with:
62+
name: unittests-${{ matrix.os }}
63+
fail_ci_if_error: true
64+
release:
65+
if: "github.event.inputs.release"
66+
needs: build
67+
runs-on: windows-latest
68+
env:
69+
PACKAGE_VERSION: ${{ needs.build.outputs.package_version }}
1870
steps:
19-
- uses: actions/checkout@v2
20-
- name: Setup .NET Core 2.1
21-
uses: actions/setup-dotnet@v1
22-
with:
23-
dotnet-version: '2.1.x'
24-
- name: Setup .NET Core 3.1
25-
uses: actions/setup-dotnet@v1
26-
with:
27-
dotnet-version: '3.1.x'
28-
- name: Setup .NET 5
29-
uses: actions/setup-dotnet@v1
30-
with:
31-
dotnet-version: '5.0.x'
32-
- name: Run build script
33-
run: ./build.ps1 -ci
34-
- uses: actions/upload-artifact@v2
35-
if: ${{ matrix.os == 'windows-latest' }}
36-
with:
37-
name: packages
38-
path: artifacts/
39-
- uses: codecov/codecov-action@v1
40-
with:
41-
name: unittests-${{ matrix.os }}
42-
fail_ci_if_error: true
71+
- run: echo "Releasing ${{ env.PACKAGE_VERSION }}"
72+
- name: Setup NuGet
73+
uses: NuGet/setup-nuget@v1
74+
with:
75+
nuget-version: latest
76+
- uses: actions/download-artifact@v2
77+
with:
78+
name: packages
79+
path: packages
80+
- name: Configure GitHub NuGet registry
81+
run: nuget sources add -name github -source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json -username ${{ github.repository_owner }} -password ${{ secrets.GITHUB_TOKEN }}
82+
- name: Push to GitHub package registry
83+
run: nuget push packages\*.nupkg -ApiKey ${{ secrets.GITHUB_TOKEN }} -Source github
84+
- name: Push to NuGet.org
85+
run: nuget push packages\*.nupkg -ApiKey ${{ secrets.NUGET_API_KEY }} -Source https://nuget.org
86+
- name: Create GitHub release
87+
uses: softprops/action-gh-release@v1
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
with:
91+
name: ${{ env.PACKAGE_VERSION }}
92+
tag_name: v${{ env.PACKAGE_VERSION }}
93+
body: |
94+
See changes in https://github.com/natemcmaster/CommandLineUtils/blob/main/CHANGELOG.md
95+
96+
Packages have been posted to these feeds:
97+
98+
#### NuGet.org
99+
https://nuget.org/packages/McMaster.Extensions.CommandLineUtils/${{ env.PACKAGE_VERSION }}
100+
https://nuget.org/packages/McMaster.Extensions.Hosting.CommandLine/${{ env.PACKAGE_VERSION }}
101+
102+
#### GitHub Package Registry
103+
https://github.com/natemcmaster?tab=packages&repo_name=CommandLineUtils
104+
105+
draft: true
106+
prerelease: ${{ env.IS_STABLE_BUILD == 'false' }} # Example: v3.1.0-beta
107+
files: packages/*

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<PropertyGroup>
4646
<VersionPrefix>4.0.0</VersionPrefix>
4747
<VersionSuffix>beta</VersionSuffix>
48-
<IncludePreReleaseLabelInPackageVersion Condition="'$(IsStableBuild)' != 'true'">true</IncludePreReleaseLabelInPackageVersion>
48+
<IncludePreReleaseLabelInPackageVersion Condition="'$(IS_STABLE_BUILD)' != 'true'">true</IncludePreReleaseLabelInPackageVersion>
4949
<BuildNumber Condition=" '$(BuildNumber)' == '' ">$(BUILD_NUMBER)</BuildNumber>
5050
<BuildNumber Condition=" '$(BuildNumber)' == '' ">0</BuildNumber>
5151
<VersionSuffix Condition=" '$(VersionSuffix)' != '' ">$(VersionSuffix).$(BuildNumber)</VersionSuffix>

src/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<Target Name="UpdateCiSettings" Condition="'$(CI)' == 'true' AND '$(IsPackable)' == 'true'">
14-
<Message Importance="High" Text="##vso[build.updatebuildnumber]$(PackageVersion)" />
14+
<Message Importance="High" Text="::set-output name=package_version::$(PackageVersion)" />
1515
</Target>
1616

1717
</Project>

0 commit comments

Comments
 (0)