releasing.bash 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/usr/bin/env bash
  2. export BROWSH_VERSION
  3. export LATEST_TAGGED_VERSION
  4. function _goreleaser_production() {
  5. if ! command -v goreleaser &>/dev/null; then
  6. echo "Installing \`goreleaser'..."
  7. go install github.com/goreleaser/goreleaser@v"$GORELEASER_VERSION"
  8. fi
  9. pushd "$PROJECT_ROOT"/interfacer || _panic
  10. _export_versions
  11. [ "$BROWSH_VERSION" = "" ] && _panic "BROWSH_VERSION unset (goreleaser needs it)"
  12. goreleaser release \
  13. --config "$PROJECT_ROOT"/goreleaser.yml \
  14. --rm-dist
  15. popd || _panic
  16. }
  17. function _export_versions() {
  18. BROWSH_VERSION=$(_parse_browsh_version)
  19. LATEST_TAGGED_VERSION=$(
  20. git tag --sort=v:refname --list 'v*.*.*' | tail -n1 | sed -e "s/^v//"
  21. )
  22. }
  23. function _parse_browsh_version() {
  24. local version_file=$PROJECT_ROOT/interfacer/src/browsh/version.go
  25. local line && line=$(grep 'browshVersion' <"$version_file")
  26. local version && version=$(echo "$line" | grep -o '".*"' | sed 's/"//g')
  27. echo -n "$version"
  28. }
  29. function _is_new_version() {
  30. _export_versions
  31. [ "$BROWSH_VERSION" = "" ] && _panic "BROWSH_VERSION unset"
  32. [ "$LATEST_TAGGED_VERSION" = "" ] && _panic "LATEST_TAGGED_VERSION unset"
  33. [[ "$BROWSH_VERSION" != "$LATEST_TAGGED_VERSION" ]]
  34. }
  35. function _tag_on_version_change() {
  36. _export_versions
  37. echo_versions
  38. if ! _is_new_version; then
  39. echo "Not tagging as there's no new version."
  40. exit 0
  41. fi
  42. git tag v"$BROWSH_VERSION"
  43. git show v"$BROWSH_VERSION" --quiet
  44. git config --global user.email "ci@github.com"
  45. git config --global user.name "Github Actions"
  46. git add --all
  47. git reset --hard v"$BROWSH_VERSION"
  48. }
  49. function echo_versions() {
  50. _export_versions
  51. echo "Browsh binary version: $BROWSH_VERSION"
  52. echo "Git latest tag: $LATEST_TAGGED_VERSION"
  53. }
  54. function browsh_version() {
  55. _export_versions
  56. echo -n "$BROWSH_VERSION"
  57. }
  58. function github_actions_output_version_status() {
  59. local status="false"
  60. if _is_new_version; then
  61. status="true"
  62. fi
  63. echo "::set-output name=is_new_version::$status"
  64. }
  65. function webext_build_release() {
  66. pushd "$PROJECT_ROOT"/webext || _panic
  67. build_webextension_production
  68. popd || _panic
  69. }
  70. function update_browsh_website_with_new_version() {
  71. _export_versions
  72. local remote="git@github.com:browsh-org/www.brow.sh.git"
  73. pushd /tmp || _panic
  74. git clone "$remote"
  75. cd www.brow.sh || _panic
  76. echo "latest_version: $BROWSH_VERSION" >_data/browsh.yml
  77. git add _data/browsh.yml
  78. git commit -m "Github Actions: updated Browsh version to $BROWSH_VERSION"
  79. git push "$remote"
  80. popd || _panic
  81. }
  82. function update_homebrew_tap_with_new_version() {
  83. _export_versions
  84. local remote="git@github.com:browsh-org/homebrew-browsh.git"
  85. pushd /tmp || _panic
  86. git clone "$remote"
  87. cd homebrew-browsh || _panic
  88. cp -f "$PROJECT_ROOT"/interfacer/dist/browsh.rb browsh.rb
  89. git add browsh.rb
  90. git commit -m "Github Actions: updated to $BROWSH_VERSION"
  91. git push "$remote"
  92. popd || _panic
  93. }
  94. function goreleaser_local_only() {
  95. pushd "$PROJECT_ROOT"/interfacer || _panic
  96. goreleaser release \
  97. --config "$PROJECT_ROOT"/goreleaser.yml \
  98. --snapshot \
  99. --rm-dist
  100. popd || _panic
  101. }
  102. function build_browsh_binary() {
  103. # Requires $path argument because it's used in the Dockerfile where the GOROOT is
  104. # outside .git/
  105. local path=$1
  106. pushd "$path" || _panic
  107. local webextension="src/browsh/browsh.xpi"
  108. [ ! -f "$webextension" ] && _panic "browsh.xpi not present"
  109. md5sum "$webextension"
  110. go build ./cmd/browsh
  111. echo "Freshly built \`browsh' version: $(./browsh --version 2>&1)"
  112. popd || _panic
  113. }
  114. function release() {
  115. [ "$(git rev-parse --abbrev-ref HEAD)" != "master" ] && _panic "Not releasing unless on the master branch"
  116. webext_build_release
  117. build_browsh_binary "$PROJECT_ROOT"/interfacer
  118. _tag_on_version_change
  119. _goreleaser_production
  120. }