Skip to content

Commit 4527417

Browse files
committed
fix: remove unreachable code in should_deploy.sh
Shellcheck ≥0.9.0 (Ubuntu 26.04) flags the dead code after the if/else block as SC2317. Both branches called exit 0, making everything after line 32 unreachable. Cherry-pick the clean version from main that simply prints DEPLOY/NOOP without the dead code.
1 parent b863f88 commit 4527417

1 file changed

Lines changed: 4 additions & 62 deletions

File tree

‎scripts/should_deploy.sh‎

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# This script determines if a commit in either the main branch or a
4-
# `release/x.y` branch should be deployed to dogfood.
3+
# This script determines if the current branch should be deployed to dogfood.
54
#
65
# To avoid masking unrelated failures, this script will return 0 in either case,
76
# and will print `DEPLOY` or `NOOP` to stdout.
@@ -11,73 +10,16 @@ set -euo pipefail
1110
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
1211
cdroot
1312

14-
deploy_branch=main
15-
16-
# Determine the current branch name and check that it is one of the supported
17-
# branch names.
1813
branch_name=$(git branch --show-current)
1914

20-
# Short circuit: we no longer deploy release branches to dogfood, and instead
21-
# test them on the stable deployment.
15+
# We no longer deploy release branches to dogfood, and instead test them on the
16+
# stable deployment.
2217
# TODO: once we're happy with the new deployment process, we can remove this
23-
# script and the related github workflow stuff.
18+
# script and the related GitHub workflow.
2419
if [[ "$branch_name" == "main" ]]; then
2520
log "VERDICT: DEPLOY"
2621
echo "DEPLOY" # stdout
27-
exit 0
2822
else
2923
log "VERDICT: NOOP"
3024
echo "NOOP" # stdout
31-
exit 0
32-
fi
33-
34-
if [[ "$branch_name" != "main" && ! "$branch_name" =~ ^release/[0-9]+\.[0-9]+$ ]]; then
35-
error "Current branch '$branch_name' is not a supported branch name for dogfood, must be 'main' or 'release/x.y'"
36-
fi
37-
log "Current branch '$branch_name'"
38-
39-
# Determine the remote name
40-
remote=$(git remote -v | grep coder/coder | awk '{print $1}' | head -n1)
41-
if [[ -z "${remote}" ]]; then
42-
error "Could not find remote for coder/coder"
43-
fi
44-
log "Using remote '$remote'"
45-
46-
# Step 1: List all release branches and sort them by major/minor so we can find
47-
# the latest release branch.
48-
release_branches=$(
49-
git branch -r --format='%(refname:short)' |
50-
grep -E "${remote}/release/[0-9]+\.[0-9]+$" |
51-
sed "s|${remote}/||" |
52-
sort -V
53-
)
54-
55-
# As a sanity check, release/2.26 should exist.
56-
if ! echo "$release_branches" | grep "release/2.26" >/dev/null; then
57-
error "Could not find existing release branches. Did you run 'git fetch -ap ${remote}'?"
58-
fi
59-
60-
latest_release_branch=$(echo "$release_branches" | tail -n 1)
61-
latest_release_branch_version=${latest_release_branch#release/}
62-
log "Latest release branch: $latest_release_branch"
63-
log "Latest release branch version: $latest_release_branch_version"
64-
65-
# Step 2: check if a matching tag `v<x.y>.0` exists. If it does not, we will
66-
# use the release branch as the deploy branch.
67-
if ! git rev-parse "refs/tags/v${latest_release_branch_version}.0" >/dev/null 2>&1; then
68-
log "Tag 'v${latest_release_branch_version}.0' does not exist, using release branch as deploy branch"
69-
deploy_branch=$latest_release_branch
70-
else
71-
log "Matching tag 'v${latest_release_branch_version}.0' exists, using main as deploy branch"
72-
fi
73-
log "Deploy branch: $deploy_branch"
74-
75-
# Finally, check if the current branch is the deploy branch.
76-
log
77-
if [[ "$branch_name" != "$deploy_branch" ]]; then
78-
log "VERDICT: DO NOT DEPLOY"
79-
echo "NOOP" # stdout
80-
else
81-
log "VERDICT: DEPLOY"
82-
echo "DEPLOY" # stdout
8325
fi

0 commit comments

Comments
 (0)