-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
1 changed file
with
151 additions
and
28 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 |
---|---|---|
@@ -1,35 +1,158 @@ | ||
name: release | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
push: | ||
# Enable when testing release infrastructure on a branch. | ||
# branches: | ||
# - ci/release-check | ||
tags: | ||
- "[0-9]+.[0-9]+.[0-9]+" | ||
- "[0-9]+.[0-9]+.[0-9]+-*" | ||
jobs: | ||
release: | ||
name: publish ${{ matrix.name }} | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
include: | ||
- target: x86_64-pc-windows-gnu | ||
suffix: windows-x86_64 | ||
archive: zip | ||
- target: x86_64-unknown-linux-gun | ||
suffix: linux-x86_64 | ||
archive: tar.xz | ||
- target: x86_64-apple-darwin | ||
suffix: darwin-x86_64 | ||
archive: tar.gz | ||
create-release: | ||
name: create-release | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
upload_url: ${{ steps.release.outputs.upload_url }} | ||
near_cli_version: ${{ env.NEAR_CLI_VERSION }} | ||
steps: | ||
- name: Clone test repository | ||
uses: actions/checkout@v2 | ||
- uses: xhaiker/[email protected] | ||
name: build ${{ matrix.name }} | ||
with: | ||
rust_target: ${{ matrix.target }} | ||
archive_suffix: ${{ matrix.suffix }} | ||
archive_types: ${{ matrix.archive }} | ||
extra_files: "README.md README_zh.md LICENSE" | ||
- name: Get the release version from the tag | ||
shell: bash | ||
if: env.NEAR_CLI_VERSION == '' | ||
run: | | ||
# Apparently, this is the right way to get a tag name. Really? | ||
# | ||
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027 | ||
echo "NEAR_CLI_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | ||
echo "version is: ${{ env.NEAR_CLI_VERSION }}" | ||
- name: Create GitHub release | ||
id: release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ env.NEAR_CLI_VERSION }} | ||
release_name: ${{ env.NEAR_CLI_VERSION }} | ||
|
||
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 | ||
# For some builds, we disable ledger support | ||
FEATURES_FLAGS: | ||
# Emit backtraces on panics. | ||
RUST_BACKTRACE: 1 | ||
# Build static releases with PCRE2. | ||
PCRE2_SYS_STATIC: 1 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- build: linux-x86_64 | ||
os: ubuntu-18.04 | ||
rust: stable | ||
target: x86_64-unknown-linux-gnu | ||
- build: linux-x86_64-musl | ||
os: ubuntu-18.04 | ||
rust: stable | ||
target: x86_64-unknown-linux-musl | ||
- build: linux-aarch64-musl | ||
os: ubuntu-18.04 | ||
rust: stable | ||
target: aarch64-unknown-linux-musl | ||
- build: macos-x86_64 | ||
os: macos-latest | ||
rust: stable | ||
target: x86_64-apple-darwin | ||
- build: win64-msvc | ||
os: windows-2019 | ||
rust: stable | ||
target: x86_64-pc-windows-msvc | ||
- build: win32-msvc | ||
os: windows-2019 | ||
rust: stable | ||
target: i686-pc-windows-msvc | ||
|
||
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: | | ||
cargo install cross | ||
echo "CARGO=cross" >> $GITHUB_ENV | ||
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV | ||
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV | ||
- name: Build cross environment | ||
shell: bash | ||
run: | | ||
if [ -d "./cross/${{ matrix.target }}" ]; then | ||
docker build --tag "cross:${{ matrix.target }}" "./cross/${{ matrix.target }}" | ||
fi | ||
- name: Disable Ledger support for platforms that don't have udev | ||
if: matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'aarch64-unknown-linux-musl' | ||
run: | | ||
echo "FEATURES_FLAGS=--no-default-features" >> $GITHUB_ENV | ||
- 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: Build release binary | ||
run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }} ${{ env.FEATURES_FLAGS }} | ||
|
||
- name: Strip release binary (linux and macos) | ||
if: matrix.build == 'linux-x86_64' || matrix.build == 'macos-x86_64' | ||
run: strip "${{ env.TARGET_DIR }}/release/near-cli" | ||
|
||
- name: Strip release binary (linux-aarch64) | ||
if: matrix.build == 'linux-aarch64-musl' | ||
run: | | ||
docker run --rm -v \ | ||
"$PWD/target:/target:Z" \ | ||
rustembedded/cross:aarch64-unknown-linux-musl \ | ||
aarch64-linux-musl-strip \ | ||
/target/aarch64-unknown-linux-musl/release/near-cli | ||
- name: Build archive | ||
shell: bash | ||
run: | | ||
staging="near-cli-${{ needs.create-release.outputs.near_cli_version }}-${{ matrix.target }}" | ||
mkdir -p "$staging"/"docs" | ||
cp README.md "$staging/" | ||
cp -a "docs"/* "$staging/docs/" | ||
if [ "${{ matrix.os }}" = "windows-2019" ]; then | ||
cp "${{ env.TARGET_DIR }}/release/near-cli.exe" "$staging/" | ||
7z a "$staging.zip" "$staging" | ||
echo "ASSET=$staging.zip" >> $GITHUB_ENV | ||
else | ||
cp "${{ env.TARGET_DIR }}/release/near-cli" "$staging/" | ||
tar czf "$staging.tar.gz" "$staging" | ||
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV | ||
fi | ||
- name: Upload release archive | ||
uses: actions/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ needs.create-release.outputs.upload_url }} | ||
asset_path: ${{ env.ASSET }} | ||
asset_name: ${{ env.ASSET }} | ||
asset_content_type: application/octet-stream |