Add formatting check for shell scripts (#106)

pull/112/head^2
Muhammad Atif Ali 1 year ago committed by GitHub
parent 1e7f91231c
commit 1e3bd2b04b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,6 +20,8 @@ jobs:
- uses: oven-sh/setup-bun@v1 - uses: oven-sh/setup-bun@v1
with: with:
bun-version: latest bun-version: latest
- name: Setup
run: bun install
- run: bun test - run: bun test
pretty: pretty:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -28,7 +30,9 @@ jobs:
- uses: oven-sh/setup-bun@v1 - uses: oven-sh/setup-bun@v1
with: with:
bun-version: latest bun-version: latest
- name: Setup
run: bun install
- name: Format - name: Format
run: bun fmt:ci run: bun fmt:ci
- name: Lint - name: Lint
run: bun install && bun lint run: bun lint

@ -1,7 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env sh
# Convert templated variables to shell variables
# shellcheck disable=SC2269
LOG_PATH=${LOG_PATH}
# shellcheck disable=SC2034
BOLD='\033[0;1m' BOLD='\033[0;1m'
# shellcheck disable=SC2059
printf "$${BOLD}Installing MODULE_NAME ...\n\n" printf "$${BOLD}Installing MODULE_NAME ...\n\n"
# Add code here # Add code here
# Use varibles from the templatefile function in main.tf # Use varibles from the templatefile function in main.tf
# e.g. LOG_PATH, PORT, etc. # e.g. LOG_PATH, PORT, etc.
@ -13,6 +21,6 @@ printf "👷 Starting MODULE_NAME in background...\n\n"
# 1. Use & to run it in background # 1. Use & to run it in background
# 2. redirct stdout and stderr to log files # 2. redirct stdout and stderr to log files
./app >${LOG_PATH} 2>&1 & ./app > "$${LOG_PATH}" 2>&1 &
printf "check logs at ${LOG_PATH} \n\n" printf "check logs at %s\n\n" "$${LOG_PATH}"

Binary file not shown.

@ -42,9 +42,9 @@ done
if [ ! -f ~/.local/share/code-server/Machine/settings.json ]; then if [ ! -f ~/.local/share/code-server/Machine/settings.json ]; then
echo "⚙️ Creating settings file..." echo "⚙️ Creating settings file..."
mkdir -p ~/.local/share/code-server/Machine mkdir -p ~/.local/share/code-server/Machine
echo "${SETTINGS}" >~/.local/share/code-server/Machine/settings.json echo "${SETTINGS}" > ~/.local/share/code-server/Machine/settings.json
fi fi
echo "👷 Running code-server in the background..." echo "👷 Running code-server in the background..."
echo "Check logs at ${LOG_PATH}!" echo "Check logs at ${LOG_PATH}!"
$CODE_SERVER --auth none --port ${PORT} >${LOG_PATH} 2>&1 & $CODE_SERVER --auth none --port ${PORT} > ${LOG_PATH} 2>&1 &

@ -7,8 +7,9 @@ BOLD='\033[0;1m'
printf "$${BOLD}Logging into Coder...\n\n$${RESET}" printf "$${BOLD}Logging into Coder...\n\n$${RESET}"
if ! coder list >/dev/null 2>&1; then if ! coder list > /dev/null 2>&1; then
set +x; coder login --token="${CODER_USER_TOKEN}" --url="${CODER_DEPLOYMENT_URL}" set +x
coder login --token="${CODER_USER_TOKEN}" --url="${CODER_DEPLOYMENT_URL}"
else else
echo "You are already authenticated with coder." echo "You are already authenticated with coder."
fi fi

@ -21,6 +21,6 @@ printf "📂 Serving $${ROOT_DIR} at http://localhost:${PORT} \n\n"
printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n" printf "Running 'filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG}' \n\n"
filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} >${LOG_PATH} 2>&1 & filebrowser --noauth --root $ROOT_DIR --port ${PORT}$${DB_FLAG} > ${LOG_PATH} 2>&1 &
printf "📝 Logs at ${LOG_PATH} \n\n" printf "📝 Logs at ${LOG_PATH} \n\n"

