-
Notifications
You must be signed in to change notification settings - Fork 1
62 lines (59 loc) · 2.31 KB
/
version_update.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
name: Update package version for release & hotfix branches
on:
workflow_call:
secrets:
caller_github_token:
required: true
permissions:
contents: write
pull-requests: write
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: update package version
id: vars
run: |
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
PACKAGE_VERSION="${GITHUB_REF##*/}"
echo branch=${BRANCH_NAME} >> $GITHUB_OUTPUT
if [[ $PACKAGE_VERSION =~ ^v[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]
then
if [[ $PACKAGE_VERSION =~ ^v[0-9]+\.[0-9]+$ ]]
then
PACKAGE_VERSION="${PACKAGE_VERSION}.0"
fi
echo version=${PACKAGE_VERSION} >> $GITHUB_OUTPUT
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
if npm --no-git-tag-version version ${PACKAGE_VERSION} &> temp-npm-version.txt
then
echo should_create_pr=1 >> $GITHUB_OUTPUT
git add package.json package-lock.json
git commit -m ${PACKAGE_VERSION}
git push -u origin HEAD:"dev/update-version-${PACKAGE_VERSION}"
exit 0
fi
echo should_create_pr=0 >> $GITHUB_OUTPUT
if grep -q 'npm ERR! Version not changed' temp-npm-version.txt
then
echo "Package version is already in sync with branch name."
exit 0
fi
cat temp-npm-version.txt
exit 1
else
echo "Branch name ${BRANCH_NAME} does not have the correct format with package version."
exit 1
fi
- name: create version update pr
if: steps.vars.outputs.should_create_pr == 1
uses: repo-sync/pull-request@v2
with:
source_branch: "dev/update-version-${{ steps.vars.outputs.version }}"
destination_branch: "${{ steps.vars.outputs.branch }}"
pr_title: "Update Package Version to ${{ steps.vars.outputs.version }}"
pr_body: "*An automated PR which updates the version number in package.json and package-lock.json files*"
github_token: ${{ secrets.caller_github_token }}