-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (77 loc) · 3.01 KB
/
create_release.yaml
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
name: Release Aperture C# SDK
on:
workflow_dispatch:
inputs:
version_type:
type: choice
description: 'Version Type'
required: true
options:
- major
- minor
- patch
default: minor
concurrency:
cancel-in-progress: false
group: ${{ github.repository }}-release-aperture-csharp
jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git Name and Email
run: |
git config --global user.name "FluxNinja Ops"
git config --global user.email [email protected]
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Install GitHub CLI
run: |
brew install gh
- name: Check diff and Create Release
env:
GH_TOKEN: ${{ github.token }}
run: |
# Fetch all tags
git fetch --tags
# Get the latest tag name
latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
# Get diff between latest tag and current commit
diff=$(git log $latestTag..HEAD --oneline)
# If there is no diff, exit
if [ -z "$diff" ]; then
echo "No changes since $latestTag."
exit 0
fi
# Fetch the version from the latest tag name and increment it
version=$(echo $latestTag | grep -oP '(?<=v)\d+\.\d+\.\d+')
# Get the version type
versionType="${{ github.event.inputs.version_type }}"
if [ "$versionType" = "major" ]; then
newVersion=$(echo $version | awk -F. '{$1 = $1 + 1; $2 = 0; $3 = 0} 1' | sed 's/ /./g')
elif [ "$versionType" = "minor" ]; then
newVersion=$(echo $version | awk -F. '{$2 = $2 + 1; $3 = 0} 1' | sed 's/ /./g')
elif [ "$versionType" = "patch" ]; then
newVersion=$(echo $version | awk -F. '{$3 = $3 + 1;} 1' | sed 's/ /./g')
else
echo "Invalid version type."
exit 1
fi
# Replace the version
sed -i "s/<Version>.*<\/Version>/<Version>$newVersion<\/Version>/g" ApertureSDK.csproj
sed -i "s/--version .*/--version $newVersion/g" README.md
# Create a new stable branch
git checkout -b "stable/v${newVersion}"
git commit --allow-empty -am "Bump version to ${newVersion}"
# Create a new tag and push it to origin
git tag -a "releases/aperture-csharp/v${newVersion}" -m "Release v${newVersion}"
# Push the branch and tag to origin
git push origin "stable/v${newVersion}"
git push origin "releases/aperture-csharp/v${newVersion}"
# Create a new release
gh release create "releases/aperture-csharp/v${newVersion}" --title "Release v${newVersion}" --target "stable/v${newVersion}" --generate-notes --latest --verify-tag