forked from AlexeyTaranov/SerializeReferenceDropdown
-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (117 loc) · 4.5 KB
/
release.yml
File metadata and controls
134 lines (117 loc) · 4.5 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
name: Release Unity Package
on:
push:
branches: [ master ]
workflow_dispatch:
inputs:
bump:
description: "Version bump type (patch/minor/major)"
required: false
default: "patch"
permissions:
contents: write
pull-requests: write
jobs:
release:
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_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$last_tag" ]; then
commits=$(git log --pretty=format:"%h")
else
commits=$(git log $last_tag..HEAD --pretty=format:"%h")
fi
if [ -z "$commits" ]; then
echo "no_new_commits=true" >> $GITHUB_OUTPUT
echo "No new commits since last release."
else
echo "no_new_commits=false" >> $GITHUB_OUTPUT
echo "New commits detected, proceeding with release."
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
echo "Version bumped to $new_version"
- 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)")
else
log=$(git log $last_tag..HEAD --pretty=format:"- %s (%h)")
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**
After merging, a new draft GitHub release will be created automatically.
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 }}