diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 31143254f..580c6ba8f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,8 +7,17 @@ on: - "v*" jobs: + prepublish-check: + name: "Check that the project is releaseable" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Run checks + run: shotover-proxy/build/is_releasable.sh + publish-image: name: "Publish Docker Image to Docker Hub" + needs: prepublish-check runs-on: ubuntu-latest steps: - name: Login to Docker Hub @@ -25,6 +34,7 @@ jobs: publish-binary: name: "Publish Binary to GitHub" + needs: prepublish-check runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 @@ -39,3 +49,18 @@ jobs: prerelease: false files: | *.tar.gz + + publish-crates-io: + name: "Publish to crates.io" + needs: prepublish-check + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - name: Install ubuntu packages + run: shotover-proxy/build/install_ubuntu_packages.sh + - name: Publish + run: | + cd shotover + cargo publish + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_TOKEN }} diff --git a/shotover-proxy/build/is_releasable.sh b/shotover-proxy/build/is_releasable.sh new file mode 100755 index 000000000..e71fcaa24 --- /dev/null +++ b/shotover-proxy/build/is_releasable.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +set -e +set -u + +TAG=$(git tag --points-at HEAD) + +if [ -z "$TAG" ]; +then + echo "Failed: The current commit has no git tags" + exit 1 +fi + +if [[ $TAG == *$'\n'* ]]; +then + echo "Failed: multiple git tags are on the latest commit, but only one tag is allowed" + echo "$TAG" + exit 1 +fi + +TAG_VERSION=$(echo $TAG | sed -e "s/^v//") + +if [ -z "$TAG_VERSION" ]; +then + echo "Failed: git tag not valid: '$TAG'" + exit 1 +fi + +BIN_VERSION="$(cargo metadata --format-version 1 --offline --no-deps | jq -c -M -r '.packages[] | select(.name == "shotover-proxy") | .version')" +if [ "$TAG_VERSION" != "$BIN_VERSION" ]; +then + echo "Failed: git tag '$TAG_VERSION' did not match shotover-proxy version '$BIN_VERSION'" + exit 1 +fi + +LIB_VERSION="$(cargo metadata --format-version 1 --offline --no-deps | jq -c -M -r '.packages[] | select(.name == "shotover") | .version')" +if [ "$TAG_VERSION" != "$LIB_VERSION" ]; +then + echo "Failed: git tag '$TAG_VERSION' did not match shotover version '$LIB_VERSION'" + exit 1 +fi + +echo "Shotover repository is ready for publishing"