Skip to content

Commit 86e4cfb

Browse files
authored
scan stderr for 409, as exit status is 1
npm/cli#7109
1 parent 3d7f438 commit 86e4cfb

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

action.bash

+30-30
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ REPO_NAME="${REPO_SLUG#*/}"
3434
REPO_TAG=""
3535
REPO_BRANCH=""
3636
REPO_COMMIT=""
37-
if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then
37+
if [[ $GITHUB_REF == "refs/tags/"* ]]; then
3838
REPO_TAG="${GITHUB_REF#"refs/tags/"}"
39-
elif [[ "$GITHUB_REF" == "refs/heads/"* ]]; then
39+
elif [[ $GITHUB_REF == "refs/heads/"* ]]; then
4040
REPO_BRANCH="${GITHUB_REF#"refs/heads/"}"
4141
REPO_COMMIT="$GITHUB_SHA"
4242
else
@@ -52,34 +52,34 @@ fi
5252
# https://github.com/bevry/oneday/actions/runs/7338411137/job/19980941727
5353
# https://github.com/bevry/typechecker/actions/runs/7349089133/job/20008437623
5454
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))"
5859
echo "waiting ${delay} seconds..."
5960
sleep "$delay"
60-
status=0 && npm publish "$@" || status=$?
61+
status=0 && npm publish "$@" 2> >(tee "$stderr" >/dev/stderr) || status=$?
6162
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...'
6667
continue
6768
else
6869
echo "npm publish failed with exit status: $status"
6970
return "$status"
7071
fi
7172
done
72-
return 0
7373
}
7474

7575
# =====================================
7676
# CHECKS
7777

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'
8080
exit 0
8181
elif test -z "$NPM_AUTH_TOKEN"; then
82-
echo "you must provide NPM_AUTH_TOKEN"
82+
echo 'you must provide NPM_AUTH_TOKEN'
8383
exit 1
8484
fi
8585

@@ -92,15 +92,15 @@ fi
9292
# # https://github.com/bevry/es-versions/runs/1378842251?check_suite_focus=true#step:7:39
9393
# # https://github.com/bevry/es-versions/runs/1378917476?check_suite_focus=true#step:7:40
9494
# # 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"
9797
echo "logged into npm as: $(npm whoami)"
9898

9999
# @todo simplify this, and consider making it only run on the default branch
100100
# check if we wish to tag the current branch
101101
if test -n "${NPM_BRANCH_TAG:-}"; then
102102
branch="${NPM_BRANCH_TAG%:*}"
103-
if test -z "$branch" -o "$branch" = "master"; then
103+
if test -z "$branch" -o "$branch" = 'master'; then
104104
branch="${GH_MASTER_BRANCH}"
105105
fi
106106
if test "$branch" = "$REPO_BRANCH"; then
@@ -113,23 +113,23 @@ if test -n "${REPO_TAG-}" -o -n "${tag-}"; then
113113

114114
# not repo tag, is branch tag
115115
if test -z "${REPO_TAG-}" -a -n "${tag-}"; then
116-
echo "bumping the npm version..."
116+
echo 'bumping the npm version...'
117117
version="$(node -e "console.log(require('./package.json').version)")"
118118
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 -
120120
npm version "${next}" --git-tag-version=false
121121
echo "publishing branch ${branch} to tag ${tag} with version ${next}..."
122122
npm_publish --access public --tag "${tag}"
123123

124124
# publish package.json
125125
else
126-
echo "publishing the local package.json version..."
126+
echo 'publishing the local package.json version...'
127127
npm_publish --access public
128128
fi
129129

130-
echo "...released to npm"
130+
echo '...released to npm'
131131
else
132-
echo "no need for release to npm"
132+
echo 'no need for release to npm'
133133
fi
134134

135135
# @todo consider making this its own script
@@ -140,39 +140,39 @@ fi
140140
if test -n "${BEVRY_CDN_TOKEN-}"; then
141141
echo 'publishing to bevry cdn...'
142142

143-
echo "prepping for cdn..."
143+
echo 'prepping for cdn...'
144144
f="./.npmignore"
145145
n="$(mktemp)"
146146
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"
148148
mv "$f" "$o"
149149
mv "$n" "$f"
150150

151-
echo "versioning for cdn..."
151+
echo 'versioning for cdn...'
152152
tag="cdn"
153153
version="$(node -e "process.stdout.write(require('./package.json').version)")"
154154
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 -
156156
npm version "${cdn}" --git-tag-version=false
157157

158158
echo "publishing to tag ${tag} with version ${cdn}..."
159159
npm_publish --access public --tag "${tag}"
160160

161-
echo "adding cdn aliases..."
161+
echo 'adding cdn aliases...'
162162
packageName="$(node -e "process.stdout.write(require('./package.json').name)")"
163163
target="${packageName}@${cdn}"
164164

165165
if test -n "${REPO_BRANCH-}"; then
166166
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'
168168
fi
169169
if test -n "${REPO_TAG-}"; then
170170
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'
172172
fi
173173
if test -n "${REPO_COMMIT-}"; then
174174
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'
176176
fi
177177

178178
echo 'resetting cdn changes...'

0 commit comments

Comments
 (0)