-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: upload built asset to gh release (#6)
- Loading branch information
1 parent
0117597
commit b1e203e
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |