-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathversion
executable file
·147 lines (122 loc) · 4.63 KB
/
version
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
141
142
143
144
145
146
147
#!/usr/bin/env bash
# https://calver.org
# https://gist.github.com/DarrenN/8c6a5b969481725a4413
declare -r DRY='' # '--dry-run'
# sign-git-tag to prevent infinite recursion
# https://unix.stackexchange.com/a/257065
# https://github.com/keybase/keybase-issues/issues/2798
# https://jam.dev/blog/articles/error-gpg-failed-to-sign-the-data
# https://gist.github.com/paolocarrasco/18ca8fe6e63490ae1be23e84a7039374
# https://gnupg.org/documentation/manuals/gnupg/Invoking-GPG_002dAGENT.html
# https://github.com/keybase/keybase-issues/issues/2798#issuecomment-2290965368
declare -r SIGN='' # --sign-git-tag'
# ignore-scripts to prevent infinite recursion
declare -r IGNORE='--ignore-scripts'
# https://github.com/orgs/community/discussions/13836
# https://docs.npmjs.com/generating-provenance-statements
declare -r PUBLISH='npm publish --provenance --access public'
declare DATE=$(date)
# https://lachy.id.au/dev/script/examples/datetime/DateFormatStrings.html
declare YEAR=$(date +%Y)
declare MONTH=$(date +%m)
declare DAY=$(date +%d)
# remove double quotes
declare VERSION=$(npm pkg get version --workspaces=false | tr -d \")
# https://stackoverflow.com/q/918886
declare MAJOR=$( echo $VERSION | cut -d "." -f 1 )
declare MINOR=$( echo $VERSION | cut -d "." -f 2 )
declare PATCH=$( echo $VERSION | cut -d "." -f 3 )
echo Package Version: $VERSION
echo MAJOR: $MAJOR
echo MINOR: $MINOR
echo PATCH: $PATCH
echo
echo DATE $DATE
echo YEAR $YEAR
echo MONTH $MONTH
echo DAY $DAY
echo
#--------------------------------------------------------------------------
function major () {
(($YEAR == $MAJOR)) && return
TAG="--tag=stable"
echo " 🗓️ Bumping $YEAR Yearly MAJOR ($TAG) Routine from $MAJOR..."
echo
# Cycle tokens
# https://docs.npmjs.com/about-authentication-tokens
npm config get
npm token list
npm doctor
npm audit fix $DRY $IGNORE # Audit npm packages
npm ci $DRY $IGNORE # Clean Install
npm version major $TAG $SIGN $IGNORE \
-m "🍾🎉 %s CalVer Yearly Major Release"
$PUBLISH $DRY $TAG
# Deprecate previous-year back (keeping past 12 months)
# https://github.com/semver/semver/issues/712
# https://softwareengineering.stackexchange.com/q/381763
# https://softwareengineering.stackexchange.com/q/337005
# https://gist.github.com/SHSharkar/76c44458b454d470d300ea6695e8688f
# https://docs.npmjs.com/deprecating-and-undeprecating-packages-or-package-versions
echo 'TODO: Merge deprecation branch hook YYYY.0.0-1'
# npm deprecate <pkg>[@<previous-year-version>] <message>
} # major
function minor () {
# https://stackoverflow.com/q/918886
# This is needed due to major() resetting month to 0 annually
local MINOR=$(
echo `npm pkg get version --workspaces=false` \
| tr -d \" | cut -d "." -f 2
)
(($MONTH == $MINOR)) && return
TAG="--tag=latest"
echo " 🗓️ Bumping $MONTH Monthly MINOR ($TAG) Routine from $MINOR..."
echo
npm ls
npm rebuild
npm outdated
npm update --save --include=dev $DRY $IGNORE
npm prune $DRY
npm dedupe $DRY
npm cache verify
# https://docs.npmjs.com/cli/v6/configuring-npm/package-locks
npm shrinkwrap # https://stackoverflow.com/q/50743893
git add {npm-shrinkwrap,package-lock,package}.json
git commit -m '📦 Archive Shrinkwrapped Packages'
npm version minor $TAG $SIGN $IGNORE \
-m "🗓️ %s CalVer Monthly Minor Release"
$PUBLISH $DRY $TAG
# Create Github Release
# - https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
# must be signed for git describe to work without (lightweight) --tags
git archive --verbose --format=tar.gz HEAD > "$(git describe --exact-match --tags).tar.gz"
# git add 'v*.tar.gz'
# https://github.com/marketplace/actions/gh-release
# https://trstringer.com/github-actions-create-release-upload-artifacts
# - https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release
echo 'TODO: hook to add artifact via API'
} # minor
function patch () {
# cut prepatch (e.g. *-0)
local -r patch=$( echo $PATCH | cut -d '-' -f 1 )
TAG="--tag=nightly"
echo " 🗓️ Bumping $DAY Nightly Patch ($TAG) Routine from $patch ($PATCH)..."
echo
npm version prerelease $TAG $SIGN $IGNORE \
-m "🌜 %s CalVer Nightly Patch Release"
$PUBLISH $DRY $TAG
} # patch
#--------------------------------------------------------------------------
patch
# major
# minor
npm version
#--------------------------------------------------------------------------
echo " 🐙 Updating branch on Github."↴
git push
echo
echo " 🔖 Updating tags on Github."↴
git push --tags
echo
echo OLD VERSION: $VERSION
echo NEW VERSION: $(npm pkg get version | tr -d \") TAG: $TAG