forked from kwsch/SysBot.NET
-
Notifications
You must be signed in to change notification settings - Fork 12
133 lines (128 loc) · 4.82 KB
/
dotnet-desktop.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
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: .NET Core Desktop
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
version-check:
runs-on: ubuntu-latest
outputs:
current_version: ${{ steps.compare_versions.outputs.current_version }}
version_changed: ${{ steps.compare_versions.outputs.version_changed }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Read Current Version
id: read_version
run: |
CURRENT_VERSION=$(grep 'public const string Version' SysBot.Pokemon/Helpers/TradeBot.cs | sed 's/.*Version = "\(.*\)";/\1/')
echo "Current version is $CURRENT_VERSION"
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Compare Versions
id: compare_versions
run: |
LAST_VERSION=${{ secrets.LAST_KNOWN_VERSION }}
CURRENT_VERSION=${{ env.CURRENT_VERSION }}
echo "Last known version: $LAST_VERSION"
echo "Current version: $CURRENT_VERSION"
if [ "$CURRENT_VERSION" == "$LAST_VERSION" ]; then
echo "No version change detected."
echo "version_changed=false" >> $GITHUB_ENV
echo "version_changed=false" >> $GITHUB_OUTPUT
else
echo "Version change detected."
echo "version_changed=true" >> $GITHUB_ENV
echo "version_changed=true" >> $GITHUB_OUTPUT
fi
build:
needs: version-check
if: needs.version-check.outputs.version_changed == 'true'
runs-on: windows-latest
env:
Project_Name: SysBot.Pokemon.WinForms/SysBot.Pokemon.WinForms.csproj
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2
- name: Restore dependencies
run: dotnet restore ${{ env.Project_Name }} --runtime win-x86
- name: Build
run: dotnet build ${{ env.Project_Name }} --configuration Release --no-restore
- name: Publish
run: dotnet publish ${{ env.Project_Name }} --configuration Release --output ./publish /p:PublishSingleFile=true /p:SelfContained=false /p:RuntimeIdentifier=win-x86
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: MergeBot
path: ./publish
create-release:
needs: [version-check, build]
if: needs.version-check.outputs.version_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Read Current Version
id: read_version
run: |
CURRENT_VERSION=$(grep 'public const string Version' SysBot.Pokemon/Helpers/TradeBot.cs | sed 's/.*Version = "\(.*\)";/\1/')
echo "Current version is $CURRENT_VERSION"
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
- name: Get Recent Changes
id: recent_changes
run: |
LAST_VERSION=${{ secrets.LAST_KNOWN_VERSION }}
if [ -z "$LAST_VERSION" ] || ! git rev-parse "$LAST_VERSION" >/dev/null 2>&1; then
echo "LAST_VERSION is not set or not found, using initial commit"
LAST_VERSION=$(git rev-list --max-parents=0 HEAD)
fi
RECENT_CHANGES=$(git log --pretty=format:"- %s" $LAST_VERSION..HEAD)
echo "RECENT_CHANGES<<EOF" >> $GITHUB_ENV
echo "$RECENT_CHANGES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: MergeBot
path: ./publish
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
with:
tag_name: ${{ env.CURRENT_VERSION }}
release_name: Release ${{ env.CURRENT_VERSION }}
body: |
## Recent Changes
${{ env.RECENT_CHANGES }}
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./publish/MergeBot.exe
asset_name: MergeBot.exe
asset_content_type: application/octet-stream
- name: Update Last Known Version
if: success()
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
gh secret set LAST_KNOWN_VERSION -b"${{ env.CURRENT_VERSION }}"
echo "LAST_KNOWN_VERSION updated to $CURRENT_VERSION"