Skip to content

Commit afbaeb8

Browse files
committed
chore: Perform dir changes in subshell and run shfmt
1 parent 7506892 commit afbaeb8

File tree

7 files changed

+136
-107
lines changed

7 files changed

+136
-107
lines changed

coderd/audit/generate.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
# Usage:
99
# ./generate.sh <database type> <database type> ...
1010

11-
1211
set -euo pipefail
1312

14-
cd "$(dirname "$0")" && cd "$(git rev-parse --show-toplevel)"
15-
go run ./scripts/auditgen ./coderd/database "$@"
13+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
14+
PROJECT_ROOT=${SCRIPT_DIR}/..
15+
16+
(
17+
cd "$PROJECT_ROOT"
18+
go run ./scripts/auditgen ./coderd/database "$@"
19+
)

coderd/database/generate.sh

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,43 @@
88

99
set -euo pipefail
1010

11-
cd "$(dirname "$0")"
12-
13-
# The logic below depends on the exact version being correct :(
14-
go run github.com/kyleconroy/sqlc/cmd/sqlc@v1.13.0 generate
15-
16-
first=true
17-
for fi in queries/*.sql.go; do
18-
# Find the last line from the imports section and add 1.
19-
cut=$(grep -n ')' "$fi" | head -n 1 | cut -d: -f1)
20-
cut=$((cut + 1))
21-
22-
# Copy the header from the first file only, ignoring the source comment.
23-
if $first; then
24-
head -n 6 < "$fi" | grep -v "source" > queries.sql.go
25-
first=false
26-
fi
27-
28-
# Append the file past the imports section into queries.sql.go.
29-
tail -n "+$cut" < "$fi" >> queries.sql.go
30-
done
31-
32-
# Move the files we want.
33-
mv queries/querier.go .
34-
mv queries/models.go .
35-
36-
# Remove temporary go files.
37-
rm -f queries/*.go
38-
39-
# Fix struct/interface names.
40-
gofmt -w -r 'Querier -> querier' -- *.go
41-
gofmt -w -r 'Queries -> sqlQuerier' -- *.go
42-
43-
# Ensure correct imports exist. Modules must all be downloaded so we get correct
44-
# suggestions.
45-
go mod download
46-
goimports -w queries.sql.go
11+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
12+
13+
(
14+
cd "$SCRIPT_DIR"
15+
16+
# The logic below depends on the exact version being correct :(
17+
go run github.com/kyleconroy/sqlc/cmd/sqlc@v1.13.0 generate
18+
19+
first=true
20+
for fi in queries/*.sql.go; do
21+
# Find the last line from the imports section and add 1.
22+
cut=$(grep -n ')' "$fi" | head -n 1 | cut -d: -f1)
23+
cut=$((cut + 1))
24+
25+
# Copy the header from the first file only, ignoring the source comment.
26+
if $first; then
27+
head -n 6 <"$fi" | grep -v "source" >queries.sql.go
28+
first=false
29+
fi
30+
31+
# Append the file past the imports section into queries.sql.go.
32+
tail -n "+$cut" <"$fi" >>queries.sql.go
33+
done
34+
35+
# Move the files we want.
36+
mv queries/querier.go .
37+
mv queries/models.go .
38+
39+
# Remove temporary go files.
40+
rm -f queries/*.go
41+
42+
# Fix struct/interface names.
43+
gofmt -w -r 'Querier -> querier' -- *.go
44+
gofmt -w -r 'Queries -> sqlQuerier' -- *.go
45+
46+
# Ensure correct imports exist. Modules must all be downloaded so we get correct
47+
# suggestions.
48+
go mod download
49+
goimports -w queries.sql.go
50+
)

coderd/database/migrations/create_migration.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77

88
set -euo pipefail
99

10-
cd "$(dirname "$0")"
10+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
11+
(
12+
cd "$SCRIPT_DIR"
1113

12-
# if migration name is an empty string exit
13-
[[ -z "${*}" ]] && (echo "Must provide a migration name" && exit 1)
14+
# if migration name is an empty string exit
15+
[[ -z "${*}" ]] && (echo "Must provide a migration name" && exit 1)
1416

15-
# " " && "-" -> "_"
16-
title="$(echo "${@}" | tr "[:upper:]" "[:lower:]" | sed -E -e "s/( |-)/_/g")"
17+
# " " && "-" -> "_"
18+
title="$(echo "${@}" | tr "[:upper:]" "[:lower:]" | sed -E -e "s/( |-)/_/g")"
1719

18-
migrate create -ext sql -dir . -seq "$title"
20+
migrate create -ext sql -dir . -seq "$title"
1921

20-
echo "Run \"make gen\" to generate models."
22+
echo "Run \"make gen\" to generate models."
23+
)

scripts/check_unstaged.sh

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@
22

33
set -euo pipefail
44

5-
FILES="$(git ls-files --other --modified --exclude-standard)"
6-
if [[ "$FILES" != "" ]]; then
7-
mapfile -t files <<<"$FILES"
5+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
6+
PROJECT_ROOT=${SCRIPT_DIR}/..
87

9-
echo "The following files contain unstaged changes:"
10-
echo
11-
for file in "${files[@]}"; do
12-
echo " - $file"
13-
done
14-
echo
8+
(
9+
cd "${PROJECT_ROOT}"
1510

16-
echo "These are the changes:"
17-
echo
18-
for file in "${files[@]}"; do
19-
git --no-pager diff "$file"
20-
done
21-
exit 1
22-
fi
11+
FILES="$(git ls-files --other --modified --exclude-standard)"
12+
if [[ "$FILES" != "" ]]; then
13+
mapfile -t files <<<"$FILES"
2314

15+
echo "The following files contain unstaged changes:"
16+
echo
17+
for file in "${files[@]}"; do
18+
echo " - $file"
19+
done
20+
echo
21+
22+
echo "These are the changes:"
23+
echo
24+
for file in "${files[@]}"; do
25+
git --no-pager diff "$file"
26+
done
27+
exit 1
28+
fi
29+
)
2430
exit 0

scripts/develop.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
set -euo pipefail
44

5-
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
6-
cd "${PROJECT_ROOT}"
5+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
6+
PROJECT_ROOT=${SCRIPT_DIR}/..
77

88
echo '== Run "make build" before running this command to build binaries.'
99
echo '== Without these binaries, workspaces will fail to start!'
@@ -19,8 +19,10 @@ export CODER_DEV_ADMIN_PASSWORD=password
1919
# to kill both at the same time. For more details, see:
2020
# https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script
2121
(
22-
trap 'kill 0' SIGINT
23-
CODERV2_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev &
24-
go run -tags embed cmd/coder/main.go server --dev --tunnel=true &
25-
wait
22+
cd "${PROJECT_ROOT}"
23+
24+
trap 'kill 0' SIGINT
25+
CODERV2_HOST=http://127.0.0.1:3000 INSPECT_XSTATE=true yarn --cwd=./site dev &
26+
go run -tags embed cmd/coder/main.go server --dev --tunnel=true &
27+
wait
2628
)

scripts/sign_macos.sh

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
#!/usr/bin/env bash
22

33
set -euo pipefail
4-
cd "$(git rev-parse --show-toplevel)"
54

6-
codesign -s $AC_APPLICATION_IDENTITY -f -v --timestamp --options runtime $1
5+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
6+
PROJECT_ROOT=${SCRIPT_DIR}/..
77

8-
config="$(mktemp -d)/gon.json"
9-
jq -r --null-input --arg path "$(pwd)/$1" '{
10-
"notarize": [
11-
{
12-
"path": $path,
13-
"bundle_id": "com.coder.cli"
14-
}
15-
]
16-
}' > $config
17-
gon $config
8+
(
9+
cd "${PROJECT_ROOT}"
10+
11+
codesign -s "$AC_APPLICATION_IDENTITY" -f -v --timestamp --options runtime "$1"
12+
13+
config=$(mktemp -d)/gon.json
14+
jq -r --null-input --arg path "$(pwd)/$1" '{
15+
"notarize": [
16+
{
17+
"path": $path,
18+
"bundle_id": "com.coder.cli"
19+
}
20+
]
21+
}' >"$config"
22+
gon "$config"
23+
)

scripts/yarn_install.sh

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,37 @@
77

88
set -euo pipefail
99

10-
PROJECT_ROOT=$(git rev-parse --show-toplevel)
11-
cd "$PROJECT_ROOT/site"
10+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
11+
PROJECT_ROOT=${SCRIPT_DIR}/..
1212

13-
yarn_flags=(
14-
# Do not execute install scripts
15-
# TODO: check if build works properly with this enabled
16-
# --ignore-scripts
13+
(
14+
cd "$PROJECT_ROOT/site"
1715

18-
# Check if existing node_modules are valid
19-
# TODO: determine if this is necessary
20-
# --check-files
21-
)
16+
yarn_flags=(
17+
# Do not execute install scripts
18+
# TODO: check if build works properly with this enabled
19+
# --ignore-scripts
20+
21+
# Check if existing node_modules are valid
22+
# TODO: determine if this is necessary
23+
# --check-files
24+
)
25+
26+
if [ -n "${CI:-}" ]; then
27+
yarn_flags+=(
28+
# Install dependencies from lockfile, ensuring builds are fully
29+
# reproducible
30+
--frozen-lockfile
31+
# Suppress progress information
32+
--silent
33+
# Disable interactive prompts for build
34+
--non-interactive
35+
)
36+
fi
2237

23-
if [ -n "${CI:-}" ]; then
24-
yarn_flags+=(
25-
# Install dependencies from lockfile, ensuring builds are fully
26-
# reproducible
27-
--frozen-lockfile
28-
# Suppress progress information
29-
--silent
30-
# Disable interactive prompts for build
31-
--non-interactive
32-
)
33-
fi
34-
35-
# Append whatever is specified on the command line
36-
yarn_flags+=("$@")
37-
38-
echo "+ yarn install ${yarn_flags[*]}"
39-
yarn install "${yarn_flags[@]}"
38+
# Append whatever is specified on the command line
39+
yarn_flags+=("$@")
40+
41+
echo "+ yarn install ${yarn_flags[*]}"
42+
yarn install "${yarn_flags[@]}"
43+
)

0 commit comments

Comments
 (0)