mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
update dependencies (#220)
This commit is contained in:
parent
1512adeca4
commit
a3a8a38571
4 changed files with 199 additions and 264 deletions
|
@ -1,9 +1,18 @@
|
|||
#!/bin/bash
|
||||
# requires following packages:
|
||||
# - git; I believe it's already installed.
|
||||
# - git; I believe you have already installed.
|
||||
# - sed; GNU sed is preferred. POSIX sed may not work.
|
||||
# - perl; Already installed on most of unix system.
|
||||
set -eu
|
||||
|
||||
BASE_BRANCH="develop"
|
||||
|
||||
PACKAGE_NAME="ssh-key-action"
|
||||
URL_PRODUCT="https://github.com/shimataro/${PACKAGE_NAME}"
|
||||
URL_REPOSITORY="${URL_PRODUCT}.git"
|
||||
URL_COMPARE="${URL_PRODUCT}/compare"
|
||||
URL_RELEASE="${URL_PRODUCT}/releases/new"
|
||||
|
||||
COLOR_ERROR="\e[1;41m"
|
||||
COLOR_SECTION="\e[1;34m"
|
||||
COLOR_COMMAND_NAME="\e[1;34m"
|
||||
|
@ -16,34 +25,39 @@ COLOR_SELECT="\e[1;32m"
|
|||
COLOR_RESET="\e[m"
|
||||
|
||||
function main() {
|
||||
cd $(dirname ${0})/..
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
cd $(dirname ${0})/..
|
||||
|
||||
local VERSION=$1
|
||||
check_version_format ${VERSION}
|
||||
local BRANCH="release/v${VERSION}"
|
||||
local TAG="v${VERSION}"
|
||||
|
||||
check_version_format ${VERSION}
|
||||
check_current_branch
|
||||
|
||||
create_branch ${BRANCH}
|
||||
update_changelog ${VERSION}
|
||||
update_package_version ${VERSION}
|
||||
update_dependencies_version
|
||||
regenerate_package_lock
|
||||
build_package
|
||||
commit_changes ${VERSION}
|
||||
finish ${VERSION} ${BRANCH} ${TAG}
|
||||
}
|
||||
|
||||
function usage() {
|
||||
local COMMAND=`basename ${0}`
|
||||
|
||||
echo -e "${COLOR_SECTION}NAME${COLOR_RESET}
|
||||
${COMMAND} - Prepare for new release
|
||||
${COMMAND} - Create a branch and prepare for new release
|
||||
|
||||
${COLOR_SECTION}SYNOPSIS${COLOR_RESET}
|
||||
${COLOR_COMMAND_NAME}${COMMAND}${COLOR_RESET} <${COLOR_OPTION}new-version${COLOR_RESET}>
|
||||
|
||||
${COLOR_SECTION}DESCRIPTION${COLOR_RESET}
|
||||
This command:
|
||||
- creates a new branch for release
|
||||
- updates ${COLOR_FILE}CHANGELOG.md${COLOR_RESET}
|
||||
- updates package version in ${COLOR_FILE}package.json${COLOR_RESET}
|
||||
- updates dependencies version in ${COLOR_FILE}package.json${COLOR_RESET}
|
||||
|
@ -65,6 +79,24 @@ function check_version_format() {
|
|||
exit 2
|
||||
}
|
||||
|
||||
function check_current_branch() {
|
||||
local CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
|
||||
if [ ${CURRENT_BRANCH} = ${BASE_BRANCH} ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
echo -e "${COLOR_ERROR}ERROR:${COLOR_RESET} Work on ${COLOR_BRANCH}${BASE_BRANCH}${COLOR_RESET} branch
|
||||
${COLOR_COMMAND}git checkout ${BASE_BRANCH}${COLOR_RESET}
|
||||
" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
function create_branch() {
|
||||
local BRANCH=$1
|
||||
|
||||
git checkout -b ${BRANCH} ${BASE_BRANCH}
|
||||
}
|
||||
|
||||
function update_changelog() {
|
||||
local VERSION=$1
|
||||
local DATE=`date "+%Y-%m-%d"`
|
||||
|
@ -79,20 +111,8 @@ function update_changelog() {
|
|||
function update_package_version() {
|
||||
local VERSION=$1
|
||||
|
||||
sed -i".bak" -r \
|
||||
-e "s/(\"version\"\s*:\s*)\".*?\"/\1\"${VERSION}\"/" \
|
||||
package.json
|
||||
}
|
||||
|
||||
function update_dependencies_version() {
|
||||
npm ci
|
||||
npm run check-updates -- -u
|
||||
}
|
||||
|
||||
function regenerate_package_lock() {
|
||||
rm -rf package-lock.json node_modules
|
||||
npm install
|
||||
npm dedupe
|
||||
# update package.json
|
||||
npm version --no-git-tag-version ${VERSION}
|
||||
}
|
||||
|
||||
function build_package() {
|
||||
|
@ -103,10 +123,46 @@ function build_package() {
|
|||
function commit_changes() {
|
||||
local VERSION=$1
|
||||
|
||||
rm -rf node_modules
|
||||
npm ci --only=production
|
||||
git add CHANGELOG.md package.json package-lock.json lib
|
||||
git add .
|
||||
git commit -m "version ${VERSION}"
|
||||
}
|
||||
|
||||
function finish() {
|
||||
local VERSION=$1
|
||||
local BRANCH=$2
|
||||
local TAG=$3
|
||||
local TARGET_BRANCH="v${VERSION%%[!0-9]*}"
|
||||
local UPSTREAM="origin"
|
||||
local CHANGELOG=$(git diff ${UPSTREAM}/${TARGET_BRANCH} ${BRANCH} CHANGELOG.md | sed -e "/^[^+]/d" -e "s/^\+\(.*\)$/\1/" -e "/^## /d" -e "/^\+/d" -e "/^\[/d" -e "s/\s/%20/g" -e "s/#/%23/g" -e 's/\n//g' | perl -pe "s/\n/%0A/g" | perl -pe "s/^(%0A)+//" | perl -pe "s/(%0A)+$//")
|
||||
|
||||
echo -e "
|
||||
Branch ${COLOR_BRANCH}${BRANCH}${COLOR_RESET} has been created.
|
||||
Remaining processes are...
|
||||
|
||||
1. Make sure all changes are correct
|
||||
${COLOR_COMMAND}git diff ${BASE_BRANCH} ${BRANCH}${COLOR_RESET}
|
||||
2. Push to remote ${UPSTREAM}
|
||||
${COLOR_COMMAND}git push --set-upstream ${UPSTREAM} ${BRANCH}${COLOR_RESET}
|
||||
3. Create a pull-request: ${COLOR_BRANCH}${BRANCH}${COLOR_RESET} to ${COLOR_BRANCH}${BASE_BRANCH}${COLOR_RESET}
|
||||
${URL_COMPARE}/${BASE_BRANCH}...${BRANCH}?expand=1
|
||||
select ${COLOR_SELECT}Squash and merge${COLOR_RESET}
|
||||
4. Create a pull-request: ${COLOR_BRANCH}${BASE_BRANCH}${COLOR_RESET} to ${COLOR_BRANCH}${TARGET_BRANCH}${COLOR_RESET}
|
||||
${URL_COMPARE}/${TARGET_BRANCH}...${BASE_BRANCH}?expand=1&title=version%20${VERSION}&body=${CHANGELOG}
|
||||
select ${COLOR_SELECT}Create a merge commit${COLOR_RESET}
|
||||
5. Create a new release
|
||||
${URL_RELEASE}?tag=${TAG}&target=${TARGET_BRANCH}&title=${PACKAGE_NAME}%20${VERSION}%20released&body=${CHANGELOG}
|
||||
Tag version: ${COLOR_INPUT}${TAG}${COLOR_RESET}
|
||||
Target: ${COLOR_INPUT}${TARGET_BRANCH}${COLOR_RESET}
|
||||
Release title: ${COLOR_INPUT}${PACKAGE_NAME} ${VERSION} released${COLOR_RESET}
|
||||
Description this release: (copy and paste CHANGELOG.md)
|
||||
6. Post processing
|
||||
${COLOR_COMMAND}git checkout ${BASE_BRANCH}${COLOR_RESET}
|
||||
${COLOR_COMMAND}git pull${COLOR_RESET}
|
||||
${COLOR_COMMAND}git fetch -p${COLOR_RESET}
|
||||
${COLOR_COMMAND}git branch -D ${BRANCH}${COLOR_RESET}
|
||||
|
||||
That's all!
|
||||
"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue