Improve release action (#284)

This commit is contained in:
EdJoPaTo 2021-10-29 20:31:25 +02:00 committed by Ajeet D'Souza
parent 279e393d5c
commit 9d8bfc90be
4 changed files with 83 additions and 80 deletions

View File

@ -3,22 +3,30 @@ on:
push: push:
branches: [main] branches: [main]
pull_request: pull_request:
workflow_dispatch:
jobs: jobs:
ci: ci:
name: ci-${{ matrix.os }} name: ${{ matrix.os }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macos-latest, windows-latest] os: [ubuntu-latest, macos-latest, windows-latest]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions-rs/install@v0.1
- uses: actions-rs/toolchain@v1
if: ${{ matrix.os == 'windows-latest' }} if: ${{ matrix.os == 'windows-latest' }}
with: with:
crate: cargo-audit toolchain: stable
version: latest components: rustfmt, clippy
profile: minimal
override: true
- uses: cachix/install-nix-action@v12 - uses: cachix/install-nix-action@v12
if: ${{ matrix.os != 'windows-latest' }} if: ${{ matrix.os != 'windows-latest' }}
with: with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz
- run: cargo xtask ci - run: cargo xtask ci
if: ${{ matrix.os == 'windows-latest' }}
- run: nix-shell --cores 0 --pure --run 'cargo xtask ci'
if: ${{ matrix.os != 'windows-latest' }}

View File

@ -1,51 +1,53 @@
name: release name: release
on: on:
push: push:
branches: [main]
tags: ["v[0-9]+.[0-9]+.[0-9]+"] tags: ["v[0-9]+.[0-9]+.[0-9]+"]
pull_request:
workflow_dispatch:
jobs: jobs:
build: release:
name: build-${{ matrix.target }} name: ${{ matrix.target }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
fail-fast: false
matrix: matrix:
target:
- aarch64-pc-windows-msvc
- aarch64-unknown-linux-musl
- armv7-unknown-linux-musleabihf
- x86_64-apple-darwin
- x86_64-pc-windows-msvc
- x86_64-unknown-linux-musl
include: include:
- target: aarch64-pc-windows-msvc - os: ubuntu-latest
os: windows-latest target: x86_64-unknown-linux-musl
use-cross: false - os: ubuntu-latest
- target: aarch64-unknown-linux-musl target: arm-unknown-linux-musleabihf
os: ubuntu-latest - os: ubuntu-latest
use-cross: true target: armv7-unknown-linux-musleabihf
- target: armv7-unknown-linux-musleabihf - os: ubuntu-latest
os: ubuntu-latest target: aarch64-unknown-linux-musl
use-cross: true
- target: x86_64-apple-darwin - os: macos-11
os: macos-latest target: x86_64-apple-darwin
use-cross: false - os: macos-11
- target: x86_64-pc-windows-msvc target: aarch64-apple-darwin
os: windows-latest
use-cross: false - os: windows-latest
- target: x86_64-unknown-linux-musl target: x86_64-pc-windows-msvc
os: ubuntu-latest - os: windows-latest
use-cross: true target: aarch64-pc-windows-msvc
steps: steps:
- name: Get the release version from the tag
shell: bash
if: env.RG_VERSION == ''
run: |
# https://github.community/t/how-to-get-just-the-tag-name/16241/7#M1027
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "Release version: ${{ env.RELEASE_VERSION }}"
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
fetch-depth: 1 fetch-depth: 0
- name: Set artifact name
shell: bash
run: |
version="$(git describe --tags --match='v*.*.*' --always)"
name="zoxide-$version-${{ matrix.target }}"
echo "ARTIFACT_NAME=$name" >> $GITHUB_ENV
echo "version: $version"
echo "artifact: $name"
- name: Install Rust - name: Install Rust
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
@ -53,52 +55,45 @@ jobs:
profile: minimal profile: minimal
override: true override: true
target: ${{ matrix.target }} target: ${{ matrix.target }}
- name: Build binary - name: Build binary
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: build command: build
args: --color=always --release --target=${{ matrix.target }} args: --release --locked --target=${{ matrix.target }} --color=always --verbose
use-cross: ${{ matrix.use-cross }} use-cross: ${{ runner.os == 'Linux' }}
- name: Build archive
shell: bash - name: Package (*nix)
run: | if: runner.os != 'Windows'
# Build archive run: >
tmpdir="zoxide-${{ env.RELEASE_VERSION }}-${{ matrix.target }}" tar -cv
mkdir "$tmpdir/" CHANGELOG.md LICENSE README.md
cp -r {man,CHANGELOG.md,LICENSE,README.md} "$tmpdir/" man/
if [[ "${{ matrix.target }}" = *"windows"* ]]; then -C contrib/ completions/ -C ../
asset="$tmpdir.zip" -C target/${{ matrix.target }}/release/ zoxide
cp "target/${{ matrix.target }}/release/zoxide.exe" "$tmpdir/" | gzip --best > '${{ env.ARTIFACT_NAME }}.tar.gz'
7z a -mm=Deflate -mfb=258 -mpass=15 -r "$asset" "./$tmpdir/*" - name: Package (Windows)
else if: runner.os == 'Windows'
asset="$tmpdir.tar.gz" run: >
cp "target/${{ matrix.target }}/release/zoxide" "$tmpdir/" 7z a ${{ env.ARTIFACT_NAME }}.zip
tar -cv "$tmpdir/" | gzip --best > "$asset" CHANGELOG.md LICENSE README.md
fi ./man/
echo "ASSET=$asset" >> $GITHUB_ENV ./contrib/completions/
- name: Upload archive ./target/${{ matrix.target }}/release/zoxide.exe
- name: Upload artifact
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: ${{ env.ASSET }} name: ${{ matrix.target }}
path: ${{ env.ASSET }} path: |
release: *.zip
runs-on: ubuntu-latest *.tar.gz
needs: [build]
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Download archives
uses: actions/download-artifact@v2
with:
path: artifact
- name: Show downloaded files
run: ls -lRh artifact/
- name: Create release - name: Create release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
with: with:
draft: true draft: true
files: artifact/*/* files: |
env: *.zip
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} *.tar.gz

View File

@ -22,7 +22,7 @@ fn main() {
fn git_version() -> Option<String> { fn git_version() -> Option<String> {
let dir = env!("CARGO_MANIFEST_DIR"); let dir = env!("CARGO_MANIFEST_DIR");
let mut git = Command::new("git"); let mut git = Command::new("git");
git.args(&["-C", dir, "describe", "--tags", "--broken"]); git.args(&["-C", &dir, "describe", "--tags", "--match=v*.*.*", "--always", "--broken"]);
let output = git.output().ok()?; let output = git.output().ok()?;
if !output.status.success() || output.stdout.is_empty() || !output.stderr.is_empty() { if !output.status.success() || output.stdout.is_empty() || !output.stderr.is_empty() {

View File

@ -2,7 +2,7 @@ let
rust = import (builtins.fetchTarball rust = import (builtins.fetchTarball
"https://github.com/oxalica/rust-overlay/archive/ad311f5bb5c5ef475985f1e0f264e831470a8510.tar.gz"); "https://github.com/oxalica/rust-overlay/archive/ad311f5bb5c5ef475985f1e0f264e831470a8510.tar.gz");
pkgs = import <nixpkgs> { overlays = [ rust ]; }; pkgs = import <nixpkgs> { overlays = [ rust ]; };
pkgs-latest = import (fetchTarball pkgs-latest = import (builtins.fetchTarball
"https://github.com/NixOS/nixpkgs/archive/3ef1d2a9602c18f8742e1fb63d5ae9867092e3d6.tar.gz") "https://github.com/NixOS/nixpkgs/archive/3ef1d2a9602c18f8742e1fb63d5ae9867092e3d6.tar.gz")
{ }; { };
in pkgs.mkShell { in pkgs.mkShell {