@ -18,7 +18,7 @@ if [ -z "$CLONE_PATH" ]; then
fi fi
# Check if `git` is installed... # Check if `git` is installed...
if ! command -v git >/dev/null; then if ! command -v git > /dev/null; then
echo "Git is not installed!" echo "Git is not installed!"
exit 1 exit 1
fi fi

@ -23,11 +23,11 @@ ssh_key=$(curl --request GET \
--url "${CODER_AGENT_URL}api/v2/workspaceagents/me/gitsshkey" \ --url "${CODER_AGENT_URL}api/v2/workspaceagents/me/gitsshkey" \
--header "Coder-Session-Token: ${CODER_AGENT_TOKEN}") --header "Coder-Session-Token: ${CODER_AGENT_TOKEN}")
jq --raw-output ".public_key" > ~/.ssh/git-commit-signing/coder.pub <<EOF jq --raw-output ".public_key" > ~/.ssh/git-commit-signing/coder.pub << EOF
$ssh_key $ssh_key
EOF EOF
jq --raw-output ".private_key" > ~/.ssh/git-commit-signing/coder <<EOF jq --raw-output ".private_key" > ~/.ssh/git-commit-signing/coder << EOF
$ssh_key $ssh_key
EOF EOF

@ -4,7 +4,7 @@ BOLD='\033[0;1m'
printf "$${BOLD}Checking git-config!\n" printf "$${BOLD}Checking git-config!\n"
# Check if git is installed # Check if git is installed
command -v git >/dev/null 2>&1 || { command -v git > /dev/null 2>&1 || {
echo "Git is not installed!" echo "Git is not installed!"
exit 1 exit 1
} }

@ -3,7 +3,7 @@
BOLD='\033[0;1m' BOLD='\033[0;1m'
# check if JFrog CLI is already installed # check if JFrog CLI is already installed
if command -v jf >/dev/null 2>&1; then if command -v jf > /dev/null 2>&1; then
echo "✅ JFrog CLI is already installed, skipping installation." echo "✅ JFrog CLI is already installed, skipping installation."
else else
echo "📦 Installing JFrog CLI..." echo "📦 Installing JFrog CLI..."
@ -23,15 +23,15 @@ if [ -z "${REPOSITORY_NPM}" ]; then
echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration." echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration."
else else
# check if npm is installed and configure it to use the Artifactory "npm" repository. # check if npm is installed and configure it to use the Artifactory "npm" repository.
if command -v npm >/dev/null 2>&1; then if command -v npm > /dev/null 2>&1; then
echo "📦 Configuring npm..." echo "📦 Configuring npm..."
jf npmc --global --repo-resolve "${REPOSITORY_NPM}" jf npmc --global --repo-resolve "${REPOSITORY_NPM}"
fi fi
cat <<EOF >~/.npmrc cat << EOF > ~/.npmrc
email = ${ARTIFACTORY_EMAIL} email = ${ARTIFACTORY_EMAIL}
registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}
EOF EOF
jf rt curl /api/npm/auth >>~/.npmrc jf rt curl /api/npm/auth >> ~/.npmrc
fi fi
# Configure the `pip` to use the Artifactory "python" repository. # Configure the `pip` to use the Artifactory "python" repository.
@ -41,7 +41,7 @@ else
echo "🐍 Configuring pip..." echo "🐍 Configuring pip..."
jf pipc --global --repo-resolve "${REPOSITORY_PYPI}" jf pipc --global --repo-resolve "${REPOSITORY_PYPI}"
mkdir -p ~/.pip mkdir -p ~/.pip
cat <<EOF >~/.pip/pip.conf cat << EOF > ~/.pip/pip.conf
[global] [global]
index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple
EOF EOF

