forked from Drassil/action-package-version-bump
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
67 lines (64 loc) · 2.78 KB
/
action.yml
File metadata and controls
67 lines (64 loc) · 2.78 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
name: 'action-package-version-bump'
description: 'Github action to upgrade the package.json version and create a changelog based on PR description'
inputs:
repository:
description: 'The github repository where to pull the changes (only the path, without the host)'
required: false
user_name:
description: 'Name of the git user to push the changes'
required: true
user_email:
description: 'Email of the git user to push the changes'
required: true
ref_branch:
description: 'Branch to use as a base reference for the version bump'
required: false
default: 'master'
use_rebase:
description: 'Use rebase strategy for pull'
required: false
default: false
version_args:
description: 'npm version command arguments. '
required: false
default: 'patch'
node_version:
description: 'node version used for the npm commands'
required: false
default: '16'
access_token:
description: 'Personal access token to clone the repository. Default: github.token'
required: false
runs:
using: 'composite'
steps:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ inputs.node_version }}
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
token: ${{ inputs.access_token || github.token }}
- name: Pull and bump version
shell: bash
run: |
git remote add main-repo https://github.com/${{ inputs.repository || github.repository }}
git config --global user.name ${{ inputs.user_name }}
git config --global user.email ${{ inputs.user_email }}
git config --global pull.rebase ${{ inputs.use_rebase }}
git pull main-repo ${{ inputs.ref_branch }}
echo "Updating version"
npm version --no-git-tag-version ${{ inputs.version_args }}
PACKAGE_VERSION=`node -e "console.log(require('./package.json').version);"`
echo "Package version: $PACKAGE_VERSION. Getting previous changelog"
PREV_CHANGELOG=`git show main-repo/${{ inputs.ref_branch }}:CHANGELOG.md || true`
echo "Composing new changelog"
echo -e "Rev: $PACKAGE_VERSION\n=============\n ${{ github.event.pull_request.body }}\n\n\n" > CHANGELOG.md
echo -e "$PREV_CHANGELOG" >> CHANGELOG.md
echo "Creating commit and pushing"
git add -A
git commit -m "chore: bump package version to $PACKAGE_VERSION and update changelog"
git push --force https://${{ inputs.access_token || github.token }}@github.com/${{ github.event.pull_request.head.repo.full_name }}