-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (123 loc) · 4.34 KB
/
create-rlease-pr.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
name: Bump Version
on:
workflow_dispatch:
inputs:
version-type:
description: 'Select version type'
required: true
default: 'patch'
type: choice
options:
- major
- minor
- patch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_EMAIL: '41898282+github-actions[bot]@users.noreply.github.com'
GH_USER: 'github-actions[bot]'
jobs:
bump-version:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
permissions:
contents: write
pull-requests: write
env:
VERSION_TYPE: ${{ github.event.inputs.version-type }}
steps:
- run: |
git config --global user.name "${GH_USER}"
git config --global user.email "${GH_EMAIL}"
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install pnpm
uses: pnpm/[email protected]
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Display selected version type
run: echo "Selected version type-> ${VERSION_TYPE}"
# You can add your own logic here based on the selected version type
- name: Bump version based on input
run: |
case "${VERSION_TYPE}" in
major)
echo "Bumping major version"
pnpm version major --no-commit-hooks --no-git-tag-version
;;
minor)
echo "Bumping minor version"
pnpm version minor --no-commit-hooks --no-git-tag-version
;;
patch)
echo "Bumping patch version"
pnpm version patch --no-commit-hooks --no-git-tag-version
;;
esac
- name: Parse package.json
id: identify-version
run: |
APP_VERSION="$(cat ./package.json |jq .version|sed -e 's/"//g'| head -n1)"
if [ ! -n "${APP_VERSION}" ]; then
exit 255
fi
echo "Detected the version: ${APP_VERSION}"
echo "app-version=${APP_VERSION}" >>"${GITHUB_OUTPUT}"
echo "app-version-text=v${APP_VERSION}" >>"${GITHUB_OUTPUT}"
- name: Check if there are any changes
run: |
git add -N .
if git diff --exit-code --quiet; then
echo "No changes detected."
echo "ERROR: could not update the package.json"
exit 1
else
echo "Changes detected."
fi
- name: Checkout new repository
id: create-repository
env:
APP_VERSION: ${{steps.identify-version.outputs.app-version}}
APP_VERSION_TEXT: ${{steps.identify-version.outputs.app-version-text}}
run: |
BRANCH_NAME="release/${APP_VERSION_TEXT}"
git checkout -b "${BRANCH_NAME}"
echo "branch-name=${BRANCH_NAME}" >>"${GITHUB_OUTPUT}"
- name: Update the changelog
env:
APP_VERSION: ${{steps.identify-version.outputs.app-version}}
APP_VERSION_TEXT: ${{steps.identify-version.outputs.app-version-text}}
run: |
pnpm run changelog --tag "${APP_VERSION_TEXT}"
pnpm exec prettier --write CHANGELOG.md
git add CHANGELOG.md
git commit -F-<<EOF
chore: update the CHANGELOG.md for ${APP_VERSION_TEXT}
[AUTO] this commit is created by github actions automatialy.
EOF
- name: Commit package.json
env:
APP_VERSION: ${{steps.identify-version.outputs.app-version}}
APP_VERSION_TEXT: ${{steps.identify-version.outputs.app-version-text}}
run: |
git add package.json
git commit -F-<<EOF
chore: update version of package.json for ${APP_VERSION_TEXT}
[AUTO] this commit is created by github actions automatialy.
EOF
- name: Push commits
env:
BRANCH_NAME: ${{ steps.create-repository.outputs.branch-name }}
run: |
git push -u origin "${BRANCH_NAME}"
- name: Create pull request
env:
APP_VERSION_TEXT: ${{steps.identify-version.outputs.app-version-text}}
run: |
gh pr create --title "chore(release): ${APP_VERSION_TEXT}" --body "**Preparations for ${APP_VERSION_TEXT}**"