Skip to content

Commit

Permalink
fix: release.yml to follow ci.yml updated cross (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
guangie88 authored Jan 2, 2023
1 parent 87fa3dc commit d6e45dd
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 31 deletions.
154 changes: 154 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,160 @@ on:
branches:
- master
jobs:
# Same as release.yml, except simplified and overwrite uploaded assets
# This requires a v0.0.0 release to be created for experimentation
set-release-vars:
name: set-release-vars
runs-on: ubuntu-22.04
outputs:
tag_version: ${{ env.TAG_VERSION }}
steps:
- name: Get the release version from the tag
if: env.TAG_VERSION == ''
run: |
TAG_VERSION=v0.0.0
echo "TAG_VERSION=${TAG_VERSION}" >> $GITHUB_ENV
echo "version is: ${TAG_VERSION}"
build-release:
name: build-release
needs: ['set-release-vars']
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:
- nightly
- nightly-musl
- nightly-32
- nightly-mips
- nightly-arm
- macos
- win-msvc
- win-gnu
include:
- build: nightly
os: ubuntu-22.04
rust: nightly
build_suffix: x86_64-unknown-linux-gnu
- build: nightly-musl
os: ubuntu-22.04
rust: nightly
target: x86_64-unknown-linux-musl
build_suffix: x86_64-unknown-linux-musl
- build: nightly-32
os: ubuntu-22.04
rust: nightly
target: i686-unknown-linux-gnu
build_suffix: i686-unknown-linux-gnu
- build: nightly-mips
os: ubuntu-22.04
rust: nightly
target: mips64-unknown-linux-gnuabi64
build_suffix: mips64-unknown-linux-gnuabi64
- build: nightly-arm
os: ubuntu-22.04
rust: nightly
target: arm-unknown-linux-gnueabihf
build_suffix: arm-unknown-linux-gnueabihf
- build: macos
os: macos-12
rust: nightly
build_suffix: x86_64-apple-darwin
- build: win-msvc
os: windows-2022
rust: nightly
build_suffix: x86_64-pc-windows-msvc
- build: win-gnu
os: windows-2022
rust: nightly-x86_64-gnu
build_suffix: x86_64-pc-windows-gnu
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install packages (Ubuntu)
if: matrix.os == 'ubuntu-22.04'
run: |
ci/ubuntu-install-packages
- name: Install packages (macOS)
if: matrix.os == 'macos-12'
run: |
ci/macos-install-packages
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}

- name: Use Cross
if: matrix.target != ''
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: Show command used for Cargo
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
- name: Build executable
run: ${{ env.CARGO }} build --verbose --workspace --release ${{ env.TARGET_FLAGS }}

- name: Strip release binary (linux and macos)
if: matrix.build == 'linux' || matrix.build == 'macos'
run: strip "target/${{ matrix.target }}/release/tera"

- name: Strip release binary (arm)
if: matrix.build == 'linux-arm'
run: |
docker run --rm -v \
"$PWD/target:/target:Z" \
rustembedded/cross:arm-unknown-linux-gnueabihf \
arm-linux-gnueabihf-strip \
/target/arm-unknown-linux-gnueabihf/release/tera
- name: Build archive
shell: bash
run: |
outdir="$(ci/cargo-out-dir "${{ env.TARGET_DIR }}")"
staging="tera-cli-${{ needs.set-release-vars.outputs.tag_version }}-${{ matrix.build_suffix }}"
mkdir -p "$staging"
cp LICENSE "$staging/"
if [ "${{ matrix.os }}" = "windows-2022" ]; then
cp "target/${{ matrix.target }}/release/tera.exe" "$staging/"
7z a "$staging.zip" "$staging"
echo "ASSET=$staging.zip" >> $GITHUB_ENV
else
# The man page is only generated on Unix systems. ¯\_(ツ)_/¯
cp "target/${{ matrix.target }}/release/tera" "$staging/"
tar czf "$staging.tar.gz" "$staging"
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
fi
- name: Upload release archive
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.ASSET }}
asset_name: ${{ env.ASSET }}
tag: ${{ needs.set-release-vars.outputs.tag_version }}
overwrite: true

