-
Notifications
You must be signed in to change notification settings - Fork 27
163 lines (148 loc) · 6.38 KB
/
Copy pathrelease.yml
File metadata and controls
163 lines (148 loc) · 6.38 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Release
# push to master (every dev->master merge) -> full release:
# a CalVer version (YYYY.(MM*100+DD).BUILD from today + existing tags), pushed
# to nuget.org via Trusted Publishing (OIDC, no stored key) and mirrored to
# GitHub Packages, a GitHub Release (which creates the tag), and a Discord
# embed. Doc-/CI-only merges are skipped (paths-ignore); put "[skip release]"
# in the merge commit to opt any other merge out.
#
# workflow_dispatch -> prerelease by default:
# packs <version>-<label>.<run_number>, pushes it to nuget.org + GitHub
# Packages, and stops - no tag, no GitHub Release, no Discord. Consumers opt in
# with `dotnet add package ESI.NET --prerelease`; same feed, no repo switch.
# Set prerelease=false on the dispatch to cut a full release by hand instead.
on:
push:
branches: [master]
paths-ignore:
- 'docs/**'
- '**.md'
- '.github/**'
workflow_dispatch:
inputs:
prerelease:
description: 'Prerelease: publish <version>-<label>.<run#> to NuGet; no tag / release / announce'
type: boolean
default: true
prerelease_label:
description: 'Prerelease label (beta, rc, alpha, ...)'
type: string
default: beta
# One release at a time; never cancel a run that may have already published.
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: write
id-token: write # OIDC token for NuGet Trusted Publishing (no stored API key)
packages: write # GitHub Packages mirror
jobs:
release:
runs-on: ubuntu-latest
# push: skip when the merge commit opts out. dispatch: always run.
if: >-
github.event_name == 'workflow_dispatch' ||
!contains(github.event.head_commit.message, '[skip release]')
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0 # need all tags so the CalVer build segment is correct
- name: Setup .NET SDK
uses: actions/setup-dotnet@v6
with:
# Must stay at least as new as the library's highest TargetFramework
# (net10.0) - a newer SDK builds older TFMs fine, not the reverse.
dotnet-version: '10.0.x'
# A dispatch with prerelease=true (the default) appends -<label>.<run_number>
# to the CalVer base. run_number is monotonic, so betas order correctly
# under SemVer. Prereleases never create a tag, so compute-version.sh only
# ever sees real releases.
- name: Compute version
id: version
shell: bash
run: |
base=$(bash scripts/compute-version.sh)
if [ "${{ inputs.prerelease }}" = "true" ]; then
echo "value=${base}-${{ inputs.prerelease_label }}.${{ github.run_number }}" >> "$GITHUB_OUTPUT"
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "value=${base}" >> "$GITHUB_OUTPUT"
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
- name: Test
shell: bash
run: dotnet test ESI.NET.sln --configuration Release
- name: Pack
shell: bash
run: >-
dotnet pack ESI.NET/ESI.NET.csproj
--configuration Release
--output ./nupkgs
-p:Version=${{ steps.version.outputs.value }}
-p:ContinuousIntegrationBuild=true
- name: Upload package artifact
uses: actions/upload-artifact@v7
with:
name: nuget-package
path: ./nupkgs/*.nupkg
# Trusted Publishing: exchanges this job's GitHub OIDC token for a NuGet
# API key valid ~1 hour. Requires a trusted-publishing policy on nuget.org
# for seraphx2/ESI.NET -> release.yml. No secret is stored.
- name: NuGet login (OIDC)
id: nuget_login
uses: NuGet/login@v1
with:
user: robmburke
- name: Push to NuGet.org
shell: bash
run: >-
dotnet nuget push "nupkgs/*.nupkg"
--api-key ${{ steps.nuget_login.outputs.NUGET_API_KEY }}
--source https://api.nuget.org/v3/index.json
--skip-duplicate
# Mirror. Auth is the automatic GITHUB_TOKEN. Note: consuming from here
# needs a PAT with read:packages - it is a backup feed, not the public one.
# --no-symbols: GitHub Packages' NuGet registry has no symbol server: it
# only documents pushing .nupkg. dotnet nuget push auto-pushes a matching
# .snupkg alongside its .nupkg by default, which would otherwise fail here.
- name: Push to GitHub Packages
shell: bash
run: >-
dotnet nuget push "nupkgs/*.nupkg"
--api-key ${{ secrets.GITHUB_TOKEN }}
--source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
--skip-duplicate
--no-symbols
- name: Create GitHub Release
id: gh_release
if: ${{ steps.version.outputs.prerelease == 'false' }}
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.version.outputs.value }}
name: ESI.NET ${{ steps.version.outputs.value }}
generate_release_notes: true
files: ./nupkgs/*.nupkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Rich embed to the project Discord. Full releases only. Test webhook for a
# manual dispatch, the real one for a dev->master merge. jq builds the
# payload so nothing needs hand-escaping.
- name: Announce on Discord
if: ${{ success() && steps.version.outputs.prerelease == 'false' }}
shell: bash
env:
DISCORD_WEBHOOK: ${{ github.event_name == 'workflow_dispatch' && secrets.DISCORD_TEST_WEBHOOK_URL || secrets.DISCORD_WEBHOOK_URL }}
VERSION: ${{ steps.version.outputs.value }}
RELEASE_URL: ${{ steps.gh_release.outputs.url }}
run: |
jq -n --arg v "$VERSION" --arg url "$RELEASE_URL" '{
embeds: [{
title: ("ESI.NET " + $v + " Release"),
url: $url,
description: "The ESI.NET build completed successfully and the NuGet package has been published (indexing may take a few minutes). Click the title for the release changelog.",
color: 3066993,
author: { name: "Psianna Archeia" },
fields: [{ name: "NuGet", value: ("https://www.nuget.org/packages/ESI.NET/" + $v) }]
}]
}' | curl -sS -f -H "Content-Type: application/json" -d @- "$DISCORD_WEBHOOK"