@ -3,7 +3,7 @@
BOLD='\033[0;1m' BOLD='\033[0;1m'
# check if JFrog CLI is already installed # check if JFrog CLI is already installed
if command -v jf >/dev/null 2>&1; then if command -v jf > /dev/null 2>&1; then
echo "✅ JFrog CLI is already installed, skipping installation." echo "✅ JFrog CLI is already installed, skipping installation."
else else
echo "📦 Installing JFrog CLI..." echo "📦 Installing JFrog CLI..."
@ -23,15 +23,15 @@ if [ -z "${REPOSITORY_NPM}" ]; then
echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration." echo "🤔 REPOSITORY_NPM is not set, skipping npm configuration."
else else
# check if npm is installed and configure it to use the Artifactory "npm" repository. # check if npm is installed and configure it to use the Artifactory "npm" repository.
if command -v npm >/dev/null 2>&1; then if command -v npm > /dev/null 2>&1; then
echo "📦 Configuring npm..." echo "📦 Configuring npm..."
jf npmc --global --repo-resolve "${REPOSITORY_NPM}" jf npmc --global --repo-resolve "${REPOSITORY_NPM}"
fi fi
cat <<EOF >~/.npmrc cat << EOF > ~/.npmrc
email = ${ARTIFACTORY_EMAIL} email = ${ARTIFACTORY_EMAIL}
registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM} registry = ${JFROG_URL}/artifactory/api/npm/${REPOSITORY_NPM}
EOF EOF
jf rt curl /api/npm/auth >>~/.npmrc jf rt curl /api/npm/auth >> ~/.npmrc
fi fi
# Configure the `pip` to use the Artifactory "python" repository. # Configure the `pip` to use the Artifactory "python" repository.
@ -41,7 +41,7 @@ else
echo "🐍 Configuring pip..." echo "🐍 Configuring pip..."
jf pipc --global --repo-resolve "${REPOSITORY_PYPI}" jf pipc --global --repo-resolve "${REPOSITORY_PYPI}"
mkdir -p ~/.pip mkdir -p ~/.pip
cat <<EOF >~/.pip/pip.conf cat << EOF > ~/.pip/pip.conf
[global] [global]
index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple index-url = https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${JFROG_HOST}/artifactory/api/pypi/${REPOSITORY_PYPI}/simple
EOF EOF

@ -5,10 +5,10 @@ BOLD='\033[0;1m'
printf "$${BOLD}Installing jupyter-notebook!\n" printf "$${BOLD}Installing jupyter-notebook!\n"
# check if jupyter-notebook is installed # check if jupyter-notebook is installed
if ! command -v jupyter-notebook >/dev/null 2>&1; then if ! command -v jupyter-notebook > /dev/null 2>&1; then
# install jupyter-notebook # install jupyter-notebook
# check if python3 pip is installed # check if python3 pip is installed
if ! command -v pip3 >/dev/null 2>&1; then if ! command -v pip3 > /dev/null 2>&1; then
echo "pip3 is not installed" echo "pip3 is not installed"
echo "Please install pip3 in your Dockerfile/VM image before running this script" echo "Please install pip3 in your Dockerfile/VM image before running this script"
exit 1 exit 1
@ -22,4 +22,4 @@ fi
echo "👷 Starting jupyter-notebook in background..." echo "👷 Starting jupyter-notebook in background..."
echo "check logs at ${LOG_PATH}" echo "check logs at ${LOG_PATH}"
$HOME/.local/bin/jupyter notebook --NotebookApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' >${LOG_PATH} 2>&1 & $HOME/.local/bin/jupyter notebook --NotebookApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' > ${LOG_PATH} 2>&1 &