test:
name: test
env:
Expand Down
70 changes: 39 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,8 @@ jobs:
name: set-release-vars
runs-on: ubuntu-22.04
outputs:
upload_url: ${{ steps.get_release.outputs.upload_url }}
tag_version: ${{ env.TAG_VERSION }}
steps:
- name: Get release
id: get_release
uses: bruceadams/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Create artifacts directory
run: mkdir artifacts

Expand Down Expand Up @@ -58,40 +51,59 @@ jobs:
# systems.
CARGO: cargo
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
TARGET_FLAGS: ""
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, linux-arm, macos, win-msvc, win-gnu, win32-msvc]
build:
- nightly
- nightly-musl
- nightly-32
- nightly-mips
- nightly-arm
- macos
- win-msvc
- win-gnu
include:
- build: linux
- build: nightly
os: ubuntu-22.04
rust: nightly
build_suffix: x86_64-unknown-linux-gnu
- build: nightly-musl
os: ubuntu-22.04
rust: nightly
target: x86_64-unknown-linux-musl
- build: linux-arm
build_suffix: x86_64-unknown-linux-musl
- build: nightly-32
os: ubuntu-22.04
rust: nightly
target: i686-unknown-linux-gnu
build_suffix: i686-unknown-linux-gnu
- build: nightly-mips
os: ubuntu-22.04
rust: nightly
target: mips64-unknown-linux-gnuabi64
build_suffix: mips64-unknown-linux-gnuabi64
- build: nightly-arm
os: ubuntu-22.04
rust: nightly
target: arm-unknown-linux-gnueabihf
build_suffix: arm-unknown-linux-gnueabihf
- build: macos
os: macos-12
rust: nightly
target: x86_64-apple-darwin
build_suffix: x86_64-apple-darwin
- build: win-msvc
os: windows-2022
rust: nightly
target: x86_64-pc-windows-msvc
build_suffix: x86_64-pc-windows-msvc
- build: win-gnu
os: windows-2022
rust: nightly-x86_64-gnu
target: x86_64-pc-windows-gnu
- build: win32-msvc
os: windows-2022
rust: nightly
target: i686-pc-windows-msvc

build_suffix: x86_64-pc-windows-gnu
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -110,10 +122,9 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}

- name: Use Cross
shell: bash
if: matrix.target != ''
run: |
cargo install cross
echo "CARGO=cross" >> $GITHUB_ENV
Expand All @@ -124,10 +135,9 @@ jobs:
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 }}
- name: Build executable
run: ${{ env.CARGO }} build --verbose --workspace --release ${{ env.TARGET_FLAGS }}

- name: Strip release binary (linux and macos)
if: matrix.build == 'linux' || matrix.build == 'macos'
Expand All @@ -146,7 +156,7 @@ jobs:
shell: bash
run: |
outdir="$(ci/cargo-out-dir "${{ env.TARGET_DIR }}")"
staging="tera-cli-${{ needs.set-release-vars.outputs.tag_version }}-${{ matrix.target }}"
staging="tera-cli-${{ needs.set-release-vars.outputs.tag_version }}-${{ matrix.build_suffix }}"
mkdir -p "$staging"
cp LICENSE "$staging/"
Expand All @@ -163,14 +173,12 @@ jobs:
fi
- name: Upload release archive
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: svenstaro/upload-release-action@v2
with:
upload_url: ${{ needs.set-release-vars.outputs.upload_url }}
asset_path: ${{ env.ASSET }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.ASSET }}
asset_name: ${{ env.ASSET }}
asset_content_type: application/octet-stream
tag: ${{ needs.set-release-vars.outputs.tag_version }}

cargo-publish:
name: cargo publish
Expand Down

0 comments on commit d6e45dd

Please sign in to comment.