From 0c46ed75e8bb4479e87ecc1f99cdc8a9c04f38bf Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Mon, 20 Jan 2025 10:53:17 +0900 Subject: [PATCH] Updated nodejs_helper for forked repositories --- .github/workflows/ci.yml | 2 ++ .github/workflows/nodejs_helper.sh | 43 ++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c759ff..bcc3402 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,6 +74,7 @@ jobs: # NODEJS_TYPE_VARS_FILE : specify custom variables file # * NPM_TOKEN : The token for publishing to npm # FORCE_PUBLISHER : nodejs major version to publish packages + # FORCE_NOT_PUBLISHER : do not allow to publish any packages(for forked repository) # USE_PACKAGECLOUD_REPO : true means using pacakgecloud.io repo, false is not using # PACKAGECLOUD_OWNER : owner name as a pat of path to packagcloud.io for downloading # PACKAGECLOUD_DOWNLOAD_REPO : repo name as a pat of path to packagcloud.io for downloading @@ -85,6 +86,7 @@ jobs: echo "ENV_NODEJS_TYPE_VARS_FILE=${{ secrets.NODEJS_TYPE_VARS_FILE }}" >> "${GITHUB_ENV}" echo "ENV_NPM_TOKEN=${{ secrets.NPM_TOKEN }}" >> "${GITHUB_ENV}" echo "ENV_FORCE_PUBLISHER=${{ secrets.FORCE_PUBLISHER }}" >> "${GITHUB_ENV}" + echo "ENV_FORCE_NOT_PUBLISHER=${{ secrets.FORCE_NOT_PUBLISHER }}" >> "${GITHUB_ENV}" echo "ENV_USE_PACKAGECLOUD_REPO=${{ secrets.USE_PACKAGECLOUD_REPO }}" >> "${GITHUB_ENV}" echo "ENV_PACKAGECLOUD_OWNER=${{ secrets.PACKAGECLOUD_OWNER }}" >> "${GITHUB_ENV}" echo "ENV_PACKAGECLOUD_DOWNLOAD_REPO=${{ secrets.PACKAGECLOUD_DOWNLOAD_REPO }}" >> "${GITHUB_ENV}" diff --git a/.github/workflows/nodejs_helper.sh b/.github/workflows/nodejs_helper.sh index 8309906..5993182 100755 --- a/.github/workflows/nodejs_helper.sh +++ b/.github/workflows/nodejs_helper.sh @@ -18,7 +18,7 @@ # # AUTHOR: Takeshi Nakatani # CREATE: Tue, Nov 24 2020 -# REVISION: 1.3 +# REVISION: 1.4 # #============================================================== @@ -71,6 +71,7 @@ CI_PACKAGECLOUD_OWNER="antpickax" CI_PACKAGECLOUD_DOWNLOAD_REPO="stable" CI_NPM_TOKEN="" CI_FORCE_PUBLISHER="" +CI_FORCE_NOT_PUBLISHER=0 CI_IN_SCHEDULE_PROCESS=0 CI_PUBLISH_TAG_NAME="" @@ -169,6 +170,7 @@ func_usage() echo " --nodejstype-vars-file(-f) specify the file that describes the package list to be installed before build(default is nodejstypevars.sh)" echo " --npm-token(-token) npm token for uploading(specify when uploading)" echo " --force-publisher(-fp) specify publisher node major version(ex. 10/11/12)." + echo " --force-not-publisher(-np) do not allow to publish any packages." echo "" echo " Option for packagecloud.io:" echo " --use-packagecloudio-repo(-usepc) use packagecloud.io repository(default), exclusive -notpc option" @@ -180,6 +182,7 @@ func_usage() echo " ENV_NODEJS_TYPE_VARS_FILE the file for custom variables ( same as option '--nodejstype-vars-file(-f)' )" echo " ENV_NPM_TOKEN the token for publishing to npm ( same as option '--npm-token(-token)' )" echo " ENV_FORCE_PUBLISHER nodejs major version to publish packages ( same as option '--force-publisher(-fp)' )" + echo " ENV_FORCE_NOT_PUBLISHER do not allow to publish any packages ( same as option '--force-not-publisher(-np)' )" echo " ENV_USE_PACKAGECLOUD_REPO use packagecloud.io repository: true/false ( same as option '--use-packagecloudio-repo(-usepc)' and '--not-use-packagecloudio-repo(-notpc)' )" echo " ENV_PACKAGECLOUD_OWNER owner name for uploading to packagecloud.io ( same as option '--packagecloudio-owner(-pcowner)' )" echo " ENV_PACKAGECLOUD_DOWNLOAD_REPO repository name of installing packages in packagecloud.io ( same as option '--packagecloudio-download-repo(-pcdlrepo)' )" @@ -531,6 +534,7 @@ PRNTITLE "Start to check options and environments" OPT_NODEJS_TYPE="" OPT_NODEJS_TYPE_VARS_FILE="" OPT_FORCE_PUBLISHER="" +OPT_FORCE_NOT_PUBLISHER=0 OPT_USE_PACKAGECLOUD_REPO= OPT_PACKAGECLOUD_OWNER="" OPT_PACKAGECLOUD_DOWNLOAD_REPO="" @@ -574,7 +578,7 @@ while [ $# -ne 0 ]; do elif [ "$1" = "-fp" ] || [ "$1" = "-FP" ] || [ "$1" = "--force-publisher" ] || [ "$1" = "--FORCE-PUBLISHER" ]; then if [ -n "${OPT_FORCE_PUBLISHER}" ]; then - PRNERR "already set \"--force-publisher(-fp)\" or \"--not-publish(-np)\" option." + PRNERR "already set \"--force-publisher(-fp)\" option." exit 1 fi shift @@ -588,6 +592,13 @@ while [ $# -ne 0 ]; do fi OPT_FORCE_PUBLISHER="$1" + elif [ "$1" = "-np" ] || [ "$1" = "-NP" ] || [ "$1" = "--force-not-publisher" ] || [ "$1" = "--FORCE-NOT-PUBLISHER" ]; then + if [ "${OPT_FORCE_NOT_PUBLISHER}" -ne 0 ]; then + PRNERR "already set \"--force-not-publisher(-np)\" option." + exit 1 + fi + OPT_FORCE_NOT_PUBLISHER="$1" + elif [ "$1" = "-usepc" ] || [ "$1" = "-USEPC" ] || [ "$1" = "--use-packagecloudio-repo" ] || [ "$1" = "--USE-PACKAGECLOUDIO-REPO" ]; then if [ -n "${OPT_USE_PACKAGECLOUD_REPO}" ]; then PRNERR "already set \"--use-packagecloudio-repo(-usepc)\" or \"--not-use-packagecloudio-repo(-notpc)\" option." @@ -680,6 +691,19 @@ elif [ -n "${ENV_FORCE_PUBLISHER}" ]; then CI_FORCE_PUBLISHER="${ENV_FORCE_PUBLISHER}" fi +if [ "${OPT_FORCE_NOT_PUBLISHER}" -ne 0 ]; then + CI_FORCE_NOT_PUBLISHER=1 +elif [ -n "${ENV_FORCE_NOT_PUBLISHER}" ]; then + if [ "${ENV_FORCE_NOT_PUBLISHER}" = "true" ] || [ "${ENV_FORCE_NOT_PUBLISHER}" -eq 1 ]; then + CI_FORCE_NOT_PUBLISHER=1 + fi +fi + +if [ -n "${CI_FORCE_PUBLISHER}" ] && [ "${CI_FORCE_NOT_PUBLISHER}" -ne 0 ]; then + PRNERR "\"FORCE_PUBLISHER\"(ENV or --force-publisher(-fp) option) and \"FORCE_NOT_PUBLISHER\"(ENV or --force-not-publisher(-np) option) cannot be specified together." + exit 1 +fi + if [ -n "${OPT_USE_PACKAGECLOUD_REPO}" ]; then if [ "${OPT_USE_PACKAGECLOUD_REPO}" -eq 1 ]; then CI_USE_PACKAGECLOUD_REPO=1 @@ -793,13 +817,15 @@ PRNTITLE "Check whether to execute processes" # # Check whether to publish # -if [ "${IS_PUBLISHER}" -eq 1 ] || { [ -n "${CI_FORCE_PUBLISHER}" ] && [ "${CI_FORCE_PUBLISHER}" = "${CI_NODEJS_MAJOR_VERSION}" ]; }; then - if [ -n "${CI_PUBLISH_TAG_NAME}" ]; then - if [ -z "${CI_NPM_TOKEN}" ]; then - PRNERR "Specified release tag for publish, but NPM token is not specified." - exit 1 +if [ "${CI_FORCE_NOT_PUBLISHER}" -eq 0 ]; then + if [ "${IS_PUBLISHER}" -eq 1 ] || { [ -n "${CI_FORCE_PUBLISHER}" ] && [ "${CI_FORCE_PUBLISHER}" = "${CI_NODEJS_MAJOR_VERSION}" ]; }; then + if [ -n "${CI_PUBLISH_TAG_NAME}" ]; then + if [ -z "${CI_NPM_TOKEN}" ]; then + PRNERR "Specified release tag for publish, but NPM token is not specified." + exit 1 + fi + CI_DO_PUBLISH=1 fi - CI_DO_PUBLISH=1 fi fi @@ -826,6 +852,7 @@ echo " CI_PACKAGECLOUD_OWNER = ${CI_PACKAGECLOUD_OWNER}" echo " CI_PACKAGECLOUD_DOWNLOAD_REPO = ${CI_PACKAGECLOUD_DOWNLOAD_REPO}" echo " CI_NPM_TOKEN = **********" echo " CI_FORCE_PUBLISHER = ${CI_FORCE_PUBLISHER}" +echo " CI_FORCE_NOT_PUBLISHER = ${CI_FORCE_NOT_PUBLISHER}" echo " CI_PUBLISH_TAG_NAME = ${CI_PUBLISH_TAG_NAME}" echo " CI_DO_PUBLISH = ${CI_DO_PUBLISH}" echo ""