release 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. set -e
  3. projects_token=${1:-}
  4. github_token=${2:-}
  5. if [[ -z $github_token ]]; then
  6. echo "Usage: $0 [projects-token] [github-token]"
  7. exit 1
  8. fi
  9. if [[ ! -f NEWS ]]; then
  10. echo "Missing NEWS file. Try running from root of repository."
  11. exit 1
  12. fi
  13. version=$(head --lines=1 NEWS)
  14. if [[ $version =~ .*dev* ]]; then
  15. echo "Refusing to release a dev version: $version"
  16. exit 1
  17. fi
  18. if ! git diff-index --quiet HEAD -- ; then
  19. echo "Refusing to release with local changes:"
  20. git status --porcelain
  21. exit 1
  22. fi
  23. git tag $version
  24. git push origin $version
  25. git push github $version
  26. # Build borgmatic and publish to pypi.
  27. rm -fr dist
  28. uv build
  29. tarball_path="dist/borgmatic-$version.tar.gz"
  30. wheel_path=$(ls dist/borgmatic-*-py3-none-any.whl)
  31. twine upload -r pypi --username __token__ "$tarball_path"
  32. twine upload -r pypi --username __token__ "$wheel_path"
  33. # Build docs and extract HTML.
  34. scripts/export-docs-from-image
  35. docs_path=dist/borgmatic-docs.tar.gz
  36. # Set release changelogs on projects.torsion.org and GitHub.
  37. release_changelog="$(cat NEWS | sed '/^$/q' | grep -v '^\S')"
  38. escaped_release_changelog="$(echo "$release_changelog" | sed -z 's/\n/\\n/g' | sed -z 's/\"/\\"/g')"
  39. release_id=$(curl --silent --request POST \
  40. "https://projects.torsion.org/api/v1/repos/borgmatic-collective/borgmatic/releases" \
  41. --header "Authorization: token $projects_token" \
  42. --header "Accept: application/json" \
  43. --header "Content-Type: application/json" \
  44. --data "{\"body\": \"$escaped_release_changelog\", \"draft\": false, \"name\": \"borgmatic $version\", \"prerelease\": false, \"tag_name\": \"$version\"}" \
  45. | jq ".id")
  46. curl --silent --request POST \
  47. "https://projects.torsion.org/api/v1/repos/borgmatic-collective/borgmatic/releases/$release_id/assets?name=$(basename $wheel_path)" \
  48. --header "Authorization: token $projects_token" \
  49. --header "Accept: application/json" \
  50. --form attachment=@"$wheel_path"
  51. curl --silent --request POST \
  52. "https://projects.torsion.org/api/v1/repos/borgmatic-collective/borgmatic/releases/$release_id/assets?name=$(basename $tarball_path)" \
  53. --header "Authorization: token $projects_token" \
  54. --header "Accept: application/json" \
  55. --form attachment=@"$tarball_path"
  56. curl --silent --request POST \
  57. "https://projects.torsion.org/api/v1/repos/borgmatic-collective/borgmatic/releases/$release_id/assets?name=$(basename $docs_path)" \
  58. --header "Authorization: token $projects_token" \
  59. --header "Accept: application/json" \
  60. --form attachment=@"$docs_path"
  61. github-release create --token="$github_token" --owner=witten --repo=borgmatic --tag="$version" --target_commit="main" \
  62. --name="borgmatic $version" --body="$release_changelog"