diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000..5c92b16f --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,74 @@ +name: CD + +on: + workflow_dispatch: + push: + branches: [ main ] + paths-ignore: + - '**/Cargo.toml' + +env: + CARGO_TERM_COLOR: always + +jobs: + rustfmt: + name: rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + # 🤮 + submodules: true + token: ${{ secrets.PRIVATE_REPO_RELEASE_ACCESS }} + - uses: actions-rs/toolchain@v1 + - name: rustfmt + run: cargo fmt -- --check + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + # 🤮 + submodules: true + token: ${{ secrets.PRIVATE_REPO_RELEASE_ACCESS }} + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + components: rustfmt + override: true + + - name: Set release + id: semrel + uses: go-semantic-release/action@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + allow-initial-development-versions: true + force-bump-patch-version: true + + - name: Update Cargo Version + run: | + chmod +x set_cargo_version.sh + ./set_cargo_version.sh ${{ steps.semrel.outputs.version }} + shell: bash + + - name: Build + run: cargo build --verbose + + - name: Build tar.gz + run: | + STASH_SHA=$(git stash create) + VERSION=${{ steps.semrel.outputs.version }} + ARCHIVE_FILE=archive-$VERSION.tar.gz + echo "ARCHIVE_FILE="$ARCHIVE_FILE >> $GITHUB_ENV + git archive --format tar $STASH_SHA | gzip > $ARCHIVE_FILE + SHA=$(openssl sha256 < ${ARCHIVE_FILE} | sed 's/.* //') + echo "SHA="$SHA >> $GITHUB_ENV + echo "sha is: ${SHA}" + AUTH="Authorization: token ${{ secrets.PRIVATE_REPO_RELEASE_ACCESS }}" + LATEST_RELEASE=$(curl -sH "$AUTH" https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/v${VERSION}) + RELEASE_ID=$(echo $LATEST_RELEASE | jq -r .id) + GH_ASSET="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${ARCHIVE_FILE}" + echo $GH_ASSET + curl --data-binary @$ARCHIVE_FILE -H "$AUTH" -H "Content-Type: application/octet-stream" $GH_ASSET + shell: bash diff --git a/set_cargo_version.sh b/set_cargo_version.sh new file mode 100755 index 00000000..1188a969 --- /dev/null +++ b/set_cargo_version.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +function log() { + local msg=$1 + >&2 echo "$msg" +} + +function usage() { + log " +This script updates the Cargo.toml file to match the semver release version +Usage: +$0 +Example: +$0 1.0.3 + " + exit 1 +} + +if [ "$#" -ne 1 ]; then + log "Expected 1 positional argument: " + log "" + usage +fi + +log "updating Cargo.toml to version $1" + +pip3 install toml +python3 update_cargo_toml.py $1 diff --git a/update_cargo.toml.py b/update_cargo.toml.py new file mode 100644 index 00000000..0fb2ca08 --- /dev/null +++ b/update_cargo.toml.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +import sys +import toml + +if len(sys.argv) != 2: + print(sys.argv) + sys.exit("must pass 1 positional argument, ex: python3 ./update_cargo_toml.py 1.0.1") + +filename = "Cargo.toml" + +toml_data = toml.load(filename) +toml_data["package"]["version"] = sys.argv[1] + +with open(filename, 'w') as cargo: + toml.dump(toml_data, cargo)