Repository navigation
89 lines (75 loc) · 3 KB
/
Copy pathrelease.yml
File metadata and controls
89 lines (75 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Release
# Publishing is driven by a tag, so the version that ships is the version that was tagged.
# v0.10.0 publishes 0.10.0. workflow_dispatch is there for a re-run without moving the tag.
#
# This package depends on BlockSoftware.QueryKit, so that version must already be live on
# nuget.org before this runs — the restore below has no local feed to fall back on.
on:
push:
tags: [ "v*" ]
workflow_dispatch:
inputs:
version:
description: "Package version to publish (e.g. 0.10.0)"
required: true
jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write # required for the OIDC token nuget.org exchanges for a short-lived key
contents: write # required to create the GitHub release
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
10.0.x
- name: Resolve version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "value=${{ inputs.version }}" >> "$GITHUB_OUTPUT"
else
echo "value=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
fi
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release -p:Version=${{ steps.version.outputs.value }}
- name: Test
run: dotnet test --no-build --configuration Release --verbosity normal
- name: Pack
run: dotnet pack QueryKit.Repositories/QueryKit.Repositories.csproj --no-build --configuration Release -p:Version=${{ steps.version.outputs.value }} -o artifacts
# The temporary key is valid for an hour, so it is requested immediately before the push.
- name: NuGet login (OIDC to short-lived API key)
id: login
uses: NuGet/login@v1
with:
user: ${{ secrets.NUGET_USER }}
- name: Push
run: >
dotnet nuget push artifacts/*.nupkg
--api-key ${{ steps.login.outputs.NUGET_API_KEY }}
--source https://api.nuget.org/v3/index.json
--skip-duplicate
# Kept in the workflow run regardless of how it was triggered, so a dispatch re-run
# still leaves the exact bytes that were built behind.
- name: Upload artifacts to the run
uses: actions/upload-artifact@v4
with:
name: packages
path: artifacts/*
# After the push, not before: a release that points at a version nuget.org rejected
# would be a link to nothing. gh is pre-installed on the runner, so this adds no
# third-party action to a workflow that holds a publishing credential.
- name: Create the GitHub release
if: github.event_name == 'push'
env:
GH_TOKEN: ${{ github.token }}
run: >
gh release create "${{ github.ref_name }}"
artifacts/*.nupkg artifacts/*.snupkg
--title "${{ github.ref_name }}"
--generate-notes