AMR/git_development.sh

203 lines
8.9 KiB
Bash
Raw Normal View History

# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Data Analysis for R #
# #
# SOURCE #
2020-07-08 14:48:06 +02:00
# https://github.com/msberends/AMR #
# #
# LICENCE #
2020-12-27 00:30:28 +01:00
# (c) 2018-2021 Berends MS, Luz CF et al. #
2020-10-08 11:16:03 +02:00
# Developed at the University of Groningen, the Netherlands, in #
# collaboration with non-profit organisations Certe Medical #
# Diagnostics & Advice, and University Medical Center Groningen. #
# #
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# We created this package for both routine data analysis and academic #
# research and it was publicly released in the hope that it will be #
# useful, but it comes WITHOUT ANY WARRANTY OR LIABILITY. #
2020-10-08 11:16:03 +02:00
# #
# Visit our website for the full manual and a complete tutorial about #
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
2020-04-17 19:16:30 +02:00
########################################################################
# `git_development.sh` takes 3 parameters: #
2020-04-17 19:16:30 +02:00
# 1. Commit message (character) [mandatory] #
2020-07-08 14:48:06 +02:00
# 2. Lazy website generation (logical), with TRUE only changed #
2020-04-17 19:16:30 +02:00
# files will be processed [defaults to TRUE] #
# 3. Version number to be used in DESCRIPTION and NEWS.md #
# [defaults to current tag and last commit number + 9000] #
# #
# To push new commits to the development branch, run: #
# bash git_development.sh "commit message" #
2020-04-17 19:16:30 +02:00
# This creates auto version numbering in DESCRIPTION and NEWS.md. #
# #
# After successful test checks, merge it to the main branch with: #
2020-04-17 19:16:30 +02:00
# bash git_merge.sh #
# #
# To prerelease a new version number, run: #
# bash git_development.sh "v1.x.x" FALSE "1.x.x" #
2020-04-17 19:16:30 +02:00
# #
# To only update the website, run: #
# bash git_siteonly.sh #
# (which is short for 'bash git_development.sh "website update" FALSE')#
2020-04-17 19:16:30 +02:00
########################################################################
2019-05-20 14:16:53 +02:00
if [ -z "$1" ]; then
echo "FATAL - no commit message"
exit 1
fi
if [ -z "$2" ]; then
lazy="TRUE"
else
lazy=$2
fi
2019-05-20 14:16:53 +02:00
# be sure to be on development branch
git checkout development --quiet
2020-04-17 19:16:30 +02:00
2019-05-20 14:16:53 +02:00
echo "••••••••••••••••••••••••••••••••••••••••••••"
echo "• Updating package date and version number •"
echo "••••••••••••••••••••••••••••••••••••••••••••"
sed -i -- "s/^Date: .*/Date: $(date '+%Y-%m-%d')/" DESCRIPTION
2019-11-29 19:43:23 +01:00
if [ -z "$3" ]; then
# no version number set, so get latest tags to create it
git pull --tags --quiet
current_tag=`git describe --tags --abbrev=0 | sed 's/v//'`
2020-03-08 11:18:59 +01:00
if [ -z "current_tag" ]; then
echo "FATAL - could not determine current tag"
exit 1
fi
2020-04-30 18:46:29 +02:00
current_tag_full=`git describe --tags | sed 's/v//'`
current_tag_dashes=`echo $current_tag_full | grep -o "[-]" | wc -l`
if (( "$current_tag_dashes" < 1 )); then
# so version number is like "1.0.0", commit nr is 0
current_commit=0
echo "---------------"
echo "Mind NEWS.md! Assuming sequence number 9000."
echo "---------------"
else
2020-04-30 18:46:29 +02:00
current_commit=`git describe --tags | sed 's/.*-\(.*\)-.*/\1/'`
fi
2020-03-08 11:18:59 +01:00
if [ -z "current_commit" ]; then
echo "FATAL - could not determine last commit index number"
exit 1
fi
2019-11-29 19:43:23 +01:00
# combine tag (e.g. 0.1.0) and commit number (like 40) increased by 9000 to indicate beta version
new_version="$current_tag.$((current_commit + 9000))" # results in 0.1.0.9040
# add date to 2nd line of NEWS.md when no version number was set
sed -i -- "2s/.*/## \<small\>Last updated: $(date '+%e %B %Y')\<\/small\>/" NEWS.md
2019-11-29 19:43:23 +01:00
else
2020-04-17 19:16:30 +02:00
# version number set in command
2019-11-29 19:43:23 +01:00
new_version=$3
# rmove 2nd line of NEWS.md (the last changed date)
sed -i -- "2s/.*//" NEWS.md
echo "Run devtools::release() or devtools::submit_cran() after this script. Non-interactive mode will not work."
2019-06-03 20:52:24 +02:00
fi
2019-11-29 19:43:23 +01:00
# set version number to DESCRIPTION and NEWS files
2019-05-28 16:50:40 +02:00
sed -i -- "s/^Version: .*/Version: ${new_version}/" DESCRIPTION
sed -i -- "1s/.*/# \`AMR\` ${new_version}/" NEWS.md
2019-07-30 19:20:13 +02:00
rm *-- || true
echo "• First 3 lines of DESCRIPTION:"
2019-05-20 14:16:53 +02:00
head -3 DESCRIPTION
echo
2019-09-01 13:16:57 +02:00
echo "• First 2 lines of NEWS.md:"
head -2 NEWS.md
2019-06-01 21:28:18 +02:00
echo
echo "R library location:" $(Rscript -e "cat(.libPaths()[1])")
2019-05-20 14:16:53 +02:00
echo "•••••••••••••••••••••••••••••••••"
2019-06-01 20:40:49 +02:00
echo "• Reloading/documenting package •"
2019-05-20 14:16:53 +02:00
echo "•••••••••••••••••••••••••••••••••"
Rscript -e "devtools::load_all(quiet = TRUE)"
echo "• Documenting..."
2019-05-20 14:16:53 +02:00
Rscript -e "suppressMessages(devtools::document())"
2019-05-20 14:16:53 +02:00
echo
2019-06-01 20:40:49 +02:00
echo "••••••••••••••••••••••••••"
echo "• Updating internal data •"
echo "••••••••••••••••••••••••••"
Rscript -e "source('data-raw/_internals.R')"
2019-06-01 20:40:49 +02:00
echo
2020-12-29 21:23:01 +01:00
echo "••••••••••••••••••••"
echo "• Building package •"
echo "••••••••••••••••••••"
2021-02-18 23:23:14 +01:00
echo "• Building 'data-raw/AMR_latest.tar.gz'..."
2021-10-03 13:50:52 +02:00
Rscript -e "x <- devtools::build(path = 'data-raw', vignettes = TRUE, manual = FALSE, binary = FALSE, quiet = TRUE)"
2021-04-12 14:24:40 +02:00
rm data-raw/AMR_latest.tar.gz
2021-03-15 07:23:21 +01:00
mv data-raw/AMR_*.tar.gz data-raw/AMR_latest.tar.gz
# echo "• Installing..."
# Rscript -e "devtools::install(quiet = TRUE, dependencies = FALSE)"
2020-12-29 21:23:01 +01:00
echo
2019-05-20 14:16:53 +02:00
echo "•••••••••••••••••"
echo "• Building site •"
echo "•••••••••••••••••"
2021-08-18 23:19:38 +02:00
if [ $lazy == "FALSE" ]; then
Rscript -e "devtools::install(quiet = TRUE, dependencies = FALSE)"
Rscript -e "suppressMessages(pkgdown::build_site(lazy = FALSE, examples = FALSE, install = FALSE))"
else
if ! git diff --quiet man; then
# documentation has changed
Rscript -e "pkgdown::build_reference(lazy = $lazy, examples = FALSE)"
fi
if ! git diff --quiet index.md; then
# home page has changed
Rscript -e "pkgdown::build_home()"
fi
if ! git diff --quiet NEWS.md; then
# news has changed
2021-08-18 23:19:38 +02:00
Rscript -e "pkgdown::build_news()"
fi
if ! git diff --quiet pkgdown; then
# something has changed in pkgdown files
Rscript -e "suppressMessages(pkgdown::build_site(lazy = $lazy, examples = FALSE, install = TRUE))"
fi
if ! git diff --quiet vignettes; then
# a vignette has changed
Rscript -e "devtools::install(quiet = TRUE, dependencies = FALSE)"
Rscript -e "pkgdown::build_articles(lazy = $lazy)"
fi
fi
2021-05-16 09:25:36 +02:00
# always rebuild datasets vignette
Rscript -e "pkgdown::build_article('datasets', lazy = FALSE, quiet = TRUE)"
2020-12-29 21:23:01 +01:00
# add the survey page
2020-07-28 18:39:57 +02:00
Rscript -e "source('data-raw/create_survey_page.R')"
2019-05-20 14:16:53 +02:00
echo
echo "•••••••••••••••••••••••••"
echo "• List of changed files •"
echo "•••••••••••••••••••••••••"
2020-03-08 11:18:59 +01:00
git add .
2019-05-20 14:16:53 +02:00
git status --short
2019-05-20 14:16:53 +02:00
echo
read -p "Uploading v${new_version} '$1'. Continue (Y/n)? " choice
2019-05-20 14:16:53 +02:00
case "$choice" in
n|N ) exit 1;;
* ) ;;
esac
echo
echo "•••••••••••••••••••••••••••"
echo "• Uploading to repository •"
echo "•••••••••••••••••••••••••••"
2020-07-08 14:48:06 +02:00
# save latest changes as well
git add .
# and commit
2020-12-29 21:23:01 +01:00
git commit -a -m "(v${new_version}) $1" --quiet
2019-05-20 14:16:53 +02:00
git push --quiet
echo "Comparison:"
echo "https://github.com/msberends/AMR/compare/main...development?view=inline"
2019-06-22 21:33:13 +02:00
echo
echo "•••••••••"
echo "• Done •"
echo "••••••••"
echo