-
Notifications
You must be signed in to change notification settings - Fork 2
/
release-publish.sh
160 lines (132 loc) · 5 KB
/
release-publish.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env bash
# TODO
#===================
# provide support for publishing locally in addition to GitHub Actions
set -u -e -o pipefail
VERBOSE=false
TRACE=false
DRY_RUN=false
# We read from a file because the list is also shared with build.sh
# Not using readarray because it does not handle \r\n
#OLD_IFS=$IFS # save old IFS value
#IFS=$'\r\n' GLOBIGNORE='*' command eval 'ALL_PACKAGES=($(cat ./modules.txt))'
#IFS=$OLD_IFS # restore IFS
PACKAGE=eslint-config
EXPECTED_REPO_SLUG="NationalBankBelgium/eslint-config"
GH_ACTIONS_TAG=${GH_ACTIONS_TAG:-""}
NPM_TOKEN=${NPM_TOKEN:-""}
#----------------------------------------------
# Uncomment block below to test locally
#----------------------------------------------
#LOGS_DIR=./.tmp/eslint-config/logs
#mkdir -p ${LOGS_DIR}
#touch ${LOGS_DIR}/build-perf.log
#NPM_TOKEN="dummy"
#GITHUB_ACTIONS=true
#GITHUB_REPOSITORY="NationalBankBelgium/eslint-config"
#GITHUB_EVENT_NAME="push"
# For normal builds:
#GITHUB_EVENT_NAME="pull_request"
#GH_ACTIONS_TAG="fooBar"
# For nightly builds:
#GITHUB_EVENT_NAME="schedule"
#----------------------------------------------
readonly currentDir=$(cd $(dirname $0); pwd)
source ${currentDir}/scripts/ci/_ghactions-group.sh
source ${currentDir}/util-functions.sh
cd ${currentDir}
logInfo "============================================="
logInfo "ESLintConfig release publish @ npm"
for ARG in "$@"; do
case "$ARG" in
--dry-run)
logInfo "============================================="
logInfo "Dry run enabled!"
DRY_RUN=true
;;
--verbose)
logInfo "============================================="
logInfo "Verbose mode enabled!"
VERBOSE=true
;;
--trace)
logInfo "============================================="
logInfo "Trace mode enabled!"
TRACE=true
;;
*)
echo "Unknown option $ARG."
exit 1
;;
esac
done
logInfo "============================================="
PROJECT_ROOT_DIR=`pwd`
logTrace "PROJECT_ROOT_DIR: ${PROJECT_ROOT_DIR}" 1
ROOT_PACKAGES_DIR=${PROJECT_ROOT_DIR}
logTrace "ROOT_PACKAGES_DIR: ${ROOT_PACKAGES_DIR}" 1
ghActionsGroupStart "publish checks" "no-xtrace"
if [[ ${GITHUB_ACTIONS} == true ]]; then
logInfo "Publishing to npm";
logInfo "============================================="
# Don't even try if not running against the official repo
# We don't want release to run outside of our own little world
if [[ ${GITHUB_REPOSITORY} != ${EXPECTED_REPO_SLUG} ]]; then
logInfo "Skipping release because this is not the main repository.";
ghActionsGroupEnd "publish checks"
exit 0;
fi
logInfo "Verifying if this build has been triggered for a tag"
if [[ ${GITHUB_EVENT_NAME} == "pull_request" ]]; then
logInfo "Not publishing because this is a build triggered for a pull request" 1
ghActionsGroupEnd "publish checks"
exit 0;
elif [[ ${GH_ACTIONS_TAG} == "" ]]; then
logInfo "Not publishing because this is not a build triggered for a tag" 1
ghActionsGroupEnd "publish checks"
exit 0;
else
logInfo "This build has been triggered for a tag"
fi
logInfo "Verifying that the NPM_TOKEN is available"
if [[ ${NPM_TOKEN} == "" ]]; then
logInfo "Not publishing because the NPM_TOKEN environment variable is is not defined correctly" 1
exit 1;
fi
# If any of the previous commands in the `steps` section of .github/workflows/build.yml failed, then abort.
# The variable is not set in early stages of the build, so we default to 0 there.
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#job-context
if [[ ${GH_ACTIONS_JOB_STATUS="failed"} == "Success" ]]; then
logInfo "Skipping release because a previous script in the GitHub Actions job has failed";
ghActionsGroupEnd "publish checks"
exit 0;
fi
fi
ghActionsGroupEnd "publish checks"
logInfo "============================================="
logInfo "Publishing package"
logInfo "============================================="
# FIXME Uncomment this once GitHub Actions support nested logs
# See: https://github.community/t5/GitHub-Actions/Feature-Request-Enhancements-to-group-commands-nested-named/m-p/45399
#ghActionsGroupStart "publish" "no-xtrace"
#logInfo "Publishing package"
ghActionsGroupStart "publishing: ${PACKAGE}" "no-xtrace"
PACKAGE_FOLDER=${ROOT_PACKAGES_DIR}/dist
logTrace "Package path: ${PACKAGE_FOLDER}" 2
cd ${PACKAGE_FOLDER}
TGZ_FILES=`find . -maxdepth 1 -type f | egrep -e ".tgz"`;
for file in ${TGZ_FILES}; do
logInfo "Publishing TGZ file: ${TGZ_FILES}" 2
if [[ ${DRY_RUN} == false ]]; then
logTrace "Publishing the release (with tag latest)" 2
npm publish ${file} --access public
else
logTrace "DRY RUN, skipping npm publish!" 2
fi
logInfo "Package published!" 2
done
cd - > /dev/null; # go back to the previous folder without any output
ghActionsGroupEnd "publishing: ${PACKAGE}"
#ghActionsGroupEnd "publish"
# Print return arrows as a log separator
ghActionsGroupReturnArrows