-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (93 loc) · 3.39 KB
/
create-draft-release.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
name: Create Draft Release
on:
workflow_dispatch:
inputs:
bump:
description: "Use PATCH for fixes, use MINOR for new features and use MAJOR for breaking changes"
type: choice
options:
- patch
- minor
- major
required: true
permissions:
contents: write
jobs:
build:
if: ${{ github.actor != 'dependabot'}}
runs-on: ubuntu-latest
outputs:
release: ${{ steps.prerelease.outputs.release }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Environment
uses: ./.github/actions/setup
- name: Calculate next version
id: next_version
run: |
# Get the latest tag, default to v0.0.0 if no tags exist
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "v0.0.0")
# Extract major, minor, and patch from the tag
VERSION=${LATEST_TAG#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
# Determine which part to bump based on the input variable
if [ "${{ inputs.bump }}" = "major" ]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [ "${{ inputs.bump }}" = "minor" ]; then
MINOR=$((MINOR + 1))
PATCH=0
elif [ "${{ inputs.bump }}" = "patch" ]; then
PATCH=$((PATCH + 1))
else
echo "Invalid bump input: ${{ inputs.bump }}"
exit 1
fi
# Create the new version string
NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}"
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
# Set the new version in the GitHub environment
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
echo "New version: $NEW_VERSION"
- name: Update package.json version
id: update_package_version
run: |
# Update the version in the root package.json
jq ".version = \"${NEW_VERSION}\"" package.json > package.json.tmp && mv package.json.tmp package.json
# Update the version in all packages inside the packages folder
for package_json in packages/*/package.json; do
if [ -f "$package_json" ]; then
echo "Updating version in $package_json to ${NEW_VERSION}"
jq ".version = \"${NEW_VERSION}\"" "$package_json" > "${package_json}.tmp" && mv "${package_json}.tmp" "$package_json"
else
echo "No package.json found in $package_json"
fi
done
- name: Build And Test
id: build-and-test
run: |
pnpm build
- name: Commit changes
run: |
# Configure Git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Commit and push the changes
git add .
git commit -m "Bump version to ${NEW_TAG}"
git push origin HEAD:main
git tag $NEW_TAG
git push origin $NEW_TAG
# Create a draft release
- name: Create GitHub draft release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "$NEW_VERSION" \
--draft \
--generate-notes