-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (78 loc) · 2.9 KB
/
publish.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
name: Publish to NuGet
on:
push:
branches:
- main
jobs:
publish:
name: publish release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🔨 set up .net 7
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
- name: 👌 extract version
shell: pwsh
run: |
$csprojPath = "src/LazyCart/LazyCart.csproj"
$csproj = [xml](Get-Content -Path $csprojPath)
$version = $csproj.Project.PropertyGroup.Version
echo "Version: $version"
echo "VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: 🧹 Trim VERSION variable
run: echo "VERSION=$(echo "$VERSION" | xargs)" >> $GITHUB_ENV
- name: 🔎 check if version changed
run: |
git fetch origin
CS_PROJ_FILE="src/LazyCart/LazyCart.csproj"
git show HEAD^:$CS_PROJ_FILE > old_csproj.xml
cp $CS_PROJ_FILE new_csproj.xml
OLD_VERSION=$(grep -oP '<Version>\K(.*?)(?=</Version>)' old_csproj.xml)
NEW_VERSION=$(grep -oP '<Version>\K(.*?)(?=</Version>)' new_csproj.xml)
VERSION_CHANGED=0
if [ "$OLD_VERSION" = "$NEW_VERSION" ]; then
echo "The <Version> tag has not changed."
else
echo "The <Version> tag has changed from $OLD_VERSION to $NEW_VERSION."
VERSION_CHANGED=1
fi
echo "VERSION_CHANGED=$VERSION_CHANGED" >> $GITHUB_ENV
- name: ⚗ restore dependencies
if: env.VERSION_CHANGED == '1'
run: dotnet restore src
- name: 🛠 build
if: env.VERSION_CHANGED == '1'
run: dotnet build src --configuration Release --no-restore
- name: 🎁 pack nuget
if: env.VERSION_CHANGED == '1'
run: dotnet pack src/LazyCart/LazyCart.csproj --configuration Release --include-symbols /p:SymbolPackageFormat=snupkg /p:ContinuousIntegrationBuild=true /p:Version="${{ env.VERSION }}" --output .
- name: 💌 publish nuget
if: env.VERSION_CHANGED == '1'
run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_KEY} --skip-duplicate
env:
NUGET_KEY: ${{ secrets.NUGET_API_KEY }}
- name: 🔨 set up python
if: env.VERSION_CHANGED == '1'
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: 📢 extract release notes
if: env.VERSION_CHANGED == '1'
run: |
python scripts/extract_changelog.py CHANGELOG.md latest_release.md
- name: 📑 create github release
if: env.VERSION_CHANGED == '1'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.VERSION }}
release_name: Release v${{ env.VERSION }}
draft: false
prerelease: false
body_path: latest_release.md