-
Notifications
You must be signed in to change notification settings - Fork 47
190 lines (157 loc) · 6.68 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
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
180
181
182
183
184
185
186
187
188
189
190
name: Code Check and Release
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Set global defaults, including the working directory
defaults:
run:
working-directory: ./src # Default working directory for all jobs and steps
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v3
# Set up .NET Core using the repository-level DOTNET_VERSION environment variable
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ vars.DOTNET_VERSION }} # Using repository-level environment variable
# Restore dependencies
- name: Restore dependencies
run: dotnet restore
# Build the solution
- name: Build solution
run: dotnet build --no-restore
# Run unit tests
- name: Test
run: dotnet test --no-build --verbosity normal
bump-version:
runs-on: ubuntu-latest
if: ${{ startsWith(github.event.head_commit.message, 'release v') }}
needs: [ build ]
# override working directory for this job
defaults:
run:
working-directory: ./
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0 # Ensures that we have access to the full commit history
- name: Extract Version and Description
id: extract_version_description
run: |
FULL_MESSAGE="${{ github.event.head_commit.message }}"
SUMMARY=$(echo "$FULL_MESSAGE" | head -n 1)
DESCRIPTION=$(echo "$FULL_MESSAGE" | tail -n +3)
if [[ $SUMMARY =~ ^release\ v([0-9]+\.[0-9]+\.[0-9]+) ]]; then
VERSION="${BASH_REMATCH[1]}"
else
echo "Commit message does not match the pattern 'release vx.x.x'"
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
printf "DESCRIPTION<<EOF\n%s\nEOF\n" "$DESCRIPTION" >> $GITHUB_ENV
echo "Bumping version to $VERSION"
- name: Run Version Bump Script
run: |
echo "Current directory: $(pwd)"
chmod +x ./bump_version.sh
./bump_version.sh "$VERSION"
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Check for Changes
id: check_changes
run: |
# Check if there are any changes to commit
if [[ -n "$(git status --porcelain)" ]]; then
echo "changes=true" >> $GITHUB_ENV
else
echo "changes=false" >> $GITHUB_ENV
fi
- name: Commit and Push Changes
id: commit_version_bump # Capture this step ID to get the commit SHA
if: env.changes == 'true'
run: |
# Commit the changes with the specified message
git add .
git commit -m "Bump to v$VERSION"
# Push changes back to main
git push origin main
env:
VERSION: ${{ env.VERSION }}
# Set up .NET Core using the repository-level DOTNET_VERSION environment variable
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
${{ vars.DOTNET_VERSION }}
3.1.x
2.1.x
# Restore dependencies
- name: Restore dependencies
working-directory: ./src # Override the default working directory
run: dotnet restore
# Build the solution
- name: Build solution
working-directory: ./src # Override the default working directory
run: dotnet build --no-restore --configuration Release
# Copy src/Nino/bin/Release/netstandard2.1/Nino.Core.dll and src/Nino/bin/Release/netstandard2.1/Nino.Generator.dll
# to Nino_Unity/Packages/com.jasonxudeveloper.nino/Runtime, replacing the existing DLLs
- name: Copy DLLs
run: |
cp ./src/Nino/bin/Release/netstandard2.1/Nino.Core.dll ./Nino_Unity/Packages/com.jasonxudeveloper.nino/Runtime
cp ./src/Nino/bin/Release/netstandard2.1/Nino.Generator.dll ./Nino_Unity/Packages/com.jasonxudeveloper.nino/Runtime
# Commit the changes (only the 2 dlls)
- name: Commit Changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add ./Nino_Unity/Packages/com.jasonxudeveloper.nino/Runtime/Nino.Core.dll ./Nino_Unity/Packages/com.jasonxudeveloper.nino/Runtime/Nino.Generator.dll
git commit -m "Bump Unity Package DLLs to v$VERSION"
git push origin main
- name: Get Commit SHA
run: echo "COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Create GitHub Release
id: create_release # Capture the release ID for uploading assets
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "v${{ env.VERSION }}" # Release tag, like "v1.2.3"
commitish: "${{ env.COMMIT_SHA }}" # Ensures the release points to the bump commit
release_name: "v${{ env.VERSION }}" # Title of the release, same as the tag
body: "${{ env.DESCRIPTION }}" # Release notes from commit message
draft: false # Make the release public immediately
prerelease: false # Mark it as a stable release
# Set up .NET Core using the repository-level DOTNET_VERSION environment variable
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ vars.DOTNET_VERSION }} # Using repository-level environment variable
# Restore dependencies
- name: Restore dependencies
working-directory: ./src # Override the default working directory
run: dotnet restore
# Build the solution
- name: Build solution
working-directory: ./src # Override the default working directory
run: dotnet build --configuration Release /p:OutputPath=../artifacts
# Push NuGet packages
- name: Push NuGet Packages
working-directory: ./src # Override the default working directory
run: |
echo "Current directory: $(pwd)"
for package in ./artifacts/*.nupkg; do
dotnet nuget push "$package" --api-key ${{ secrets.MYTOKEN }} --source https://api.nuget.org/v3/index.json
done
benchmark:
needs: [ bump-version ]
uses: JasonXuDeveloper/Nino/.github/workflows/report.yml@main