-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (44 loc) · 1.87 KB
/
code-version.yml
File metadata and controls
50 lines (44 loc) · 1.87 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
name: Increment version
on:
workflow_call:
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
version:
name: Check mergeability and increment version
runs-on: ubuntu-24.04
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
# Make sure that PR has latest changes from main before incrementing version and tagging PR
- name: main branch has no changes since last synced to PR branch
run: |
# https://stackoverflow.com/a/76151412/9747630
# https://github.com/orgs/community/discussions/54825#discussioncomment-7579053
if ! git merge-base --is-ancestor origin/main ${{ github.event.pull_request.head.sha }};
then echo "This branch is not up to date with main";
exit 1; fi
- name: Update version
run: |
# https://api.github.com/users/github-actions%5Bbot%5D
# https://github.com/orgs/community/discussions/26560#discussioncomment-3531273
git config user.name github-actions
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
PACKAGE_FILE="package.json"
VERSION=$(jq -r '.version' "$PACKAGE_FILE")
OLD_VERSION="$VERSION"
MAJOR=$(echo "$VERSION" | cut -d '.' -f 1)
MINOR=$(echo "$VERSION" | cut -d '.' -f 2)
CURRENT_YEAR=$(date +'%Y')
CURRENT_MONTH=$(date +'%-m')
if [ "$MAJOR" != "$CURRENT_YEAR" ] || [ "$MINOR" != "$CURRENT_MONTH" ]; then
npm version "$CURRENT_YEAR.$CURRENT_MONTH.0"
echo "Version updated from $OLD_VERSION to $VERSION"
else
npm version patch
fi
git push && git push --tags