Skip to content

Commit

Permalink
build: upload built asset to gh release (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruuuuuuuce authored Nov 4, 2021
1 parent 0117597 commit b1e203e
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions set_cargo_version.sh
Original file line number Diff line number Diff line change
@@ -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 <SEMVER_VERSION>
Example:
$0 1.0.3
"
exit 1
}

if [ "$#" -ne 1 ]; then
log "Expected 1 positional argument: <SEMVER_VERSION>"
log ""
usage
fi

log "updating Cargo.toml to version $1"

pip3 install toml
python3 update_cargo_toml.py $1
15 changes: 15 additions & 0 deletions update_cargo.toml.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b1e203e

Please sign in to comment.