Skip to content

Commit

Permalink
devops: Move random scripts into central ctl.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
tombh committed Jul 16, 2022
1 parent 77fd0e6 commit f34ccc7
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 243 deletions.
49 changes: 0 additions & 49 deletions contrib/release_if_new_version.sh

This file was deleted.

65 changes: 0 additions & 65 deletions contrib/upload_github_release_asset.sh

This file was deleted.

29 changes: 29 additions & 0 deletions ctl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/env bash
set -e

function_to_run=$1

export PROJECT_ROOT && PROJECT_ROOT=$(git rev-parse --show-toplevel)
export GORELEASER_VERSION=1.10.2
export GOBINDATA_VERSION=3.23.0

function _includes_path {
echo "$PROJECT_ROOT"/scripts
}

function _load_includes {
for file in "$(_includes_path)"/*.bash; do
# shellcheck disable=1090
source "$file"
done
}

_load_includes

if [[ $(type -t "$function_to_run") != function ]]; then
echo "Subcommand: '$function_to_run' not found."
exit 1
fi

shift
"$function_to_run" "$@"
37 changes: 0 additions & 37 deletions interfacer/contrib/build_browsh.sh

This file was deleted.

9 changes: 0 additions & 9 deletions interfacer/contrib/get_browsh_version.sh

This file was deleted.

15 changes: 0 additions & 15 deletions interfacer/contrib/xpi2bin.sh

This file was deleted.

78 changes: 78 additions & 0 deletions scripts/bundling.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash

export WEBEXTENSION_GO=$PROJECT_ROOT/interfacer/src/browsh/webextension.go
export GOBINDATA_VERSION=3.23.0

# Convert the web extension into binary data that can be compiled into a
# cross-platform Go binary.
function xpi_to_bin() {
local xpi_file=$1
local bin_file=$2

if ! command -v go-bindata &>/dev/null; then
echo "Installing \`go-bindata'..."
go install github.com/kevinburke/go-bindata/go-bindata@v"$GOBINDATA_VERSION"
go-bindata -version
fi

go-bindata \
-nocompress \
-prefix "$PROJECT_ROOT/interfacer" \
-pkg browsh \
-o "$bin_file" \
"$xpi_file"

ls -alh "$WEBEXTENSION_GO"
}

function build_webextension() {
local NODE_BIN=$PROJECT_ROOT/webext/node_modules/.bin

cd "$PROJECT_ROOT"/webext && "$NODE_BIN"/webpack
cd "$PROJECT_ROOT"/webext/dist && rm ./*.map
if [ -f core ]; then
# Is this a core dump for some failed process?
rm core
fi
ls -alh .
"$NODE_BIN"/web-ext build --overwrite-dest
ls -alh web-ext-artifacts

version=$("$PROJECT_ROOT"/ctl.sh browsh_version)

local xpi_file=browsh-$version-an+fx.xpi
local zip_file=browsh-$version.zip
local source_dir=$PROJECT_ROOT/webext/dist/web-ext-artifacts

if [ "$BROWSH_ENV" == "RELEASE" ]; then
# The signed version. There can only be one canonical XPI for each semantic
# version.
source_file=$source_dir/$xpi_file
bundle_file=$PROJECT_ROOT/interfacer/browsh.xpi
"$NODE_BIN"/web-ext sign --api-key "$MDN_USER" --api-secret "$MDN_KEY"
else
# TODO: This doesn't currently work with the Marionettte `tempAddon`
# installation method. Just use `web-ext run` and Browsh's `use-existing-ff`
# flag - which is better anyway as it auto-reloads the extension when files
# change. NB: If you fix this, don't forget to change the filename loaded
# by `Asset()` in `main.go`.
# In development/testing, we want to be able to bundle the webextension
# frequently without having to resort to version bumps.
source_file=$source_dir/$zip_file
bundle_file=$source_dir/browsh.zip
fi

cp -f "$source_file" "$bundle_file"
echo "Bundling $source_file to $WEBEXTENSION_GO using internal path $bundle_file"
xpi2bin "$bundle_file" "$WEBEXTENSION_GO"
}

function bundle_production_webextension() {
local version && version=$(browsh_version)
local base='https://github.com/browsh-org/browsh/releases/download'
local release_url="$base/v$version/browsh-$version-an.fx.xpi"
local xpi_file=$PROJECT_ROOT/interfacer/src/browsh/browsh.xpi
curl -L -o "$xpi_file" "$release_url"

xpi2bin "$xpi_file" "$WEBEXTENSION_GO"
}
7 changes: 7 additions & 0 deletions scripts/common.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/env bash

function _panic() {
local message=$1
echo >&2 "$message"
exit 1
}
11 changes: 11 additions & 0 deletions scripts/misc.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/env bash

function golang_lint_check() {
pushd "$PROJECT_ROOT"/interfacer || _panic
diff -u <(echo -n) <(gofmt -d ./)
popd || _panic
}

function golang_lint_fix() {
gofmt -f ./interfacer
}
Loading

0 comments on commit f34ccc7

Please sign in to comment.