Repository navigation
88 lines (83 loc) · 3.13 KB
/
Copy pathrelease.yml
File metadata and controls
88 lines (83 loc) · 3.13 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
# Written by DocSpring/docspring's api_clients/scripts/generate from api_clients/github_workflows/csharp/release.yml:
# change it there.
#
# Packs the package on every push and pull request. A v* tag (pushed by the monorepo's api_clients/scripts/release)
# also pushes it to NuGet with trusted publishing, in the release environment, and waits until NuGet serves it.
name: Release
on:
push:
branches: ['**']
tags: ['v*']
pull_request:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
dotnet-version: 9.0.x
- name: Check the tag matches the package version
if: github.ref_type == 'tag'
run: |
VERSION="$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' src/DocSpring.Client/DocSpring.Client.csproj)"
if [ "v$VERSION" != "$GITHUB_REF_NAME" ]; then
echo "::error::The tag is $GITHUB_REF_NAME, but the package version is $VERSION"
exit 1
fi
- run: dotnet pack src/DocSpring.Client/DocSpring.Client.csproj --configuration Release --output out
- if: github.ref_type == 'tag'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: package
path: out/
if-no-files-found: error
publish:
needs: build
if: github.ref_type == 'tag'
runs-on: ubuntu-latest
environment: release
permissions:
contents: read
id-token: write
steps:
- uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
dotnet-version: 9.0.x
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: package
path: out/
# The nuget.org account that owns DocSpring.Client and its trusted publishing policy
- uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2.0
id: login
with:
user: nathan-formapi
- name: Push to NuGet
env:
NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }}
run: |
dotnet nuget push "out/DocSpring.Client.${GITHUB_REF_NAME#v}.nupkg" \
--api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json
verify:
needs: publish
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
# NuGet validates and indexes a package before it serves it, which can take a while
- name: Wait until NuGet serves the version
run: |
VERSION="${GITHUB_REF_NAME#v}"
for _ in $(seq 150); do
if curl -fsS -o /dev/null "https://api.nuget.org/v3-flatcontainer/docspring.client/$VERSION/docspring.client.nuspec"; then
echo "NuGet serves DocSpring.Client $VERSION"
exit 0
fi
sleep 10
done
echo "::error::NuGet doesn't serve DocSpring.Client $VERSION after 25 minutes"
exit 1