Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 608eb32

Browse files
authored
chore: Add .editorconfig, shfmt, shellcheck and subshell dir changes (coder#1649)
1 parent 1a70298 commit 608eb32

File tree

11 files changed

+199
-111
lines changed

11 files changed

+199
-111
lines changed

.editorconfig

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
indent_style = tab
9+
10+
[*.{md,json,yaml,tf,tfvars}]
11+
indent_style = space
12+
indent_size = 2
13+
14+
[coderd/database/dump.sql]
15+
indent_style = space
16+
indent_size = 4

.github/workflows/coder.yaml

+17-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ jobs:
4444
with:
4545
version: v1.46.0
4646

47+
style-lint-shellcheck:
48+
name: style/lint/shellcheck
49+
timeout-minutes: 5
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v3
53+
- name: Run ShellCheck
54+
uses: ludeeus/[email protected]
55+
with:
56+
ignore: node_modules
57+
4758
style-lint-typescript:
4859
name: "style/lint/typescript"
4960
timeout-minutes: 5
@@ -133,7 +144,12 @@ jobs:
133144
- name: Install node_modules
134145
run: ./scripts/yarn_install.sh
135146

136-
- run: "make --output-sync -j -B fmt"
147+
- name: Install shfmt
148+
run: go install mvdan.cc/sh/v3/cmd/[email protected]
149+
150+
- run: |
151+
export PATH=${PATH}:$(go env GOPATH)/bin
152+
make --output-sync -j -B fmt
137153
138154
test-go:
139155
name: "test/go"

Makefile

+20-3
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,37 @@ fmt/terraform: $(wildcard *.tf)
4141
terraform fmt -recursive
4242
.PHONY: fmt/terraform
4343

44-
fmt: fmt/prettier fmt/terraform
44+
fmt/shfmt: $(shell shfmt -f .)
45+
@echo "--- shfmt"
46+
# Only do diff check in CI, errors on diff.
47+
ifdef CI
48+
shfmt -d $(shell shfmt -f .)
49+
else
50+
shfmt -w $(shell shfmt -f .)
51+
endif
52+
53+
fmt: fmt/prettier fmt/terraform fmt/shfmt
4554
.PHONY: fmt
4655

4756
gen: coderd/database/querier.go peerbroker/proto/peerbroker.pb.go provisionersdk/proto/provisioner.pb.go provisionerd/proto/provisionerd.pb.go site/src/api/typesGenerated.ts
4857

4958
install: build
59+
mkdir -p $(INSTALL_DIR)
5060
@echo "--- Copying from bin to $(INSTALL_DIR)"
5161
cp -r ./dist/coder-$(GOOS)_$(GOOS)_$(GOARCH)*/* $(INSTALL_DIR)
5262
@echo "-- CLI available at $(shell ls $(INSTALL_DIR)/coder*)"
5363
.PHONY: install
5464

55-
lint:
65+
lint: lint/shellcheck lint/go
66+
67+
lint/go:
5668
golangci-lint run
57-
.PHONY: lint
69+
.PHONY: lint/go
70+
71+
# Use shfmt to determine the shell files, takes editorconfig into consideration.
72+
lint/shellcheck: $(shell shfmt -f .)
73+
@echo "--- shellcheck"
74+
shellcheck $(shell shfmt -f .)
5875

5976
peerbroker/proto/peerbroker.pb.go: peerbroker/proto/peerbroker.proto
6077
protoc \

coderd/audit/generate.sh

+7-3
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=$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel)
15+
16+
(
17+
cd "$PROJECT_ROOT"
18+
go run ./scripts/auditgen ./coderd/database "$@"
19+
)

coderd/database/generate.sh

+40-36
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/[email protected] 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/[email protected] 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

+10-7
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

+22-16
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=$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel)
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

+8-6
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=$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel)
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

+18-12
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=$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel)
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

+31-27
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=$(cd "$SCRIPT_DIR" && git rev-parse --show-toplevel)
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+
)

site/.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[*]
2+
indent_style = space
3+
indent_size = 2
4+
5+
[*.go]
6+
indent_style = tab
7+
indent_size = unset
8+
9+
[node_modules/**]
10+
ignore = true

0 commit comments

Comments
 (0)