feat(formatting): add prettier-plugin-sh

This commit is contained in:
Julien Neuhart
2025-03-02 18:04:21 +01:00
parent 536d3ee70d
commit 820b914291
10 changed files with 144 additions and 88 deletions
+1 -1
View File
@@ -1 +1 @@
.git .git
+3 -3
View File
@@ -5,9 +5,9 @@ GOTENBERG_VERSION=snapshot
GOTENBERG_USER_GID=1001 GOTENBERG_USER_GID=1001
GOTENBERG_USER_UID=1001 GOTENBERG_USER_UID=1001
NOTO_COLOR_EMOJI_VERSION=v2.047 # See https://github.com/googlefonts/noto-emoji/releases. NOTO_COLOR_EMOJI_VERSION=v2.047 # See https://github.com/googlefonts/noto-emoji/releases.
PDFTK_VERSION=v3.3.3 # See https://gitlab.com/pdftk-java/pdftk/-/releases - Binary package. PDFTK_VERSION=v3.3.3 # See https://gitlab.com/pdftk-java/pdftk/-/releases - Binary package.
PDFCPU_VERSION=v0.8.1 # See https://github.com/pdfcpu/pdfcpu/releases. PDFCPU_VERSION=v0.8.1 # See https://github.com/pdfcpu/pdfcpu/releases.
GOLANGCI_LINT_VERSION=v1.64.2 # See https://github.com/golangci/golangci-lint/releases. GOLANGCI_LINT_VERSION=v1.64.2 # See https://github.com/golangci/golangci-lint/releases.
GOTENBERG_VERSION=snapshot GOTENBERG_VERSION=snapshot
DOCKERFILE=build/Dockerfile DOCKERFILE=build/Dockerfile
DOCKERFILE_CLOUDRUN=build/Dockerfile.cloudrun DOCKERFILE_CLOUDRUN=build/Dockerfile.cloudrun
+13 -13
View File
@@ -16,7 +16,7 @@ dry_run=""
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
--version) --version)
version="${2//v}" version="${2//v/}"
shift 2 shift 2
;; ;;
--platform) --platform)
@@ -47,11 +47,11 @@ echo "Target platform: $platform"
if [ -n "$alternate_repository" ]; then if [ -n "$alternate_repository" ]; then
DOCKER_REPOSITORY=$alternate_repository DOCKER_REPOSITORY=$alternate_repository
echo "⚠️ Using $alternate_repository for DOCKER_REPOSITORY" echo "⚠️ Using $alternate_repository for DOCKER_REPOSITORY"
fi fi
if [ "$dry_run" = "true" ]; then if [ "$dry_run" = "true" ]; then
echo "🚧 Dry run" echo "🚧 Dry run"
fi fi
# Build tags arrays. # Build tags arrays.
tags=() tags=()
@@ -142,20 +142,20 @@ cmd="docker buildx build \
run_cmd "$cmd" run_cmd "$cmd"
if [ "$platform" != "linux/amd64" ]; then if [ "$platform" != "linux/amd64" ]; then
echo "⚠️ Skip Cloud Run variant(s)" echo "⚠️ Skip Cloud Run variant(s)"
echo "✅ Done!" echo "✅ Done!"
echo "tags=$(join "," "${tags[@]}")" >> "$GITHUB_OUTPUT" echo "tags=$(join "," "${tags[@]}")" >> "$GITHUB_OUTPUT"
echo "tags_cloud_run=$(join "," "${tags_cloud_run[@]}")" >> "$GITHUB_OUTPUT" echo "tags_cloud_run=$(join "," "${tags_cloud_run[@]}")" >> "$GITHUB_OUTPUT"
exit 0 exit 0
fi fi
source_tag_cloud_run="$DOCKER_REGISTRY/$DOCKER_REPOSITORY:$version-${arch[1]}" source_tag_cloud_run="$DOCKER_REGISTRY/$DOCKER_REPOSITORY:$version-${arch[1]}"
cmd="docker pull $source_tag_cloud_run" cmd="docker pull $source_tag_cloud_run"
run_cmd "$cmd" run_cmd "$cmd"
target_tag_cloud_run="$DOCKER_REGISTRY/$DOCKER_REPOSITORY:$version" target_tag_cloud_run="$DOCKER_REGISTRY/$DOCKER_REPOSITORY:$version"
cmd="docker image tag $source_tag_cloud_run $target_tag_cloud_run" cmd="docker image tag $source_tag_cloud_run $target_tag_cloud_run"
run_cmd "$cmd" run_cmd "$cmd"
cmd="docker build \ cmd="docker build \
--build-arg DOCKER_REGISTRY=$DOCKER_REGISTRY \ --build-arg DOCKER_REGISTRY=$DOCKER_REGISTRY \
+38 -38
View File
@@ -19,7 +19,7 @@ while [[ $# -gt 0 ]]; do
shift 2 shift 2
;; ;;
--snapshot-version) --snapshot-version)
snapshot_version="${2//v}" snapshot_version="${2//v/}"
shift 2 shift 2
;; ;;
--dry-run) --dry-run)
@@ -47,9 +47,9 @@ for tag in "${tags_to_delete[@]}"; do
echo "- $tag" echo "- $tag"
done done
if [ "$dry_run" = "true" ]; then if [ "$dry_run" = "true" ]; then
echo "🚧 Dry run" echo "🚧 Dry run"
fi fi
echo echo
# Delete tags. # Delete tags.
@@ -61,28 +61,28 @@ if [ "$dry_run" = "true" ]; then
echo "🚧 Dry run - would call $base_url to get a token" echo "🚧 Dry run - would call $base_url to get a token"
echo echo
else else
echo "🌐 Get token from $base_url" echo "🌐 Get token from $base_url"
readarray -t lines < <( readarray -t lines < <(
curl -s -X POST \ curl -s -X POST \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "{\"username\":\"$DOCKERHUB_USERNAME\", \"password\":\"$DOCKERHUB_TOKEN\"}" \ -d "{\"username\":\"$DOCKERHUB_USERNAME\", \"password\":\"$DOCKERHUB_TOKEN\"}" \
-w "\n%{http_code}" \ -w "\n%{http_code}" \
"$base_url/users/login" "$base_url/users/login"
) )
http_code="${lines[-1]}" http_code="${lines[-1]}"
unset 'lines[-1]' unset 'lines[-1]'
json_body=$(printf "%s\n" "${lines[@]}") json_body=$(printf "%s\n" "${lines[@]}")
if [ "$http_code" -ne "200" ]; then if [ "$http_code" -ne "200" ]; then
echo "❌ Wrong HTTP status - $http_code" echo "❌ Wrong HTTP status - $http_code"
echo "$json_body" echo "$json_body"
exit 1 exit 1
fi fi
token=$(jq -r '.token' <<< "$json_body") token=$(jq -r '.token' <<< "$json_body")
echo echo
fi fi
if [ -z "$token" ]; then if [ -z "$token" ]; then
@@ -95,26 +95,26 @@ for tag in "${tags_to_delete[@]}"; do
echo "🚧 Dry run - would call $base_url to delete tag $tag" echo "🚧 Dry run - would call $base_url to delete tag $tag"
echo echo
else else
echo "🌐 Delete tag $tag" echo "🌐 Delete tag $tag"
IFS=':' read -ra tag_parts <<< "$tag" IFS=':' read -ra tag_parts <<< "$tag"
readarray -t lines < <( readarray -t lines < <(
curl -s -X DELETE \ curl -s -X DELETE \
-H "Authorization: Bearer $token" \ -H "Authorization: Bearer $token" \
-w "\n%{http_code}" \ -w "\n%{http_code}" \
"$base_url/repositories/${tag_parts[0]}/tags/${tag_parts[1]}/" "$base_url/repositories/${tag_parts[0]}/tags/${tag_parts[1]}/"
) )
http_code="${lines[-1]}" http_code="${lines[-1]}"
unset 'lines[-1]' unset 'lines[-1]'
if [ "$http_code" -ne "200" ] && [ "$http_code" -ne "204" ]; then if [ "$http_code" -ne "200" ] && [ "$http_code" -ne "204" ]; then
echo "❌ Wrong HTTP status - $http_code" echo "❌ Wrong HTTP status - $http_code"
printf '%s\n' "${lines[@]}" printf '%s\n' "${lines[@]}"
exit 1 exit 1
fi fi
echo echo
fi fi
done done
+27 -28
View File
@@ -46,23 +46,23 @@ if [ -n "$alternate_registry" ]; then
echo "⚠️ Will also push to $alternate_registry registry" echo "⚠️ Will also push to $alternate_registry registry"
fi fi
if [ "$dry_run" = "true" ]; then if [ "$dry_run" = "true" ]; then
echo "🚧 Dry run" echo "🚧 Dry run"
fi fi
echo echo
# Build merge map. # Build merge map.
declare -A merge_map declare -A merge_map
for tag in "${tags_to_merge[@]}"; do for tag in "${tags_to_merge[@]}"; do
target_tag="${tag//-amd64/}" target_tag="${tag//-amd64/}"
target_tag="${target_tag//-arm64/}" target_tag="${target_tag//-arm64/}"
target_tag="${target_tag//-arm/}" target_tag="${target_tag//-arm/}"
target_tag="${target_tag//-386/}" target_tag="${target_tag//-386/}"
merge_map["$target_tag"]+="$tag " merge_map["$target_tag"]+="$tag "
done done
# Merge tags. # Merge tags.
run_cmd() { run_cmd() {
@@ -80,30 +80,29 @@ run_cmd() {
fi fi
} }
for target in "${!merge_map[@]}"; do for target in "${!merge_map[@]}"; do
IFS=' ' read -ra source_tags <<< "${merge_map[$target]}" IFS=' ' read -ra source_tags <<< "${merge_map[$target]}"
cmd="docker buildx imagetools create \ cmd="docker buildx imagetools create \
-t $target \ -t $target \
${source_tags[*]} ${source_tags[*]}
" "
run_cmd "$cmd" run_cmd "$cmd"
echo "➡️ $target pushed" echo "➡️ $target pushed"
echo echo
if [ -n "$alternate_registry" ]; then if [ -n "$alternate_registry" ]; then
alternate_target="${target/$DOCKER_REGISTRY/$alternate_registry}" alternate_target="${target/$DOCKER_REGISTRY/$alternate_registry}"
cmd="docker buildx imagetools create \ cmd="docker buildx imagetools create \
-t $alternate_target \ -t $alternate_target \
$target $target
" "
run_cmd "$cmd" run_cmd "$cmd"
echo "➡️ $alternate_target pushed"
echo
fi
done
echo "➡️ $alternate_target pushed"
echo
fi
done
echo "✅ Done!" echo "✅ Done!"
exit 0 exit 0
+1
View File
@@ -0,0 +1 @@
build
+1 -1
View File
@@ -1,3 +1,3 @@
{ {
"plugins": ["prettier-plugin-gherkin"] "plugins": ["prettier-plugin-gherkin", "prettier-plugin-sh"]
} }
+6 -2
View File
@@ -188,19 +188,23 @@ tests-integration: ## Run integration tests
go test -tags=integration -v github.com/gotenberg/gotenberg/v8/test/integration go test -tags=integration -v github.com/gotenberg/gotenberg/v8/test/integration
.PHONY: lint .PHONY: lint
lint: ## Lint the code. lint: ## Lint codebase.
#golangci-lint run #golangci-lint run
npx prettier --check . npx prettier --check .
# go install mvdan.cc/gofumpt@latest # go install mvdan.cc/gofumpt@latest
# go install github.com/daixiang0/gci@latest # go install github.com/daixiang0/gci@latest
.PHONY: fmt .PHONY: fmt
fmt: ## Format the code and "optimize" the dependencies fmt: ## Format codebase and "optimize" the dependencies
gofumpt -l -w . gofumpt -l -w .
gci write -s standard -s default -s "prefix(github.com/gotenberg/gotenberg/v8)" --skip-generated --skip-vendor --custom-order . gci write -s standard -s default -s "prefix(github.com/gotenberg/gotenberg/v8)" --skip-generated --skip-vendor --custom-order .
npx prettier --write . npx prettier --write .
go mod tidy go mod tidy
.PHONY: todo
todo: ## Find TODOs in codebase.
golangci-lint run --no-config --disable-all --enable godox
# go install golang.org/x/tools/cmd/godoc@latest # go install golang.org/x/tools/cmd/godoc@latest
.PHONY: godoc .PHONY: godoc
godoc: ## Run a webserver with Gotenberg godoc godoc: ## Run a webserver with Gotenberg godoc
+52 -1
View File
@@ -6,7 +6,8 @@
"": { "": {
"devDependencies": { "devDependencies": {
"prettier": "3.5.2", "prettier": "3.5.2",
"prettier-plugin-gherkin": "^3.1.1" "prettier-plugin-gherkin": "^3.1.1",
"prettier-plugin-sh": "^0.15.0"
} }
}, },
"node_modules/@cucumber/gherkin": { "node_modules/@cucumber/gherkin": {
@@ -76,6 +77,13 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/mvdan-sh": {
"version": "0.10.1",
"resolved": "https://registry.npmjs.org/mvdan-sh/-/mvdan-sh-0.10.1.tgz",
"integrity": "sha512-kMbrH0EObaKmK3nVRKUIIya1dpASHIEusM13S4V1ViHFuxuNxCo+arxoa6j/dbV22YBGjl7UKJm9QQKJ2Crzhg==",
"dev": true,
"license": "BSD-3-Clause"
},
"node_modules/prettier": { "node_modules/prettier": {
"version": "3.5.2", "version": "3.5.2",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.2.tgz", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.2.tgz",
@@ -104,6 +112,26 @@
"prettier": "^3.0.0" "prettier": "^3.0.0"
} }
}, },
"node_modules/prettier-plugin-sh": {
"version": "0.15.0",
"resolved": "https://registry.npmjs.org/prettier-plugin-sh/-/prettier-plugin-sh-0.15.0.tgz",
"integrity": "sha512-U0PikJr/yr2bzzARl43qI0mApBj0C1xdAfA04AZa6LnvIKawXHhuy2fFo6LNA7weRzGlAiNbaEFfKMFo0nZr/A==",
"dev": true,
"license": "MIT",
"dependencies": {
"mvdan-sh": "^0.10.1",
"sh-syntax": "^0.4.2"
},
"engines": {
"node": ">=16.0.0"
},
"funding": {
"url": "https://opencollective.com/unts"
},
"peerDependencies": {
"prettier": "^3.0.3"
}
},
"node_modules/reflect-metadata": { "node_modules/reflect-metadata": {
"version": "0.1.13", "version": "0.1.13",
"resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz",
@@ -111,6 +139,29 @@
"dev": true, "dev": true,
"license": "Apache-2.0" "license": "Apache-2.0"
}, },
"node_modules/sh-syntax": {
"version": "0.4.2",
"resolved": "https://registry.npmjs.org/sh-syntax/-/sh-syntax-0.4.2.tgz",
"integrity": "sha512-/l2UZ5fhGZLVZa16XQM9/Vq/hezGGbdHeVEA01uWjOL1+7Ek/gt6FquW0iKKws4a9AYPYvlz6RyVvjh3JxOteg==",
"dev": true,
"license": "MIT",
"dependencies": {
"tslib": "^2.6.2"
},
"engines": {
"node": ">=16.0.0"
},
"funding": {
"url": "https://opencollective.com/unts"
}
},
"node_modules/tslib": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"dev": true,
"license": "0BSD"
},
"node_modules/uuid": { "node_modules/uuid": {
"version": "9.0.1", "version": "9.0.1",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
+2 -1
View File
@@ -1,6 +1,7 @@
{ {
"devDependencies": { "devDependencies": {
"prettier": "3.5.2", "prettier": "3.5.2",
"prettier-plugin-gherkin": "^3.1.1" "prettier-plugin-gherkin": "^3.1.1",
"prettier-plugin-sh": "^0.15.0"
} }
} }