release 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. python3 -m build
  29. twine upload -r pypi --username __token__ dist/borgmatic-*.tar.gz
  30. twine upload -r pypi --username __token__ dist/borgmatic-*-py3-none-any.whl
  31. # Set release changelogs on projects.torsion.org and GitHub.
  32. release_changelog="$(cat NEWS | sed '/^$/q' | grep -v '^\S')"
  33. escaped_release_changelog="$(echo "$release_changelog" | sed -z 's/\n/\\n/g' | sed -z 's/\"/\\"/g')"
  34. curl --silent --request POST \
  35. "https://projects.torsion.org/api/v1/repos/borgmatic-collective/borgmatic/releases" \
  36. --header "Authorization: token $projects_token" \
  37. --header "Accept: application/json" \
  38. --header "Content-Type: application/json" \
  39. --data "{\"body\": \"$escaped_release_changelog\", \"draft\": false, \"name\": \"borgmatic $version\", \"prerelease\": false, \"tag_name\": \"$version\"}"
  40. github-release create --token="$github_token" --owner=witten --repo=borgmatic --tag="$version" --target_commit="main" \
  41. --name="borgmatic $version" --body="$release_changelog"