-
Notifications
You must be signed in to change notification settings - Fork 83
100 lines (84 loc) · 2.99 KB
/
CI.yml
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
name: CI
on:
pull_request:
branches: [main]
push:
branches: [main]
tags:
- v*
workflow_dispatch:
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
jobs:
github_env:
name: GitHub Env Debug
runs-on: ubuntu-latest
steps:
- name: Dump github context
run: echo "$GITHUB_CONTEXT"
shell: bash
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
build_win:
name: Windows
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Version
if: contains(github.ref, 'tags/')
shell: pwsh
run: |
if($env:GITHUB_REF.StartsWith("refs/tags/v", "CurrentCultureIgnoreCase"))
{
$BuildVersion = $env:GITHUB_REF.Remove(0, 11);
echo "BuildVersion=$BuildVersion" >> $env:GITHUB_ENV
# github的内置版本有Bug, 此行必须添加否则无法获得内容
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
$releaseNotes = & git tag -l --format='%(contents)' $env:GITHUB_REF.Remove(0, 10)
$content = [System.IO.File]::ReadAllText("libwsk.NuGet\Musa.libwsk.nuspec")
$releaseNotesToken = '$releaseNotes$'
$releaseNotesIndex = $content.IndexOf($releaseNotesToken)
if($releaseNotesIndex -ne -1)
{
echo $content.Substring(0, $releaseNotesIndex) | out-file "libwsk.NuGet\Musa.libwsk-New.nuspec" -NoNewline
echo $releaseNotes | out-file "libwsk.NuGet\Musa.libwsk-New.nuspec" -Append
echo $content.Remove(0, $releaseNotesIndex + $releaseNotesToken.Length) | out-file "libwsk.NuGet\Musa.libwsk-New.nuspec" -NoNewline -Append
}
}
- name: Build
shell: pwsh
run: |
& "${{github.workspace}}\Publish.bat"
- name: Build NuGet
if: contains(github.ref, 'tags/')
shell: cmd
run: |
if "${{env.BuildVersion}}" NEQ "" (
NuGet pack .\libwsk.NuGet\Musa.libwsk-New.nuspec -Properties version=${{env.BuildVersion}};commit=%GITHUB_SHA%
)
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
- name: Build Zip
shell: cmd
run: |
7z a -tzip -r "./libwsk.zip" "./Publish/*"
- name: Publish NuGet
if: contains(github.ref, 'tags/')
shell: cmd
run: |
NuGet push Musa.libwsk.${{env.BuildVersion}}.nupkg -ApiKey ${{ secrets.NUGET_TOKEN }} -Source https://api.nuget.org/v3/index.json
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
- name: Publish Artifacts
uses: actions/upload-artifact@v4
with:
name: libwsk
path: Publish/
if-no-files-found: error
- name: Publish Version
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v2
with:
files: |
*.zip
*.nupkg