-
Notifications
You must be signed in to change notification settings - Fork 10
179 lines (149 loc) · 5.48 KB
/
publish-packages.yml
File metadata and controls
179 lines (149 loc) · 5.48 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Publish Packages
on:
workflow_dispatch:
env:
DOTNET_VERSION: '9.0.x'
PROJECT_PATH: 'src/BlazorTextDiff/BlazorTextDiff.csproj'
ARTIFACT_NAME: 'BlazorTextDiff-Package'
jobs:
build-and-test:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
should-publish: ${{ steps.check-publish.outputs.should-publish }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Install .NET workloads
run: dotnet workload install wasm-tools
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Generate version number
id: version
run: |
# Generate date-based version similar to 2021.4.22.43642
UTC_DATE=$(date -u '+%Y.%m.%d')
START_OF_DAY=$(date -u -d "today 00:00:00" '+%s')
CURRENT_TIME=$(date -u '+%s')
SECONDS_SINCE_MIDNIGHT=$(( (CURRENT_TIME - START_OF_DAY) / 2 ))
VERSION="$UTC_DATE.$SECONDS_SINCE_MIDNIGHT"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Generated version: $VERSION"
- name: Update project version
run: |
sed -i "s|<Version>.*</Version>|<Version>${{ steps.version.outputs.version }}</Version>|" ${{ env.PROJECT_PATH }}
echo "Updated version in project file to: ${{ steps.version.outputs.version }}"
cat ${{ env.PROJECT_PATH }} | grep -A1 -B1 "<Version>"
- name: Restore dependencies
run: |
dotnet workload restore
dotnet restore
- name: Build solution
run: dotnet build --no-restore --configuration Release
- name: Run tests
run: dotnet test --no-build --configuration Release --verbosity normal
- name: Pack NuGet package
run: dotnet pack ${{ env.PROJECT_PATH }} --no-build --configuration Release --output ./artifacts
- name: Check if should publish
id: check-publish
run: |
echo "should-publish=true" >> $GITHUB_OUTPUT
echo "Will publish packages (manual trigger)"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}-${{ steps.version.outputs.version }}
path: ./artifacts/*.nupkg
if-no-files-found: error
publish-github:
name: Publish to GitHub Packages
runs-on: ubuntu-latest
needs: build-and-test
if: needs.build-and-test.outputs.should-publish == 'true'
permissions:
contents: read
packages: write
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}-${{ needs.build-and-test.outputs.version }}
path: ./artifacts
- name: Publish to GitHub Packages
run: |
dotnet nuget push "./artifacts/*.nupkg" \
--source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \
--api-key ${{ secrets.GITHUB_TOKEN }} \
--skip-duplicate
publish-nuget:
name: Publish to NuGet.org
runs-on: ubuntu-latest
needs: build-and-test
if: needs.build-and-test.outputs.should-publish == 'true'
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}-${{ needs.build-and-test.outputs.version }}
path: ./artifacts
- name: Publish to NuGet.org
run: |
dotnet nuget push "./artifacts/*.nupkg" \
--api-key ${{ secrets.NUGET_API_KEY }} \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [build-and-test]
if: needs.build-and-test.outputs.should-publish == 'true'
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}-${{ needs.build-and-test.outputs.version }}
path: ./artifacts
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.build-and-test.outputs.version }}
name: Release v${{ needs.build-and-test.outputs.version }}
body: |
## BlazorTextDiff v${{ needs.build-and-test.outputs.version }}
### 📦 Package Information
- **Version**: ${{ needs.build-and-test.outputs.version }}
- **Built**: ${{ github.run_id }}
- **Commit**: ${{ github.sha }}
### 📥 Installation
```bash
dotnet add package BlazorTextDiff --version ${{ needs.build-and-test.outputs.version }}
```
### 🔗 Links
- [NuGet Package](https://www.nuget.org/packages/BlazorTextDiff/${{ needs.build-and-test.outputs.version }})
- [GitHub Package](https://github.com/${{ github.repository }}/packages)
files: ./artifacts/*.nupkg
draft: false
prerelease: false