misc.bash 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env bash
  2. function golang_lint_check() {
  3. pushd "$PROJECT_ROOT"/interfacer || _panic
  4. diff -u <(echo -n) <(gofmt -d ./)
  5. popd || _panic
  6. }
  7. function golang_lint_fix() {
  8. gofmt -w ./interfacer
  9. }
  10. function prettier_fix() {
  11. pushd "$PROJECT_ROOT"/webext || _panic
  12. prettier --write '{src,test}/**/*.js'
  13. popd || _panic
  14. }
  15. function parse_firefox_version_from_ci_config() {
  16. local line && line=$(grep 'firefox-version:' <"$PROJECT_ROOT"/.github/workflows/main.yml)
  17. local version && version=$(echo "$line" | tr -s ' ' | cut -d ' ' -f 3)
  18. [ "$version" = "" ] && _panic "Couldn't parse Firefox version"
  19. echo -n "$version"
  20. }
  21. function install_firefox() {
  22. local version && version=$(parse_firefox_version_from_ci_config)
  23. local destination=/tmp
  24. echo "Installing Firefox v$version to $destination..."
  25. mkdir -p "$destination"
  26. pushd "$destination" || _panic
  27. curl -L -o firefox.tar.bz2 \
  28. "https://ftp.mozilla.org/pub/firefox/releases/$version/linux-x86_64/en-US/firefox-$version.tar.bz2"
  29. bzip2 -d firefox.tar.bz2
  30. tar xf firefox.tar
  31. popd || _panic
  32. }
  33. function parse_golang_version_from_go_mod() {
  34. local path=$1
  35. [ "$path" = "" ] && _panic "Path to Golang interfacer code not passed"
  36. local line && line=$(grep '^go ' <"$path"/go.mod)
  37. local version && version=$(echo "$line" | tr -s ' ' | cut -d ' ' -f 2)
  38. [ "$(echo "$version" | tr -s ' ')" == "" ] && _panic "Couldn't parse Golang version"
  39. echo -n "$version"
  40. }
  41. function install_golang() {
  42. local path=$1
  43. [ "$path" = "" ] && _panic "Path to Golang interfacer code not passed"
  44. local version && version=$(parse_golang_version_from_go_mod "$path")
  45. [ "$GOPATH" = "" ] && _panic "GOPATH not set"
  46. [ "$GOROOT" = "" ] && _panic "GOROOT not set"
  47. GOARCH=$(uname -m)
  48. [[ $GOARCH == aarch64 ]] && GOARCH=arm64
  49. [[ $GOARCH == x86_64 ]] && GOARCH=amd64
  50. url=https://dl.google.com/go/go"$version".linux-"$GOARCH".tar.gz
  51. echo "Installing Golang ($url)... to $GOROOT"
  52. curl -L \
  53. -o go.tar.gz \
  54. "$url"
  55. mkdir -p "$GOPATH"/bin
  56. mkdir -p "$GOROOT"
  57. tar -C "$GOROOT/.." -xzf go.tar.gz
  58. go version
  59. }