-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f0ea1d
commit 666209f
Showing
1 changed file
with
149 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,149 @@ | ||
name: release | ||
on: | ||
push: | ||
tags: | ||
- '[0-9]+.[0-9]+.[0-9]+' | ||
- '[0-9]+.[0-9]+.[0-9]+.alpha' | ||
- '[0-9]+.[0-9]+.[0-9]+.beta' | ||
- '[0-9]+.[0-9]+.[0-9]+.rc' | ||
jobs: | ||
create-release: | ||
name: create-release | ||
runs-on: ubuntu-latest | ||
# env: | ||
# Set to force version number, e.g., when no tag exists. | ||
# UNUSED_VERSION: TEST-0.0.0 | ||
steps: | ||
- name: Create artifacts directory | ||
run: mkdir artifacts | ||
|
||
- name: Get the release version from the tag | ||
if: env.UNUSED_VERSION == '' | ||
run: | | ||
# Apparently, this is the right way to get a tag name. Really? | ||
# | ||
# See: https://git.luolix.topmunity/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027 | ||
echo "::set-env name=UNUSED_VERSION::${GITHUB_REF#refs/tags/}" | ||
echo "version is: ${{ env.UNUSED_VERSION }}" | ||
- name: Create GitHub release | ||
id: release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ env.UNUSED_VERSION }} | ||
release_name: ${{ env.UNUSED_VERSION }} | ||
|
||
- name: Save release upload URL to artifact | ||
run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url | ||
|
||
- name: Save version number to artifact | ||
run: echo "${{ env.UNUSED_VERSION }}" > artifacts/release-version | ||
|
||
- name: Upload artifacts | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: artifacts | ||
path: artifacts | ||
|
||
build-release: | ||
name: build-release | ||
needs: ['create-release'] | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
# For some builds, we use cross to test on 32-bit and big-endian | ||
# systems. | ||
CARGO: cargo | ||
# When CARGO is set to CROSS, this is set to `--target matrix.target`. | ||
TARGET_FLAGS: | ||
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target. | ||
TARGET_DIR: ./target | ||
# Emit backtraces on panics. | ||
RUST_BACKTRACE: 1 | ||
strategy: | ||
matrix: | ||
build: [linux, macos] | ||
include: | ||
- build: linux | ||
os: ubuntu-18.04 | ||
rust: stable | ||
target: x86_64-unknown-linux-musl | ||
- build: macos | ||
os: macos-latest | ||
rust: stable | ||
target: x86_64-apple-darwin | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 1 | ||
|
||
- name: Install Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
profile: minimal | ||
override: true | ||
target: ${{ matrix.target }} | ||
|
||
- name: Use Cross | ||
run: | | ||
# FIXME: to work around bugs in latest cross release, install master. | ||
# See: https://github.com/rust-embedded/cross/issues/357 | ||
cargo install --git https://github.com/rust-embedded/cross | ||
echo "::set-env name=CARGO::cross" | ||
echo "::set-env name=TARGET_FLAGS::--target ${{ matrix.target }}" | ||
echo "::set-env name=TARGET_DIR::./target/${{ matrix.target }}" | ||
- name: Show command used for Cargo | ||
run: | | ||
echo "cargo command is: ${{ env.CARGO }}" | ||
echo "target flag is: ${{ env.TARGET_FLAGS }}" | ||
echo "target dir is: ${{ env.TARGET_DIR }}" | ||
- name: Get release download URL | ||
uses: actions/download-artifact@v1 | ||
with: | ||
name: artifacts | ||
path: artifacts | ||
|
||
- name: Set release upload URL and release version | ||
shell: bash | ||
run: | | ||
release_upload_url="$(cat artifacts/release-upload-url)" | ||
echo "::set-env name=RELEASE_UPLOAD_URL::$release_upload_url" | ||
echo "release upload url: $RELEASE_UPLOAD_URL" | ||
release_version="$(cat artifacts/release-version)" | ||
echo "::set-env name=RELEASE_VERSION::$release_version" | ||
echo "release version: $RELEASE_VERSION" | ||
- name: Build release binary | ||
run: ${{ env.CARGO }} build --verbose --release --bin unused-rs ${{ env.TARGET_FLAGS }} | ||
|
||
- name: Strip release binary (Linux and macOS) | ||
if: matrix.build == 'linux' || matrix.build == 'macos' | ||
run: strip "target/${{ matrix.target }}/release/unused-rs" | ||
|
||
- name: Build archive | ||
shell: bash | ||
run: | | ||
staging="unused-rs-${{ env.RELEASE_VERSION }}-${{ matrix.target }}" | ||
mkdir -p "$staging" | ||
cp {README.md,LICENSE} "$staging/" | ||
cp "target/${{ matrix.target }}/release/unused-rs" "$staging/" | ||
tar czf "$staging.tar.gz" "$staging" | ||
echo "::set-env name=ASSET::$staging.tar.gz" | ||
- name: Upload release archive | ||
uses: actions/upload-release-asset@v1.0.1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ env.RELEASE_UPLOAD_URL }} | ||
asset_path: ${{ env.ASSET }} | ||
asset_name: ${{ env.ASSET }} | ||
asset_content_type: application/octet-stream |