Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 1e3bd2b

Browse files
authored
Add formatting check for shell scripts (#106)
1 parent 1e7f912 commit 1e3bd2b

File tree

18 files changed

+144
-129
lines changed

18 files changed

+144
-129
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
- uses: oven-sh/setup-bun@v1
2121
with:
2222
bun-version: latest
23+
- name: Setup
24+
run: bun install
2325
- run: bun test
2426
pretty:
2527
runs-on: ubuntu-latest
@@ -28,7 +30,9 @@ jobs:
2830
- uses: oven-sh/setup-bun@v1
2931
with:
3032
bun-version: latest
33+
- name: Setup
34+
run: bun install
3135
- name: Format
3236
run: bun fmt:ci
3337
- name: Lint
34-
run: bun install && bun lint
38+
run: bun lint

.sample/run.sh

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

3+
# Convert templated variables to shell variables
4+
# shellcheck disable=SC2269
5+
LOG_PATH=${LOG_PATH}
6+
7+
# shellcheck disable=SC2034
38
BOLD='\033[0;1m'
9+
10+
# shellcheck disable=SC2059
411
printf "$${BOLD}Installing MODULE_NAME ...\n\n"
12+
513
# Add code here
614
# Use varibles from the templatefile function in main.tf
715
# e.g. LOG_PATH, PORT, etc.
@@ -13,6 +21,6 @@ printf "👷 Starting MODULE_NAME in background...\n\n"
1321
# 1. Use & to run it in background
1422
# 2. redirct stdout and stderr to log files
1523

16-
./app >${LOG_PATH} 2>&1 &
24+
./app > "$${LOG_PATH}" 2>&1 &
1725

18-
printf "check logs at ${LOG_PATH} \n\n"
26+
printf "check logs at %s\n\n" "$${LOG_PATH}"

bun.lockb

2.12 KB
Binary file not shown.

code-server/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ done
4242
if [ ! -f ~/.local/share/code-server/Machine/settings.json ]; then
4343
echo "⚙️ Creating settings file..."
4444
mkdir -p ~/.local/share/code-server/Machine
45-
echo "${SETTINGS}" >~/.local/share/code-server/Machine/settings.json
45+
echo "${SETTINGS}" > ~/.local/share/code-server/Machine/settings.json
4646
fi
4747

4848
echo "👷 Running code-server in the background..."
4949
echo "Check logs at ${LOG_PATH}!"
50-
$CODE_SERVER --auth none --port ${PORT} >${LOG_PATH} 2>&1 &
50+
$CODE_SERVER --auth none --port ${PORT} > ${LOG_PATH} 2>&1 &

coder-login/run.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ BOLD='\033[0;1m'
77

88
printf "$${BOLD}Logging into Coder...\n\n$${RESET}"
99

10-
if ! coder list >/dev/null 2>&1; then
11-
set +x; coder login --token="${CODER_USER_TOKEN}" --url="${CODER_DEPLOYMENT_URL}"
10+
if ! coder list > /dev/null 2>&1; then
11+
set +x
12+
coder login --token="${CODER_USER_TOKEN}" --url="${CODER_DEPLOYMENT_URL}"
1213
else
1314
echo "You are already authenticated with coder."
1415
fi

filebrowser/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ printf "📂 Serving $${ROOT_DIR} at http://localhost:${PORT} \n\n"
2121

2222
printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n"
2323

24-
filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} >${LOG_PATH} 2>&1 &
24+
filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} > ${LOG_PATH} 2>&1 &
2525

2626
printf "📝 Logs at ${LOG_PATH} \n\n"

git-clone/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [ -z "$CLONE_PATH" ]; then
1818
fi
1919

2020
# Check if `git` is installed...
21-
if ! command -v git >/dev/null; then
21+
if ! command -v git > /dev/null; then
2222
echo "Git is not installed!"
2323
exit 1
2424
fi

git-commit-signing/run.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#!/usr/bin/env sh
22

33
if ! command -v git > /dev/null; then
4-
echo "git is not installed"
5-
exit 1
4+
echo "git is not installed"
5+
exit 1
66
fi
77

88
if ! command -v curl > /dev/null; then
9-
echo "curl is not installed"
10-
exit 1
9+
echo "curl is not installed"
10+
exit 1
1111
fi
1212

