@@ -34,9 +34,9 @@ REPO_NAME="${REPO_SLUG#*/}"
34
34
REPO_TAG=" "
35
35
REPO_BRANCH=" "
36
36
REPO_COMMIT=" "
37
- if [[ " $GITHUB_REF " == " refs/tags/" * ]]; then
37
+ if [[ $GITHUB_REF == " refs/tags/" * ]]; then
38
38
REPO_TAG=" ${GITHUB_REF# " refs/tags/" } "
39
- elif [[ " $GITHUB_REF " == " refs/heads/" * ]]; then
39
+ elif [[ $GITHUB_REF == " refs/heads/" * ]]; then
40
40
REPO_BRANCH=" ${GITHUB_REF# " refs/heads/" } "
41
41
REPO_COMMIT=" $GITHUB_SHA "
42
42
else
52
52
# https://github.com/bevry/oneday/actions/runs/7338411137/job/19980941727
53
53
# https://github.com/bevry/typechecker/actions/runs/7349089133/job/20008437623
54
54
function npm_publish {
55
- local delay status
56
- while true ; do
57
- delay=" $(( RANDOM% 60 )) "
55
+ local delay status stderr
56
+ while true ; do
57
+ stderr=" $( mktemp) "
58
+ delay=" $(( RANDOM % 60 )) "
58
59
echo " waiting ${delay} seconds..."
59
60
sleep " $delay "
60
- status=0 && npm publish " $@ " || status=$?
61
+ status=0 && npm publish " $@ " 2> >( tee " $stderr " > /dev/stderr ) || status=$?
61
62
if test " $status " -eq 0; then
62
- echo " npm publish successful"
63
- break
64
- elif test " $status " -eq 409; then
65
- echo " npm publish failed with conflict , trying again..."
63
+ echo ' npm publish successful'
64
+ return 0
65
+ elif test " $status " -eq 409 || grep --quiet --fixed-strings --regexp= ' code E409 ' " $stderr " ; then
66
+ echo ' npm publish failed with E409 Conflict , trying again...'
66
67
continue
67
68
else
68
69
echo " npm publish failed with exit status: $status "
69
70
return " $status "
70
71
fi
71
72
done
72
- return 0
73
73
}
74
74
75
75
# =====================================
76
76
# CHECKS
77
77
78
- if [[ " $REPO_BRANCH " = * " dependabot" * ]]; then
79
- echo " skipping as running on a dependabot branch"
78
+ if [[ $REPO_BRANCH = = * " dependabot" * ]]; then
79
+ echo ' skipping as running on a dependabot branch'
80
80
exit 0
81
81
elif test -z " $NPM_AUTH_TOKEN " ; then
82
- echo " you must provide NPM_AUTH_TOKEN"
82
+ echo ' you must provide NPM_AUTH_TOKEN'
83
83
exit 1
84
84
fi
85
85
92
92
# # https://github.com/bevry/es-versions/runs/1378842251?check_suite_focus=true#step:7:39
93
93
# # https://github.com/bevry/es-versions/runs/1378917476?check_suite_focus=true#step:7:40
94
94
# # hence the need for the following login code below
95
- echo " creating npmrc with npm auth token..."
96
- echo " //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN " > " $HOME /.npmrc"
95
+ echo ' creating npmrc with npm auth token...'
96
+ echo " //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN " > " $HOME /.npmrc"
97
97
echo " logged into npm as: $( npm whoami) "
98
98
99
99
# @todo simplify this, and consider making it only run on the default branch
100
100
# check if we wish to tag the current branch
101
101
if test -n " ${NPM_BRANCH_TAG:- } " ; then
102
102
branch=" ${NPM_BRANCH_TAG%:* } "
103
- if test -z " $branch " -o " $branch " = " master" ; then
103
+ if test -z " $branch " -o " $branch " = ' master' ; then
104
104
branch=" ${GH_MASTER_BRANCH} "
105
105
fi
106
106
if test " $branch " = " $REPO_BRANCH " ; then
@@ -113,23 +113,23 @@ if test -n "${REPO_TAG-}" -o -n "${tag-}"; then
113
113
114
114
# not repo tag, is branch tag
115
115
if test -z " ${REPO_TAG-} " -a -n " ${tag-} " ; then
116
- echo " bumping the npm version..."
116
+ echo ' bumping the npm version...'
117
117
version=" $( node -e " console.log(require('./package.json').version)" ) "
118
118
time=" $( date +%s) "
119
- next=" ${version% -* } -${tag} .${time} .${REPO_SHA} " # version trims anything after -
119
+ next=" ${version% -* } -${tag} .${time} .${REPO_SHA} " # version trims anything after -
120
120
npm version " ${next} " --git-tag-version=false
121
121
echo " publishing branch ${branch} to tag ${tag} with version ${next} ..."
122
122
npm_publish --access public --tag " ${tag} "
123
123
124
124
# publish package.json
125
125
else
126
- echo " publishing the local package.json version..."
126
+ echo ' publishing the local package.json version...'
127
127
npm_publish --access public
128
128
fi
129
129
130
- echo " ...released to npm"
130
+ echo ' ...released to npm'
131
131
else
132
- echo " no need for release to npm"
132
+ echo ' no need for release to npm'
133
133
fi
134
134
135
135
# @todo consider making this its own script
140
140
if test -n " ${BEVRY_CDN_TOKEN-} " ; then
141
141
echo ' publishing to bevry cdn...'
142
142
143
- echo " prepping for cdn..."
143
+ echo ' prepping for cdn...'
144
144
f=" ./.npmignore"
145
145
n=" $( mktemp) "
146
146
o=" $( mktemp) "
147
- node -e " process.stdout.write(require('fs').readFileSync('$f ', 'utf8').replace(/# [-=\s]+# CDN Inclusions.+?[^#][^ ][^-=]+/, ''))" > " $n "
147
+ node -e " process.stdout.write(require('fs').readFileSync('$f ', 'utf8').replace(/# [-=\s]+# CDN Inclusions.+?[^#][^ ][^-=]+/, ''))" > " $n "
148
148
mv " $f " " $o "
149
149
mv " $n " " $f "
150
150
151
- echo " versioning for cdn..."
151
+ echo ' versioning for cdn...'
152
152
tag=" cdn"
153
153
version=" $( node -e " process.stdout.write(require('./package.json').version)" ) "
154
154
time=" $( date +%s) "
155
- cdn=" ${version% -* } -${tag} .${time} .${REPO_JOB_ID} " # version trims anything after -
155
+ cdn=" ${version% -* } -${tag} .${time} .${REPO_JOB_ID} " # version trims anything after -
156
156
npm version " ${cdn} " --git-tag-version=false
157
157
158
158
echo " publishing to tag ${tag} with version ${cdn} ..."
159
159
npm_publish --access public --tag " ${tag} "
160
160
161
- echo " adding cdn aliases..."
161
+ echo ' adding cdn aliases...'
162
162
packageName=" $( node -e " process.stdout.write(require('./package.json').name)" ) "
163
163
target=" ${packageName} @${cdn} "
164
164
165
165
if test -n " ${REPO_BRANCH-} " ; then
166
166
echo " aliasing $REPO_NAME /$REPO_BRANCH to ${target} "
167
- curl -d " alias=$REPO_NAME /$REPO_BRANCH " -d " target=${target} " -d " token=${BEVRY_CDN_TOKEN} " https://cdn.bevry.me
167
+ curl -d " alias=$REPO_NAME /$REPO_BRANCH " -d " target=${target} " -d " token=${BEVRY_CDN_TOKEN} " ' https://cdn.bevry.me'
168
168
fi
169
169
if test -n " ${REPO_TAG-} " ; then
170
170
echo " aliasing $REPO_NAME /$REPO_TAG to ${target} "
171
- curl -d " alias=$REPO_NAME /$REPO_TAG " -d " target=${target} " -d " token=${BEVRY_CDN_TOKEN} " https://cdn.bevry.me
171
+ curl -d " alias=$REPO_NAME /$REPO_TAG " -d " target=${target} " -d " token=${BEVRY_CDN_TOKEN} " ' https://cdn.bevry.me'
172
172
fi
173
173
if test -n " ${REPO_COMMIT-} " ; then
174
174
echo " aliasing $REPO_NAME /$REPO_COMMIT to ${target} "
175
- curl -d " alias=$REPO_NAME /$REPO_COMMIT " -d " target=${target} " -d " token=${BEVRY_CDN_TOKEN} " https://cdn.bevry.me
175
+ curl -d " alias=$REPO_NAME /$REPO_COMMIT " -d " target=${target} " -d " token=${BEVRY_CDN_TOKEN} " ' https://cdn.bevry.me'
176
176
fi
177
177
178
178
echo ' resetting cdn changes...'
0 commit comments