@ -5,10 +5,10 @@ BOLD='\033[0;1m'
printf "$${BOLD}Installing jupyterlab!\n" printf "$${BOLD}Installing jupyterlab!\n"
# check if jupyterlab is installed # check if jupyterlab is installed
if ! command -v jupyterlab >/dev/null 2>&1; then if ! command -v jupyterlab > /dev/null 2>&1; then
# install jupyterlab # install jupyterlab
# check if python3 pip is installed # check if python3 pip is installed
if ! command -v pip3 >/dev/null 2>&1; then if ! command -v pip3 > /dev/null 2>&1; then
echo "pip3 is not installed" echo "pip3 is not installed"
echo "Please install pip3 in your Dockerfile/VM image before running this script" echo "Please install pip3 in your Dockerfile/VM image before running this script"
exit 1 exit 1
@ -22,4 +22,4 @@ fi
echo "👷 Starting jupyterlab in background..." echo "👷 Starting jupyterlab in background..."
echo "check logs at ${LOG_PATH}" echo "check logs at ${LOG_PATH}"
$HOME/.local/bin/jupyter lab --ServerApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' >${LOG_PATH} 2>&1 & $HOME/.local/bin/jupyter lab --ServerApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' > ${LOG_PATH} 2>&1 &

@ -2,16 +2,17 @@
"name": "modules", "name": "modules",
"scripts": { "scripts": {
"test": "bun test", "test": "bun test",
"fmt": "bun x prettier -w **/*.ts **/*.md *.md && terraform fmt **/*.tf", "fmt": "bun x prettier --plugin prettier-plugin-sh -w **/*.sh .sample/run.sh new.sh **/*.ts **/*.md *.md && terraform fmt **/*.tf .sample/main.tf",
"fmt:ci": "bun x prettier --check **/*.ts **/*.md *.md && terraform fmt -check **/*.tf", "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",
"lint": "bun run lint.ts" "lint": "bun run lint.ts"
}, },
"devDependencies": { "devDependencies": {
"bun-types": "^1.0.3", "bun-types": "^1.0.18",
"gray-matter": "^4.0.3", "gray-matter": "^4.0.3",
"marked": "^9.0.3" "marked": "^11.1.0",
"prettier-plugin-sh": "^0.13.1"
}, },
"peerDependencies": { "peerDependencies": {
"typescript": "^5.0.0" "typescript": "^5.3.3"
} }
} }

@ -1,14 +1,15 @@
#!/usr/bin/env sh #!/usr/bin/env sh
PROVIDER_ID=${PROVIDER_ID} PROVIDER_ID=${PROVIDER_ID}
SLACK_MESSAGE=$(cat << "EOF" SLACK_MESSAGE=$(
cat << "EOF"
${SLACK_MESSAGE} ${SLACK_MESSAGE}
EOF EOF
) )
SLACK_URL=$${SLACK_URL:-https://slack.com} SLACK_URL=$${SLACK_URL:-https://slack.com}
usage() { usage() {
cat <<EOF cat << EOF
slackme — Send a Slack notification when a command finishes slackme — Send a Slack notification when a command finishes
Usage: slackme <command> Usage: slackme <command>
@ -74,7 +75,7 @@ START=$(date +%s%N)
# Run all arguments as a command # Run all arguments as a command
$@ $@
END=$(date +%s%N) END=$(date +%s%N)
DURATION_MS=$${DURATION_MS:-$(( (END - START) / 1000000 ))} DURATION_MS=$${DURATION_MS:-$(((END - START) / 1000000))}
PRETTY_DURATION=$(pretty_duration $DURATION_MS) PRETTY_DURATION=$(pretty_duration $DURATION_MS)
set -e set -e

@ -18,4 +18,4 @@ printf "🥳 vscode-cli has been installed.\n\n"
echo "👷 Running ${INSTALL_DIR}/bin/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms in the background..." echo "👷 Running ${INSTALL_DIR}/bin/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms in the background..."
echo "Check logs at ${LOG_PATH}!" echo "Check logs at ${LOG_PATH}!"
${INSTALL_DIR}/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms >${LOG_PATH} 2>&1 & ${INSTALL_DIR}/code serve-web --port ${PORT} --without-connection-token --accept-server-license-terms > ${LOG_PATH} 2>&1 &

Loading…
Cancel
Save