1313
if ! command -v jq > /dev/null; then
14-
echo "jq is not installed"
15-
exit 1
14+
echo "jq is not installed"
15+
exit 1
1616
fi
1717

1818
mkdir -p ~/.ssh/git-commit-signing
1919

2020
echo "Downloading SSH key"
2121

2222
ssh_key=$(curl --request GET \
23-
--url "${CODER_AGENT_URL}api/v2/workspaceagents/me/gitsshkey" \
24-
--header "Coder-Session-Token: ${CODER_AGENT_TOKEN}")
23+
--url "${CODER_AGENT_URL}api/v2/workspaceagents/me/gitsshkey" \
24+
--header "Coder-Session-Token: ${CODER_AGENT_TOKEN}")
2525

26-
jq --raw-output ".public_key" > ~/.ssh/git-commit-signing/coder.pub <<EOF
26+
jq --raw-output ".public_key" > ~/.ssh/git-commit-signing/coder.pub << EOF
2727
$ssh_key
2828
EOF
2929

30-
jq --raw-output ".private_key" > ~/.ssh/git-commit-signing/coder <<EOF
30+
jq --raw-output ".private_key" > ~/.ssh/git-commit-signing/coder << EOF
3131
$ssh_key
3232
EOF
3333

@@ -38,4 +38,4 @@ echo "Configuring git to use the SSH key"
3838

3939
git config --global gpg.format ssh
4040
git config --global commit.gpgsign true
41-
git config --global user.signingkey ~/.ssh/git-commit-signing/coder
41+
git config --global user.signingkey ~/.ssh/git-commit-signing/coder

git-config/run.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ BOLD='\033[0;1m'
44
printf "$${BOLD}Checking git-config!\n"
55

66
# Check if git is installed
7-
command -v git >/dev/null 2>&1 || {
8-
echo "Git is not installed!"
9-
exit 1
7+
command -v git > /dev/null 2>&1 || {
8+
echo "Git is not installed!"
9+
exit 1
1010
}
1111

1212
# Set git username and email if missing
1313
if [ -z $(git config --get user.email) ]; then
14-
printf "git-config: No user.email found, setting to ${GIT_EMAIL}\n"
15-
git config --global user.email "${GIT_EMAIL}"
14+
printf "git-config: No user.email found, setting to ${GIT_EMAIL}\n"
15+
git config --global user.email "${GIT_EMAIL}"
1616
fi
1717

1818
if [ -z $(git config --get user.name) ]; then
19-
printf "git-config: No user.name found, setting to ${GIT_USERNAME}\n"
20-
git config --global user.name "${GIT_USERNAME}"
19+
printf "git-config: No user.name found, setting to ${GIT_USERNAME}\n"
20+
git config --global user.name "${GIT_USERNAME}"
2121
fi
2222

2323
printf "\n$${BOLD}git-config: using email: $(git config --get user.email)\n"

jfrog-oauth/run.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
BOLD='\033[0;1m'
44

55
# check if JFrog CLI is already installed
6-
if command -v jf >/dev/null 2>&1; then
6+
if command -v jf > /dev/null 2>&1; then
77
echo "✅ JFrog CLI is already installed, skipping installation."
88
else
99
echo "📦 Installing JFrog CLI..."
@@ -23,15 +23,15 @@ if [ -z "${REPOSITORY_NPM}" ]; then
2323
echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration."
2424
else
2525
# check if npm is installed and configure it to use the Artifactory "npm" repository.
26-
if command -v npm >/dev/null 2>&1; then
26+
if command -v npm > /dev/null 2>&1; then
2727
echo "📦 Configuring npm..."
2828
jf npmc --global --repo-resolve "${REPOSITORY_NPM}"
2929
fi
30-
cat <<EOF >~/.npmrc
30+
cat << EOF > ~/.npmrc
3131
email = ${ARTIFACTORY_EMAIL}
3232
registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}
3333
EOF
34-
jf rt curl /api/npm/auth >>~/.npmrc
34+
jf rt curl /api/npm/auth >> ~/.npmrc
3535
fi
3636

