-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (138 loc) · 6.16 KB
/
Copy pathpublish-prerelease.yml
File metadata and controls
160 lines (138 loc) · 6.16 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
name: Publish Prerelease
on:
push:
branches:
- main
permissions:
contents: read
env:
TESTINGPLATFORM_EXITCODE_IGNORE: 8
jobs:
tests:
uses: ./.github/workflows/build-template.yml
with:
configuration: Release
publish-prerelease:
needs: tests
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: true
submodules: recursive
- name: Check if commit has a preview release tag
id: check-tags
run: |
git fetch --tags
if git tag --points-at HEAD | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+-preview\.[0-9]+$'; then
echo "is_tagged=true" >> $GITHUB_OUTPUT
else
echo "is_tagged=false" >> $GITHUB_OUTPUT
fi
- name: Setup .NET SDKs
if: steps.check-tags.outputs.is_tagged == 'false'
uses: actions/setup-dotnet@v6
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
11.0.100-preview.6.26359.118
- name: Setup Node.js
if: steps.check-tags.outputs.is_tagged == 'false'
uses: actions/setup-node@v7
with:
node-version: lts/*
- name: Restore WebAssembly workloads
if: steps.check-tags.outputs.is_tagged == 'false'
run: dotnet workload restore NTComponents.slnx --skip-manifest-update
- name: Restore dependencies
if: steps.check-tags.outputs.is_tagged == 'false'
run: dotnet restore NTComponents.slnx -p:SkipAotCompatibilityNativeBuild=true
- name: Install node dependencies
if: steps.check-tags.outputs.is_tagged == 'false'
run: npm ci
- name: Build TypeScript modules
if: steps.check-tags.outputs.is_tagged == 'false'
run: npm run build:ts:release
- name: Build
if: steps.check-tags.outputs.is_tagged == 'false'
run: dotnet build NTComponents.slnx --no-restore --configuration Release -p:SkipAotCompatibilityNativeBuild=true
- name: Install semantic-release
if: steps.check-tags.outputs.is_tagged == 'false'
run: |
npm install --no-save semantic-release @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/github conventional-changelog-conventionalcommits
- name: Publish preview release
if: steps.check-tags.outputs.is_tagged == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
git fetch --tags
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -B preview HEAD
git push --force origin HEAD:preview
GITHUB_REF=refs/heads/preview GITHUB_REF_NAME=preview npx semantic-release
- name: Resolve preview package version
id: release-version
if: steps.check-tags.outputs.is_tagged == 'false'
run: |
set -euo pipefail
git fetch --tags
release_tag=$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-preview\.[0-9]+$' | sort -V | tail -n 1 || true)
if [ -z "$release_tag" ]; then
echo "No preview release was created for this commit; skipping package publication."
echo "version=" >> $GITHUB_OUTPUT
exit 0
fi
echo "version=${release_tag#v}" >> $GITHUB_OUTPUT
- name: Validate NuGet API key
if: steps.check-tags.outputs.is_tagged == 'false' && steps.release-version.outputs.version != ''
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
if [ -z "$NUGET_API_KEY" ]; then
echo "NUGET_API_KEY secret is missing or unavailable to this workflow."
exit 1
fi
- name: Pack NuGet packages
if: steps.check-tags.outputs.is_tagged == 'false' && steps.release-version.outputs.version != ''
run: |
set -euo pipefail
rm -rf ./artifacts/nuget
mkdir -p ./artifacts/nuget
dotnet pack ./NTComponents/NTComponents.csproj --configuration Release --output ./artifacts/nuget /p:PackageVersion=${{ steps.release-version.outputs.version }}
dotnet pack ./NTComponents.AspNetCore/NTComponents.AspNetCore.csproj --configuration Release --output ./artifacts/nuget /p:PackageVersion=${{ steps.release-version.outputs.version }}
dotnet pack ./NTComponents.Extensions/NTComponents.Extensions.csproj --configuration Release --output ./artifacts/nuget /p:PackageVersion=${{ steps.release-version.outputs.version }}
dotnet pack ./NTComponents.Analyzers/NTComponents.Analyzers.csproj --configuration Release --output ./artifacts/nuget /p:PackageVersion=${{ steps.release-version.outputs.version }}
- name: Verify analyzer package
if: steps.check-tags.outputs.is_tagged == 'false' && steps.release-version.outputs.version != ''
run: pwsh ./test-analyzer-package.ps1 -PackagePath "./artifacts/nuget/NTComponents.Analyzers.${{ steps.release-version.outputs.version }}.nupkg"
- name: Publish NuGet packages
if: steps.check-tags.outputs.is_tagged == 'false' && steps.release-version.outputs.version != ''
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push ./artifacts/nuget/*.nupkg --api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate
- name: Delete preview tag on failure
if: failure() && steps.check-tags.outputs.is_tagged == 'false'
run: |
set -euo pipefail
git fetch --tags
tags=$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-preview\.[0-9]+$' || true)
if [ -z "$tags" ]; then
echo "No preview release tag found on this commit."
exit 0
fi
for tag in $tags; do
echo "Deleting failed preview release tag $tag"
git tag -d "$tag" || true
git push origin ":refs/tags/$tag"
done