-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (118 loc) · 3.9 KB
/
release.yaml
File metadata and controls
133 lines (118 loc) · 3.9 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Version Number"
required: true
type: string
jobs:
version:
name: Validate version
runs-on: ubuntu-latest
outputs:
version_3: ${{ steps.version.outputs.version_3 }}
version_suffix: ${{ steps.version.outputs.version_suffix }}
version_full: ${{ steps.version.outputs.version_full }}
is_prerelease: ${{ steps.version.outputs.is_prerelease }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: build
- name: Parse version
id: version
run: ./build/Get-Version.ps1 -Version ${{ inputs.version }}
shell: pwsh
build:
name: (.NET) Build & Test
uses: ./.github/workflows/build-dotnet.yaml
permissions:
id-token: write
contents: read
checks: write
publish:
name: Publish
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
needs:
- version
- build
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Restore cache
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Pack
run: dotnet pack -p:VersionPrefix="${{ needs.version.outputs.version_3 }}" --version-suffix "${{ needs.version.outputs.version_suffix }}"
- name: NuGet login
uses: NuGet/login@v1
id: login
with:
user: ${{ secrets.NUGET_USER }}
- name: Publish
run: dotnet nuget push "*.nupkg" --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
working-directory: .nupkgs
- name: Create tag
uses: actions/github-script@v8
env:
TAG: v${{ needs.version.outputs.version_full }}
with:
script: |
const tag = process.env.TAG;
// Check if tag already exists
let existingTag;
try {
existingTag = await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${tag}`
});
} catch (error) {
if (error.status === 404) {
// Tag doesn't exist, we can create it
existingTag = null;
} else {
throw error;
}
}
if (existingTag) {
const existingSha = existingTag.data.object.sha;
if (existingSha === context.sha) {
console.log(`Tag ${tag} already exists with the same SHA (${context.sha}). Skipping tag creation.`);
return;
} else {
throw new Error(`Tag ${tag} already exists with a different SHA. Existing: ${existingSha}, Current: ${context.sha}`);
}
}
// Create the tag
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tag}`,
sha: context.sha
});
console.log(`Tag ${tag} created successfully at ${context.sha}`);
- name: Create GitHub release
uses: ncipollo/release-action@v1
with:
tag: v${{ needs.version.outputs.version_full }}
draft: true
generateReleaseNotes: true
artifacts: ".nupkgs/*"
allowUpdates: true
updateOnlyUnreleased: true
prerelease: ${{ needs.version.outputs.is_prerelease }}