3737
# Configure the `pip` to use the Artifactory "python" repository.
@@ -41,7 +41,7 @@ else
4141
echo "🐍 Configuring pip..."
4242
jf pipc --global --repo-resolve "${REPOSITORY_PYPI}"
4343
mkdir -p ~/.pip
44-
cat <<EOF >~/.pip/pip.conf
44+
cat << EOF > ~/.pip/pip.conf
4545
[global]
4646
index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple
4747
EOF

jfrog-token/run.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
BOLD='\033[0;1m'
44

55
# check if JFrog CLI is already installed
6-
if command -v jf >/dev/null 2>&1; then
6+
if command -v jf > /dev/null 2>&1; then
77
echo "✅ JFrog CLI is already installed, skipping installation."
88
else
99
echo "📦 Installing JFrog CLI..."
@@ -23,15 +23,15 @@ if [ -z "${REPOSITORY_NPM}" ]; then
2323
echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration."
2424
else
2525
# check if npm is installed and configure it to use the Artifactory "npm" repository.
26-
if command -v npm >/dev/null 2>&1; then
26+
if command -v npm > /dev/null 2>&1; then
2727
echo "📦 Configuring npm..."
2828
jf npmc --global --repo-resolve "${REPOSITORY_NPM}"
2929
fi
30-
cat <<EOF >~/.npmrc
30+
cat << EOF > ~/.npmrc
3131
email = ${ARTIFACTORY_EMAIL}
3232
registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}
3333
EOF
34-
jf rt curl /api/npm/auth >>~/.npmrc
34+
jf rt curl /api/npm/auth >> ~/.npmrc
3535
fi
3636

3737
# Configure the `pip` to use the Artifactory "python" repository.
@@ -41,7 +41,7 @@ else
4141
echo "🐍 Configuring pip..."
4242
jf pipc --global --repo-resolve "${REPOSITORY_PYPI}"
4343
mkdir -p ~/.pip
44-
cat <<EOF >~/.pip/pip.conf
44+
cat << EOF > ~/.pip/pip.conf
4545
[global]
4646
index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple
4747
EOF

jupyter-notebook/run.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ BOLD='\033[0;1m'
55
printf "$${BOLD}Installing jupyter-notebook!\n"
66

77
# check if jupyter-notebook is installed
8-
if ! command -v jupyter-notebook >/dev/null 2>&1; then
9-
# install jupyter-notebook
10-
# check if python3 pip is installed
11-
if ! command -v pip3 >/dev/null 2>&1; then
12-
echo "pip3 is not installed"
13-
echo "Please install pip3 in your Dockerfile/VM image before running this script"
14-
exit 1
15-
fi
16-
# install jupyter-notebook
17-
pip3 install --upgrade --no-cache-dir --no-warn-script-location jupyter
18-
echo "🥳 jupyter-notebook has been installed\n\n"
8+
if ! command -v jupyter-notebook > /dev/null 2>&1; then
9+
# install jupyter-notebook
10+
# check if python3 pip is installed
11+
if ! command -v pip3 > /dev/null 2>&1; then
12+
echo "pip3 is not installed"
13+
echo "Please install pip3 in your Dockerfile/VM image before running this script"
14+
exit 1
15+
fi
16+
# install jupyter-notebook
17+
pip3 install --upgrade --no-cache-dir --no-warn-script-location jupyter
18+
echo "🥳 jupyter-notebook has been installed\n\n"
1919
else
20-
echo "🥳 jupyter-notebook is already installed\n\n"
20+
echo "🥳 jupyter-notebook is already installed\n\n"
2121
fi
2222

2323
echo "👷 Starting jupyter-notebook in background..."
2424
echo "check logs at ${LOG_PATH}"
25-
$HOME/.local/bin/jupyter notebook --NotebookApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' >${LOG_PATH} 2>&1 &
25+
$HOME/.local/bin/jupyter notebook --NotebookApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' > ${LOG_PATH} 2>&1 &

jupyterlab/run.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ BOLD='\033[0;1m'
55
printf "$${BOLD}Installing jupyterlab!\n"
66

