-
Notifications
You must be signed in to change notification settings - Fork 23
/
release-publish.sh
170 lines (144 loc) · 5.64 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
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
# TODO
#===================
# provide a clean way to define/check the "current" version of node (i.e., the one we should execute the publish under/for)
## ideally we should read it from .nvmrc
# provide support for publishing only a subset of the packages (same --packages logic as in build.sh)
# 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
EXPECTED_REPOSITORY="NationalBankBelgium/stark"
GH_ACTIONS_TAG=${GH_ACTIONS_TAG:-""}
#----------------------------------------------
# Uncomment block below to test locally
#----------------------------------------------
#LOGS_DIR=./.tmp/stark/logs
#mkdir -p ${LOGS_DIR}
#LOGS_FILE=${LOGS_DIR}/build-perf.log
#touch ${LOGS_FILE}
#GITHUB_ACTIONS=true
#GITHUB_REPOSITORY="NationalBankBelgium/stark"
# For normal builds:
#GITHUB_EVENT_NAME="pull_request"
#GITHUB_EVENT_NAME="push"
#GH_ACTIONS_TAG="fooBar"
# For nightly builds:
#GITHUB_EVENT_NAME="schedule"
#----------------------------------------------
NIGHTLY_BUILD=false
readonly currentDir=$(cd $(dirname $0); pwd)
source ${currentDir}/scripts/ci/_ghactions-group.sh
source ${currentDir}/util-functions.sh
cd ${currentDir}
logInfo "============================================="
logInfo "Stark 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
;;
--nightly)
logInfo "============================================="
logInfo "Nightly build!"
NIGHTLY_BUILD=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}/dist/packages-dist
logTrace "ROOT_PACKAGES_DIR: ${ROOT_PACKAGES_DIR}" 1
ghActionsGroupStart "publish checks" "no-xtrace"
if [[ ${GITHUB_ACTIONS} == true ]]; then
logInfo "============================================="
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_REPOSITORY} ]]; then
logInfo "Skipping release because this is not the main repository.";
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
exit 0;
elif [[ ${GITHUB_EVENT_NAME} == "schedule" || ${GH_ACTIONS_TAG} =~ .*-(alpha|beta|rc).* ]]; then
logInfo "Nightly build initiated by GitHub Actions scheduled job or pre-release tag" 1
NIGHTLY_BUILD=true
elif [[ ${GH_ACTIONS_TAG} == "" ]]; then
logInfo "Not publishing because this is not a build triggered for a tag" 1
exit 0;
else
logInfo "This build has been triggered for a tag"
fi
fi
ghActionsGroupEnd "publish checks"
logInfo "============================================="
logInfo "Publishing all packages"
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 all packages"
for PACKAGE in ${ALL_PACKAGES[@]}
do
ghActionsGroupStart "publishing: ${PACKAGE}" "no-xtrace"
PACKAGE_FOLDER=${ROOT_PACKAGES_DIR}/${PACKAGE}
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
if [[ ${NIGHTLY_BUILD} == false ]]; then
logTrace "Publishing the release (with tag latest)" 2
npm publish ${file} --access public
logTrace "Adapting the tag next to point to the new release" 2
npm dist-tag add @nationalbankbelgium/${PACKAGE}@${GH_ACTIONS_TAG} next
else
logTrace "Check if nightly build is not already published."
LATEST_NPM_VERSION=`npm view @nationalbankbelgium/${PACKAGE} dist-tags.next`
FILENAME_LATEST_NPM_PACKAGE="./nationalbankbelgium-${PACKAGE}-${LATEST_NPM_VERSION}.tgz"
if [[ ${file} != ${FILENAME_LATEST_NPM_PACKAGE} ]]; then
logTrace "Publishing the nightly release (with tag next)" 2
npm publish ${file} --access public --tag next
else
logTrace "Package cannot be published because it is already published." 2
fi
fi
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}"
done
#ghActionsGroupEnd "publish"
# Print return arrows as a log separator
ghActionsGroupReturnArrows