Skip to content

Commit 4057da0

Browse files
committed
Publish packages to GitHub and NuGet.
1 parent c0895df commit 4057da0

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

.github/workflows/build.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ on:
55
CODECOV_TOKEN:
66
description: Token for uploading code coverage metrics to CodeCov.io.
77
required: true
8+
NUGET_API_KEY:
9+
description: Token for publishing packages to NuGet.
10+
required: true
811
jobs:
912
build:
1013
runs-on: ubuntu-latest
1114
steps:
12-
- uses: actions/checkout@v4
15+
- name: Checkout
16+
uses: actions/checkout@v4
1317
- name: Setup .NET 6
1418
uses: actions/setup-dotnet@v4
1519
with:
@@ -24,9 +28,22 @@ jobs:
2428
dotnet-version: 8.0.x
2529
- name: Build and test
2630
run: dotnet msbuild ./default.proj
27-
- uses: codecov/codecov-action@v5
31+
- name: Upload coverage
32+
uses: codecov/codecov-action@v5
2833
with:
2934
fail_ci_if_error: true
3035
files: artifacts/logs/*/coverage.cobertura.xml
3136
token: ${{ secrets.CODECOV_TOKEN }}
32-
# TODO: Upload to GitHub packages instead of MyGet in GitHub actions for master and develop.
37+
- name: Publish to GitHub Packages
38+
if: ${{ github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/v') }}
39+
run: |
40+
dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/autofac/index.json"
41+
dotnet nuget push ./artifacts/packages/*.nupkg --source github --api-key ${{ secrets.GITHUB_TOKEN }}
42+
- name: Publish to NuGet
43+
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
44+
run: |
45+
# Ensure the tag is on the master branch.
46+
git branch --remote --contains | grep origin/master
47+
48+
# Push to NuGet.
49+
dotnet nuget push ./artifacts/packages/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ on:
55
- develop
66
- master
77
push:
8+
branches:
9+
- develop
10+
- master
11+
- feature/*
12+
tags:
13+
- v[0-9]+.[0-9]+.[0-9]+
814
# If multiple pushes happen quickly in succession, cancel the running build and
915
# start a new one.
1016
concurrency:
@@ -21,3 +27,4 @@ jobs:
2127
uses: ./.github/workflows/build.yml
2228
secrets:
2329
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
30+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}

0 commit comments

Comments
 (0)