Repository navigation
135 lines (115 loc) · 3.88 KB
/
Copy pathrelease.yml
File metadata and controls
135 lines (115 loc) · 3.88 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
name: Release
on:
workflow_dispatch:
inputs:
tags:
required: true
type: string
description: Example - v1.0.0
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
permissions:
contents: read
jobs:
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: 10.0.x
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore -p:SkipFormatVerification=true
- name: Test
run: dotnet run --project MarkupString.Tests --configuration Release --no-build
build:
name: Pack
runs-on: ubuntu-latest
timeout-minutes: 15
needs: test
permissions:
contents: read
id-token: write
attestations: write
steps:
# MinVer reads the version from the tag on this commit, so the tags and the commits
# between them have to be present — a shallow clone would build 0.0.0-preview.0.x.
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v6
with:
dotnet-version: 10.0.x
- name: Restore
run: dotnet restore
# A tag on a commit that never reached main would otherwise ship as a release.
- name: Verify commit exists in origin/main
run: |
git fetch --no-tags --prune --depth=100 origin +refs/heads/*:refs/remotes/origin/*
git branch --remote --contains | grep origin/main
# Only to confirm the tag and the built version agree; the version itself comes from MinVer.
- name: Set VERSION variable
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ inputs.tags }}"
else
TAG="${GITHUB_REF#refs/tags/}"
fi
echo "VERSION=${TAG#v}" >> $GITHUB_ENV
- name: Pack
run: dotnet pack --configuration Release -p:SkipFormatVerification=true -o packages
env:
CI: true
- name: Verify the packed version matches the tag
run: |
if ! ls packages/MarkupString.${VERSION}.nupkg >/dev/null 2>&1; then
echo "::error::Expected packages/MarkupString.${VERSION}.nupkg; MinVer produced:"
ls packages
exit 1
fi
- name: Attest build provenance
uses: actions/attest-build-provenance@v4
with:
subject-path: "packages/*.nupkg"
- name: Upload NuGet packages
uses: actions/upload-artifact@v7
with:
name: nuget-packages
path: packages
release:
name: Publish
runs-on: ubuntu-latest
timeout-minutes: 15
needs: build
permissions:
contents: read
id-token: write
packages: write
steps:
- name: Download NuGet packages
uses: actions/download-artifact@v8
with:
name: nuget-packages
path: packages
- uses: actions/setup-dotnet@v6
with:
dotnet-version: 10.0.x
- name: Push to GitHub Packages
run: dotnet nuget push "packages/*.nupkg" --skip-duplicate --source https://nuget.pkg.github.com/SharpMUSH/index.json --api-key ${GITHUB_TOKEN}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Trusted publishing: the OIDC token minted by `id-token: write` is exchanged for a
# short-lived NuGet key. No long-lived secret exists to leak or rotate. It requires a
# trusted-publishing policy on nuget.org for this repository — see docs/releasing.md.
- name: NuGet Login
uses: NuGet/login@v1
id: login
with:
user: harrycordewener
- name: Push to NuGet
run: dotnet nuget push "packages/*.nupkg" --skip-duplicate --source https://api.nuget.org/v3/index.json -k ${{ steps.login.outputs.NUGET_API_KEY }}