77
# check if jupyterlab is installed
8-
if ! command -v jupyterlab >/dev/null 2>&1; then
9-
# install jupyterlab
10-
# check if python3 pip is installed
11-
if ! command -v pip3 >/dev/null 2>&1; then
12-
echo "pip3 is not installed"
13-
echo "Please install pip3 in your Dockerfile/VM image before running this script"
14-
exit 1
15-
fi
16-
# install jupyterlab
17-
pip3 install --upgrade --no-cache-dir --no-warn-script-location jupyterlab
18-
echo "🥳 jupyterlab has been installed\n\n"
8+
if ! command -v jupyterlab > /dev/null 2>&1; then
9+
# install jupyterlab
10+
# check if python3 pip is installed
11+
if ! command -v pip3 > /dev/null 2>&1; then
12+
echo "pip3 is not installed"
13+
echo "Please install pip3 in your Dockerfile/VM image before running this script"
14+
exit 1
15+
fi
16+
# install jupyterlab
17+
pip3 install --upgrade --no-cache-dir --no-warn-script-location jupyterlab
18+
echo "🥳 jupyterlab has been installed\n\n"
1919
else
20-
echo "🥳 jupyterlab is already installed\n\n"
20+
echo "🥳 jupyterlab is already installed\n\n"
2121
fi
2222

2323
echo "👷 Starting jupyterlab in background..."
2424
echo "check logs at ${LOG_PATH}"
25-
$HOME/.local/bin/jupyter lab --ServerApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' >${LOG_PATH} 2>&1 &
25+
$HOME/.local/bin/jupyter lab --ServerApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' > ${LOG_PATH} 2>&1 &

new.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ MODULE_NAME=$1
77

88
# Check if module name is provided
99
if [ -z "$MODULE_NAME" ]; then
10-
echo "Usage: ./new.sh <module_name>"
11-
exit 1
10+
echo "Usage: ./new.sh <module_name>"
11+
exit 1
1212
fi
1313

1414
# Create module directory and exit if it alredy exists
1515
if [ -d "$MODULE_NAME" ]; then
16-
echo "Module with name $MODULE_NAME already exists"
17-
echo "Please choose a different name"
18-
exit 1
16+
echo "Module with name $MODULE_NAME already exists"
17+
echo "Please choose a different name"
18+
exit 1
1919
fi
2020
mkdir -p "${MODULE_NAME}"
2121

@@ -27,13 +27,13 @@ cd "${MODULE_NAME}"
2727

2828
# Detect OS
2929
if [[ "$OSTYPE" == "darwin"* ]]; then
30-
# macOS
31-
sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" main.tf
32-
sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" README.md
30+
# macOS
31+
sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" main.tf
32+
sed -i '' "s/MODULE_NAME/${MODULE_NAME}/g" README.md
3333
else
34-
# Linux
35-
sed -i "s/MODULE_NAME/${MODULE_NAME}/g" main.tf
36-
sed -i "s/MODULE_NAME/${MODULE_NAME}/g" README.md
34+
# Linux
35+
sed -i "s/MODULE_NAME/${MODULE_NAME}/g" main.tf
36+
sed -i "s/MODULE_NAME/${MODULE_NAME}/g" README.md
3737
fi
3838

3939
# Make run.sh executable

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
"name": "modules",
33
"scripts": {
44
"test": "bun test",
5-
"fmt": "bun x prettier -w **/*.ts **/*.md *.md && terraform fmt **/*.tf",
6-
"fmt:ci": "bun x prettier --check **/*.ts **/*.md *.md && terraform fmt -check **/*.tf",
5+
"fmt": "bun x prettier --plugin prettier-plugin-sh -w **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt **/*.tf .sample/main.tf",
6+
"fmt:ci": "bun x prettier --plugin prettier-plugin-sh --check **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt -check **/*.tf .sample/main.tf",
77
"lint": "bun run lint.ts"
88
},
99
"devDependencies": {
10-
"bun-types": "^1.0.3",
10+
"bun-types": "^1.0.18",
1111
"gray-matter": "^4.0.3",
12-
"marked": "^9.0.3"
12+
"marked": "^11.1.0",
13+
"prettier-plugin-sh": "^0.13.1"
1314
},
1415
"peerDependencies": {
15-
"typescript": "^5.0.0"
16+
"typescript": "^5.3.3"
1617
}
1718
}

0 commit comments

Comments
 (0)