From f73374cf4ed67aa1e9bbc7364da63eb401241c32 Mon Sep 17 00:00:00 2001 From: "Shih-Ting, Yuan" Date: Sat, 30 Dec 2023 12:23:21 +0000 Subject: [PATCH] remoive .sh test --- tools/init.sh | 115 ----------------------- tools/release.sh | 231 ----------------------------------------------- tools/test.sh | 90 ------------------ 3 files changed, 436 deletions(-) delete mode 100755 tools/init.sh delete mode 100755 tools/release.sh delete mode 100755 tools/test.sh diff --git a/tools/init.sh b/tools/init.sh deleted file mode 100755 index 33b5209a044..00000000000 --- a/tools/init.sh +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env bash -# -# Init the evrionment for new user. - -set -eu - -ACTIONS_WORKFLOW=pages-deploy.yml - -TEMP_SUFFIX="to-delete" # temporary file suffixes that make `sed -i` compatible with BSD and Linux - -help() { - echo "Usage:" - echo - echo " bash /path/to/init.sh [options]" - echo - echo "Options:" - echo " --no-gh Do not deploy to Github." - echo " -h, --help Print this help information." -} - -check_status() { - if [[ -n $(git status . -s) ]]; then - echo "Error: Commit unstaged files first, and then run this tool againt." - exit -1 - fi -} - -check_init() { - local _has_inited=false - - if [[ ! -d .github ]]; then # using option `--no-gh` - _has_inited=true - else - if [[ -f .github/workflows/$ACTIONS_WORKFLOW ]]; then - # on BSD, the `wc` could contains blank - local _count="$(find .github/workflows/ -type f -name "*.yml" | wc -l)" - if [[ ${_count//[[:blank:]]/} == 1 ]]; then - _has_inited=true - fi - fi - fi - - if $_has_inited; then - echo "Already initialized." - exit 0 - fi -} - -init_files() { - if $_no_gh; then - rm -rf .github - else - ## Change the files of `.github` - - mv .github/workflows/$ACTIONS_WORKFLOW.hook . - rm -rf .github - mkdir -p .github/workflows - mv ./${ACTIONS_WORKFLOW}.hook .github/workflows/${ACTIONS_WORKFLOW} - - ## Ensure the gh-actions trigger branch - - _workflow=".github/workflows/${ACTIONS_WORKFLOW}" - _default_branch="$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')" - _lineno="$(sed -n "/branches:/=" "$_workflow")" - - sed -i.$TEMP_SUFFIX "$((_lineno + 1))s/- .*/- ${_default_branch}/" "$_workflow" - rm -f "$_workflow.$TEMP_SUFFIX" - - ## Cleanup image settings in site config - sed -i.$TEMP_SUFFIX "s/^img_cdn:.*/img_cdn:/;s/^avatar:.*/avatar:/" _config.yml - rm -f _config.yml.$TEMP_SUFFIX - - fi - - # trace the gem lockfile on user-end - sed -i.$TEMP_SUFFIX "/Gemfile.lock/d" .gitignore - rm -f ".gitignore.$TEMP_SUFFIX" - - # remove the other fies - rm -f .travis.yml - rm -rf _posts/* - - # save changes - git add -A - git commit -m "[Automation] Initialize the environment." -q - - echo "[INFO] Initialization successful!" -} - -check_status - -check_init - -_no_gh=false - -while (($#)); do - opt="$1" - case $opt in - --no-gh) - _no_gh=true - shift - ;; - -h | --help) - help - exit 0 - ;; - *) - # unknown option - help - exit 1 - ;; - esac -done - -init_files diff --git a/tools/release.sh b/tools/release.sh deleted file mode 100755 index b9cdfbcb1ed..00000000000 --- a/tools/release.sh +++ /dev/null @@ -1,231 +0,0 @@ -#!/usr/bin/env bash -# -# Release a new version to the GitLab flow production branch. -# -# For a new major/minor version, bump version on the main branch, and then merge into the production branch. -# -# For a patch version, bump the version number on the patch branch, then merge that branch into the main branch -# and production branch. -# -# -# Usage: run on main branch or the patch branch -# -# Requires: Git, NPM and RubyGems - -set -eu - -opt_pre=false # preview mode option -opt_skip_ver=false # option for skip versioning - -working_branch="$(git branch --show-current)" - -STAGING_BRANCH="$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')" - -PROD_BRANCH="production" - -GEM_SPEC="jekyll-theme-chirpy.gemspec" - -NODE_CONFIG="package.json" - -FILES=( - "_sass/jekyll-theme-chirpy.scss" - "_javascript/copyright" - "$GEM_SPEC" - "$NODE_CONFIG" -) - -TOOLS=( - "git" - "npm" - "standard-version" - "gem" -) - -help() { - echo "A tool to release new version Chirpy gem" - echo - echo "Usage:" - echo - echo " bash ./tools/release.sh [options]" - echo - echo "Options:" - echo " -k, --skip-versioning Skip the step of generating the version number." - echo " -p, --preview Enable preview mode, only package, and will not modify the branches" - echo " -h, --help Print this information." -} - -_check_git() { - # ensure nothing is uncommitted - if [[ -n $(git status . -s) ]]; then - echo "Abort: Commit the staged files first, and then run this tool again." - exit 1 - fi - - # ensure the working branch is the main/patch branch - if [[ $working_branch != "$STAGING_BRANCH" && $working_branch != hotfix/* ]]; then - echo "Abort: Please run on the main branch or patch branches." - exit 1 - fi -} - -_check_src() { - if [[ ! -f $1 && ! -d $1 ]]; then - echo -e "Error: Missing file \"$1\"!\n" - exit 1 - fi -} - -_check_command() { - if ! command -v "$1" &>/dev/null; then - echo "Command '$1' not found" - exit 1 - fi -} - -_check_node_packages() { - if [[ ! -d node_modules || "$(du node_modules | awk '{print $1}')" == "0" ]]; then - npm i - fi -} - -check() { - _check_git - - for i in "${!FILES[@]}"; do - _check_src "${FILES[$i]}" - done - - for i in "${!TOOLS[@]}"; do - _check_command "${TOOLS[$i]}" - done - - _check_node_packages -} - -_bump_file() { - for i in "${!FILES[@]}"; do - if [[ ${FILES[$i]} == $NODE_CONFIG ]]; then - continue - fi - - sed -i "s/v[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/v$1/" "${FILES[$i]}" - done - - npx gulp -} - -_bump_gemspec() { - sed -i "s/[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/$1/" "$GEM_SPEC" -} - -# 1. Bump latest version number to the following files: -# -# - _sass/jekyll-theme-chirpy.scss -# - _javascript/copyright -# - assets/js/dist/*.js (will be built by gulp later) -# - jekyll-theme-chirpy.gemspec -# -# 2. Create a commit to save the changes. -bump() { - _bump_file "$1" - _bump_gemspec "$1" - - if [[ $opt_pre = false && -n $(git status . -s) ]]; then - git add . - git commit -m "chore(release): $1" - fi -} - -## Remove unnecessary theme settings -cleanup_config() { - cp _config.yml _config.yml.bak - sed -i "s/^img_cdn:.*/img_cdn:/;s/^avatar:.*/avatar:/" _config.yml -} - -resume_config() { - mv _config.yml.bak _config.yml -} - -# build a gem package -build_gem() { - echo -e "Build the gem package for v$_version\n" - cleanup_config - rm -f ./*.gem - gem build "$GEM_SPEC" - resume_config -} - -# Update the git branch graph, tag, and then build the gem package. -release() { - _version="$1" # X.Y.Z - - # Create a new tag on working branch - echo -e "Create tag v$_version\n" - git tag "v$_version" - - git checkout "$PROD_BRANCH" - git merge --no-ff --no-edit "$working_branch" - - # merge from patch branch to the staging branch - # NOTE: This may break due to merge conflicts, so it may need to be resolved manually. - if [[ $working_branch == hotfix/* ]]; then - git checkout "$STAGING_BRANCH" - git merge --no-ff --no-edit "$working_branch" - git branch -D "$working_branch" - fi -} - -main() { - if [[ $opt_skip_ver = false ]]; then - check - - # auto-generate a new version number to the file 'package.json' - if $opt_pre; then - standard-version --prerelease rc - else - standard-version - fi - fi - - # Change heading of Patch version to level 2 (a bug from `standard-version`) - sed -i "s/^### \[/## \[/g" CHANGELOG.md - - _version="$(grep '"version":' "$NODE_CONFIG" | sed 's/.*: "//;s/".*//')" - - echo -e "Bump version number to $_version\n" - bump "$_version" - - build_gem - - if [[ $opt_pre = true ]]; then - # Undo all changes on Git - git reset --hard && git clean -fd - else - release "$_version" - fi -} - -while (($#)); do - opt="$1" - case $opt in - -p | --preview) - opt_pre=true - shift - ;; - -k | --skip-versioning) - opt_skip_ver=true - shift - ;; - -h | --help) - help - exit 0 - ;; - *) - # unknown option - help - exit 1 - ;; - esac -done - -main diff --git a/tools/test.sh b/tools/test.sh deleted file mode 100755 index 0210387c323..00000000000 --- a/tools/test.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env bash -# -# Build and test the site content -# -# Requirement: html-proofer, jekyll -# -# Usage: See help information - -set -eu - -SITE_DIR="_site" - -_config="_config.yml" - -_baseurl="" - -help() { - echo "Build and test the site content" - echo - echo "Usage:" - echo - echo " bash ./tools/test.sh [options]" - echo - echo "Options:" - echo ' -c, --config "" Specify config file(s)' - echo " -h, --help Print this information." -} - -read_baseurl() { - if [[ $_config == *","* ]]; then - # multiple config - IFS="," - read -ra config_array <<<"$_config" - - # reverse loop the config files - for ((i = ${#config_array[@]} - 1; i >= 0; i--)); do - _tmp_baseurl="$(grep '^baseurl:' "${config_array[i]}" | sed "s/.*: *//;s/['\"]//g;s/#.*//")" - - if [[ -n $_tmp_baseurl ]]; then - _baseurl="$_tmp_baseurl" - break - fi - done - - else - # single config - _baseurl="$(grep '^baseurl:' "$_config" | sed "s/.*: *//;s/['\"]//g;s/#.*//")" - fi -} - -main() { - # clean up - if [[ -d $SITE_DIR ]]; then - rm -rf "$SITE_DIR" - fi - - read_baseurl - - # build - JEKYLL_ENV=production bundle exec jekyll b \ - -d "$SITE_DIR$_baseurl" -c "$_config" --trace - - # test - bundle exec htmlproofer "$SITE_DIR" \ - --disable-external \ - --check-html \ - --allow_hash_href -} - -while (($#)); do - opt="$1" - case $opt in - -c | --config) - _config="$2" - shift - shift - ;; - -h | --help) - help - exit 0 - ;; - *) - # unknown option - help - exit 1 - ;; - esac -done - -main