diff --git a/.github/release-auto-flag.txt b/.github/tag_and_release/release-auto-flag.txt similarity index 100% rename from .github/release-auto-flag.txt rename to .github/tag_and_release/release-auto-flag.txt diff --git a/.github/release-notes.md b/.github/tag_and_release/release-notes.md similarity index 100% rename from .github/release-notes.md rename to .github/tag_and_release/release-notes.md diff --git a/.github/release-title.md b/.github/tag_and_release/release-title.md similarity index 100% rename from .github/release-title.md rename to .github/tag_and_release/release-title.md diff --git a/scripts/ci/build_git-tag_or_create_github-release.sh b/scripts/ci/build_git-tag_or_create_github-release.sh index f076c309..88805a0d 100644 --- a/scripts/ci/build_git-tag_or_create_github-release.sh +++ b/scripts/ci/build_git-tag_or_create_github-release.sh @@ -2,27 +2,33 @@ #set -ex +# The file paths for auto-tag (git tag) and auto-release (GitHub release info) +Auto_Tag_And_Release_Dir=.github/tag_and_release +Auto_Tag_And_Release_Flag=release-auto-flag.txt +Auto_Release_Title=release-title.md +Auto_Release_Content=release-notes.md + # Check whether it has 'release-notes.md' or 'release-title.md' in the target directory '.github'. -has_auto_release_flag=$(ls .github | grep -E "release-auto-flag.txt") +has_auto_release_flag=$(ls "$Auto_Tag_And_Release_Dir" | grep -E "$Auto_Tag_And_Release_Flag") if [ "$has_auto_release_flag" == "" ]; then - echo "⚠️ It should have *release-auto-flag.txt* in '.github' directory of your project in HitHub." + echo "⚠️ It should have *$Auto_Tag_And_Release_Flag* in '$Auto_Tag_And_Release_Dir/' directory of your project in HitHub." exit 0 else - auto_release_flag=$(cat .github/release-auto-flag.txt) + auto_release_flag=$(cat "$Auto_Tag_And_Release_Dir"/$Auto_Tag_And_Release_Flag) if [ "$auto_release_flag" == false ]; then echo "💤 Auto-release flag is 'false' so it won't build git tag or create GitHub release." exit 0 fi fi -has_release_notes=$(ls .github | grep -E "release-notes.md") -has_release_title=$(ls .github | grep -E "release-title.md") +has_release_notes=$(ls "$Auto_Tag_And_Release_Dir" | grep -E "$Auto_Release_Content") +has_release_title=$(ls "$Auto_Tag_And_Release_Dir" | grep -E "$Auto_Release_Title") if [ "$has_release_notes" == "" ]; then - echo "❌ It should have *release-notes.md* in '.github' directory of your project in HitHub." + echo "❌ It should have *$Auto_Release_Content* in '$Auto_Tag_And_Release_Dir/' directory of your project in HitHub." exit 1 fi if [ "$has_release_title" == "" ]; then - echo "❌ It should have *release-title.md* in '.github' directory of your project in HitHub." + echo "❌ It should have *$Auto_Release_Title* in '$Auto_Tag_And_Release_Dir/' directory of your project in HitHub." exit 1 fi @@ -31,6 +37,8 @@ fi Input_Arg_Release_Type=$1 Input_Arg_Debug_Mode=$2 +keep_release=(echo "$KEEP_RELEASE_IF_PRE_VERSION") + if [ "$Input_Arg_Release_Type" == "" ]; then echo "❌ The argument 'Input_Arg_Release_Type' (first argument) cannot be empty." exit 1 @@ -182,9 +190,18 @@ build_git_tag_or_github_release() { # git event: push # all branch -> Build tag # master branch -> Build tag and create release - project_type=$1 generate_new_version_as_tag "$project_type" + build_git_tag + build_github_release +} + + +build_git_tag() { + # git event: push + # all branch -> Build tag + # master branch -> Build tag and create release + ensure_release_tag_is_not_empty if [ "$Input_Arg_Debug_Mode" == true ]; then echo " 🔍👀 [DEBUG MODE] Build git tag $New_Release_Tag in git branch '$Current_Branch'." @@ -193,26 +210,39 @@ build_git_tag_or_github_release() { git push -u origin --tags fi echo "🎉 🍻 🌳 🏷 Build git tag which named '$New_Release_Tag' with current branch '$Current_Branch' successfully!" +} + + +build_github_release() { + # git event: push + # all branch -> Build tag + # master branch -> Build tag and create release + ensure_release_tag_is_not_empty if [ "$Current_Branch" == "master" ]; then - release_title=$(cat .github/release-title.md) + release_title=$(cat "$Auto_Tag_And_Release_Dir"/$Auto_Release_Title) if [ "$Input_Arg_Debug_Mode" == true ]; then echo " 🔍👀 [DEBUG MODE] Create GitHub release with tag '$New_Release_Tag' and title '$release_title' in git branch '$Current_Branch'." else - gh release create "$New_Release_Tag" --title "$release_title" --notes-file .github/release-notes.md + gh release create "$New_Release_Tag" --title "$release_title" --notes-file "$Auto_Tag_And_Release_Dir"/$Auto_Release_Content fi fi echo "🎉 🍻 🐙 🐈 🏷 Create GitHub release with title '$release_title' successfully!" } -# The truly running implementation of shell script -if [ "$Input_Arg_Release_Type" == 'python-package' ]; then +ensure_release_tag_is_not_empty() { + if [ "$New_Release_Tag" == "" ]; then + echo "❌ The new release tag it got is empty. Please check version info in your repository." + exit 1 + else + echo "✅ It gets new version info and it's *$New_Release_Tag*. It would keep running to set it." + fi +} - # # # # For Python package release - echo "🏃‍♂ ️🐍 𝌚 Run python package releasing process" +tag_and_release_python_project() { git_tag=$(git describe --tag --abbrev=0 --match "v[0-9]\.[0-9]\.[0-9]*" | grep -o '[0-9]\.[0-9]\.[0-9]*') github_release=$(curl -s https://api.github.com/repos/Chisanan232/GitHub-Action_Reusable_Workflows-Python/releases/latest | jq -r '.tag_name') # shellcheck disable=SC2002 @@ -273,10 +303,10 @@ if [ "$Input_Arg_Release_Type" == 'python-package' ]; then fi fi +} -elif [ "$Input_Arg_Release_Type" == 'github-action-reusable-workflow' ]; then - echo "🏃‍♂ 🐙 🐈 𝌚 Run github-action-reusable-workflow releasing process" +tag_and_release_reusable_github_action_workflows_project() { # # # # For GitHub Action reusable workflow template release # 1. Compare whether the release-notes.md has different or not. # Note 1: Diff a specific file with currently latest tag and previous one commit @@ -296,9 +326,9 @@ elif [ "$Input_Arg_Release_Type" == 'github-action-reusable-workflow' ]; then echo "🔎 🔗 🌳 Verify the git remote info again after git fetch." git remote -v - echo "🔬 📄 🌳 ⛓ 🌳 Check the different of '.github/release-notes.md' between current git branch and master branch ..." + echo "🔬 📄 🌳 ⛓ 🌳 Check the different of '$Auto_Tag_And_Release_Dir/$Auto_Release_Content' between current git branch and master branch ..." # # v1: compare by git branches -# release_notes_has_diff=$(git diff origin/master "$Current_Branch" -- .github/release-notes.md | cat) +# release_notes_has_diff=$(git diff origin/master "$Current_Branch" -- "$Auto_Tag_And_Release_Dir"/$Auto_Release_Content | cat) # # v2: compare by git tag all_git_tags=$(git tag -l | cat) declare -a all_git_tags_array=( $(echo "$all_git_tags" | awk -v RS='' '{gsub("\n"," "); print}') ) @@ -306,8 +336,8 @@ elif [ "$Input_Arg_Release_Type" == 'github-action-reusable-workflow' ]; then latest_git_tag=${all_git_tags_array[$all_git_tags_array_len - 1]} echo "🔎 🌳 🏷 The latest git tag: $latest_git_tag" - release_notes_has_diff=$(git diff "$latest_git_tag" "$Current_Branch" -- .github/release-notes.md | cat) - echo "🔎 🔬 📄 different of '.github/release-notes.md': $release_notes_has_diff" + release_notes_has_diff=$(git diff "$latest_git_tag" "$Current_Branch" -- "$Auto_Tag_And_Release_Dir"/$Auto_Release_Content | cat) + echo "🔎 🔬 📄 different of '$Auto_Tag_And_Release_Dir/$Auto_Release_Content': $release_notes_has_diff" if [ "$release_notes_has_diff" != "" ]; then # 1. Yes, it has different. -> Build git tag, GitHub release and version branch @@ -320,5 +350,15 @@ elif [ "$Input_Arg_Release_Type" == 'github-action-reusable-workflow' ]; then echo "💤 Release note file doesn't change. Don't do anything." echo "[GitHub Action - Reusable workflow] [Final Running Result] Pre-Release" fi +} + +# The truly running implementation of shell script +if [ "$Input_Arg_Release_Type" == 'python-package' ]; then + # # # # For Python package release + echo "🏃‍♂ ️🐍 𝌚 Run python package releasing process" + tag_and_release_python_project +elif [ "$Input_Arg_Release_Type" == 'github-action-reusable-workflow' ]; then + echo "🏃‍♂ 🐙 🐈 𝌚 Run github-action-reusable-workflow releasing process" + tag_and_release_reusable_github_action_workflows_project fi