Skip to content

Commit

Permalink
Fixes for invoke-mermaid.sh and invoke-bikeshed.sh (gpuweb#4671)
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x authored May 25, 2024
1 parent ac2dda6 commit e8430a9
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion tools/check-repo-clean.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -eo pipefail
set -euo pipefail

status=$(git status -s)

Expand Down
2 changes: 1 addition & 1 deletion tools/copy-if-different.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -eo pipefail
set -euo pipefail

usage()
{
Expand Down
2 changes: 1 addition & 1 deletion tools/custom-action/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash --login
set -eo pipefail
set -euo pipefail

source /prepare.sh # Execute the prepare script
git init # To ensure subsequent git commands pick the workspace
Expand Down
2 changes: 1 addition & 1 deletion tools/custom-action/prepare.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -eo pipefail
set -euo pipefail

source /dependency-versions.sh # Source dependency versions
cp -r /grammar ./wgsl/
Expand Down
2 changes: 1 addition & 1 deletion tools/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -eo pipefail
set -euo pipefail
source ./tools/custom-action/dependency-versions.sh # Source dependency versions

code=1
Expand Down
24 changes: 14 additions & 10 deletions tools/invoke-bikeshed.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -eo pipefail
set -euo pipefail

if [ $# -lt 1 ] ; then
echo "Usage: $0 output.html SOURCE_FILES..."
Expand All @@ -19,38 +19,42 @@ output="$1"
shift
# now $@ is the list of input files

if type bikeshed >/dev/null && [ -z "$BIKESHED_DISALLOW_LOCAL" ] ; then
if type bikeshed >/dev/null && [ -z "${BIKESHED_DISALLOW_LOCAL:=}" ] ; then
# Build using locally-installed bikeshed.
# Always build using the tarfile build, to ensure that it never breaks.
if [ "$DIE_ON" ] ; then
opts="--die-on=$DIE_ON"

opts=()
if [ "${DIE_ON:=}" ] ; then
opts+=("--die-on=$DIE_ON")
fi

# Use a temporary file because Bikeshed won't check for tarfiles on stdin.
tmp_tar=$(mktemp)
trap 'rm -f -- "$tmp_tar"' EXIT

tar cf "$tmp_tar" "$@"
bikeshed $opts spec "$tmp_tar" "$output"
bikeshed "${opts[@]}" spec "$tmp_tar" "$output"
exit
elif [ -z "$BIKESHED_DISALLOW_ONLINE" ] ; then
elif [ -z "${BIKESHED_DISALLOW_ONLINE:=}" ] ; then
# Build using Bikeshed API.
echo 'Local bikeshed not found. Falling back to Bikeshed API.'

tmp_body=$(mktemp) # Contains response body
tmp_headers=$(mktemp) # Contains response headers
trap 'rm -f -- "$tmp_body" "$tmp_headers"' EXIT

if [ "$DIE_ON" ] ; then
opts="-Fdie-on=$DIE_ON"
opts=()
if [ "${DIE_ON:=}" ] ; then
opts+=("--form" "die-on=$DIE_ON")
fi
tar c "$@" | curl -s https://api.csswg.org/bikeshed/ -Ffile=@- "$opts" -o"$tmp_body" -D"$tmp_headers"
tar c "$@" | curl --silent https://api.csswg.org/bikeshed/ --form "file=@-" "${opts[@]}" --output "$tmp_body" --dump-header "$tmp_headers"

if grep -q '^HTTP/1.1 200' "$tmp_headers" ; then
if head --lines=1 "$tmp_headers" | grep --quiet '\<200\>' ; then
# If successful, write to output file
cat "$tmp_body" > "$output"
exit
else
cat "$tmp_headers"
# If unsuccessful, print the errors on stdout
cat "$tmp_body" >&2
exit 1
Expand Down
19 changes: 9 additions & 10 deletions tools/invoke-mermaid.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -eo pipefail
set -euo pipefail
source ../tools/custom-action/dependency-versions.sh # Source dependency versions

cfg_file=$(dirname "$0")/mermaid.json
Expand All @@ -8,16 +8,15 @@ cfg_puppeteer_file=$(dirname "$0")/mermaid-puppeteer.json
# This script is meant to be run in parallel with itself, so it uses --no to
# disable the prompt to install new packages (and avoid npx racing with itself).
# Use tools/install-dependencies.sh to install the package explicitly.
npx --no -- @mermaid-js/mermaid-cli@$NPM_MERMAID_CLI_VERSION --puppeteerConfigFile "$cfg_puppeteer_file" --backgroundColor black --configFile "$cfg_file" "$@"
ret=$?

if [ "$ret" != 0 ]; then
echo '**************** Mermaid is not installed. *****************'
echo '*** Please run `tools/install-dependencies.sh diagrams`. ***'
if [ -n "$REQUIRE_DIAGRAM_GENERATION" ]; then
npx --no -- @mermaid-js/mermaid-cli@$NPM_MERMAID_CLI_VERSION --puppeteerConfigFile "$cfg_puppeteer_file" --backgroundColor black --configFile "$cfg_file" "$@" || {
echo
echo '**************** Mermaid is not installed. *****************'
echo '*** Please run `tools/install-dependencies.sh diagrams`. ***'
if [ -n "${REQUIRE_DIAGRAM_GENERATION:=}" ]; then
echo '**** Failing because REQUIRE_DIAGRAM_GENERATION is set. ****'
exit "$ret"
exit 1
else
echo '********** Skipping mermaid diagram regeneration. **********'
fi
fi
echo
}
2 changes: 1 addition & 1 deletion tools/populate-out.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# This is called from the repository root. Populates out/ with everything to
# publish on GitHub Pages and PR previews.
set -eo pipefail
set -euo pipefail

mkdir -p out/{wgsl,wgsl/grammar,explainer,correspondence}

Expand Down

0 comments on commit e8430a9

Please sign in to comment.