forked from AlexeyTaranov/SerializeReferenceDropdown
-
Notifications
You must be signed in to change notification settings - Fork 0
211 lines (180 loc) · 6.84 KB
/
release.yml
File metadata and controls
211 lines (180 loc) · 6.84 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
name: Release Unity Package
on:
push:
branches: [ master ]
paths-ignore:
- "package.json"
- "CHANGELOG.md"
workflow_dispatch:
inputs:
bump:
description: "Version bump type (patch/minor/major)"
required: false
default: "patch"
permissions:
contents: write
pull-requests: write
checks: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
name: Run Unity Tests 🧪
if: "${{ github.event_name != 'push' || !startsWith(github.event.head_commit.message, 'chore: release') }}"
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Setup Unity Test Project
run: |
mkdir -p UnityProject/Assets
mkdir -p UnityProject/Packages
mkdir -p UnityProject/ProjectSettings
# Copy package into Packages folder
mkdir -p UnityProject/Packages/com.alexeytaranov.serializereferencedropdown
rsync -a . UnityProject/Packages/com.alexeytaranov.serializereferencedropdown/ \
--exclude UnityProject \
--exclude .git \
--exclude .github
# Register package & dependencies
cat <<EOF > UnityProject/Packages/manifest.json
{
"dependencies": {
"com.alexeytaranov.serializereferencedropdown": "file:com.alexeytaranov.serializereferencedropdown",
"com.unity.test-framework": "1.1.33",
"com.unity.nuget.newtonsoft-json": "3.2.0"
}
}
EOF
# Unity version
echo "m_EditorVersion: 2022.3.10f1" > UnityProject/ProjectSettings/ProjectVersion.txt
- name: Cache Library
uses: actions/cache@v3
with:
path: UnityProject/Library
key: Library-${{ hashFiles('UnityProject/Packages/manifest.json') }}
restore-keys: |
Library-
- name: Run Unity Tests
uses: game-ci/unity-test-runner@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
projectPath: UnityProject
unityVersion: 2022.3.10f1
testMode: EditMode
githubToken: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: Test Results
path: UnityProject/artifacts
release:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install jq
run: sudo apt-get install -y jq
- name: Get current version
id: get_version
run: |
version=$(jq -r '.version' package.json)
echo "current_version=$version" >> $GITHUB_OUTPUT
echo "Current version: $version"
- name: Check for new commits since last tag
id: check_commits
run: |
last_commit_msg=$(git log -1 --pretty=%s)
if [[ "$last_commit_msg" == "chore: release"* ]]; then
echo "no_new_commits=true" >> $GITHUB_OUTPUT
exit 0
fi
last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$last_tag" ]; then
commits=$(git log --pretty=format:"%h" -- Editor Runtime Samples~ Tests)
else
commits=$(git log $last_tag..HEAD --pretty=format:"%h" -- Editor Runtime Samples~ Tests)
fi
if [ -z "$commits" ]; then
echo "no_new_commits=true" >> $GITHUB_OUTPUT
else
echo "no_new_commits=false" >> $GITHUB_OUTPUT
fi
- name: Bump version
if: steps.check_commits.outputs.no_new_commits == 'false'
id: bump_version
run: |
bump="${{ github.event.inputs.bump || 'patch' }}"
version=$(jq -r '.version' package.json)
IFS='.' read -r major minor patch <<< "$version"
case "$bump" in
major) new_version="$((major + 1)).0.0" ;;
minor) new_version="$major.$((minor + 1)).0" ;;
*) new_version="$major.$minor.$((patch + 1))" ;;
esac
jq ".version = \"$new_version\"" package.json > tmp.json && mv tmp.json package.json
echo "new_version=$new_version" >> $GITHUB_OUTPUT
- name: Generate changelog text
if: steps.check_commits.outputs.no_new_commits == 'false'
id: changelog
run: |
last_tag=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$last_tag" ]; then
log=$(git log --pretty=format:"- %s (%h)" -- Editor Runtime Samples~ Tests)
else
log=$(git log $last_tag..HEAD --pretty=format:"- %s (%h)" -- Editor Runtime Samples~ Tests)
fi
log=$(echo "$log" | grep -v -E "Merge (pull request|branch)" || true)
echo "$log" > changelog.txt
echo "log<<EOF" >> $GITHUB_OUTPUT
echo "$log" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Update CHANGELOG.md
if: steps.check_commits.outputs.no_new_commits == 'false'
run: |
VERSION=${{ steps.bump_version.outputs.new_version }}
DATE=$(date +'%Y-%m-%d')
echo "## v$VERSION - $DATE" > new_changelog.md
cat changelog.txt >> new_changelog.md
echo "" >> new_changelog.md
if [ -f CHANGELOG.md ]; then
cat CHANGELOG.md >> new_changelog.md
fi
mv new_changelog.md CHANGELOG.md
- name: Create PR with version bump
if: steps.check_commits.outputs.no_new_commits == 'false'
uses: peter-evans/create-pull-request@v6
with:
commit-message: "chore: release v${{ steps.bump_version.outputs.new_version }}"
branch: "release/v${{ steps.bump_version.outputs.new_version }}"
title: "Release v${{ steps.bump_version.outputs.new_version }}"
body: |
This PR updates:
- **package.json**
- **CHANGELOG.md**
labels: release
add-paths: |
package.json
CHANGELOG.md
- name: Create draft GitHub release
if: steps.check_commits.outputs.no_new_commits == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.bump_version.outputs.new_version }}
name: Release ${{ steps.bump_version.outputs.new_version }}
body: |
🧩 Unity package **com.alexeytaranov.serializereferencedropdown**
Version: ${{ steps.bump_version.outputs.new_version }}
### Changelog
${{ steps.changelog.outputs.log }}
draft: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}