From 9d8bfc90be1f990619501271f8209e2d8a4f79bb Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Fri, 29 Oct 2021 20:31:25 +0200 Subject: [PATCH] Improve release action (#284) --- .github/workflows/ci.yml | 16 +++- .github/workflows/release.yml | 143 ++++++++++++++++------------------ build.rs | 2 +- shell.nix | 2 +- 4 files changed, 83 insertions(+), 80 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52ac2a2..20b164a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,22 +3,30 @@ on: push: branches: [main] pull_request: + workflow_dispatch: jobs: ci: - name: ci-${{ matrix.os }} + name: ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] steps: - uses: actions/checkout@v2 - - uses: actions-rs/install@v0.1 + + - uses: actions-rs/toolchain@v1 if: ${{ matrix.os == 'windows-latest' }} with: - crate: cargo-audit - version: latest + toolchain: stable + components: rustfmt, clippy + profile: minimal + override: true - uses: cachix/install-nix-action@v12 if: ${{ matrix.os != 'windows-latest' }} with: nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz + - run: cargo xtask ci + if: ${{ matrix.os == 'windows-latest' }} + - run: nix-shell --cores 0 --pure --run 'cargo xtask ci' + if: ${{ matrix.os != 'windows-latest' }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6c4800c..2947bfc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,51 +1,53 @@ name: release on: push: + branches: [main] tags: ["v[0-9]+.[0-9]+.[0-9]+"] + pull_request: + workflow_dispatch: + jobs: - build: - name: build-${{ matrix.target }} + release: + name: ${{ matrix.target }} runs-on: ${{ matrix.os }} strategy: + fail-fast: false 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: - - target: aarch64-pc-windows-msvc - os: windows-latest - use-cross: false - - target: aarch64-unknown-linux-musl - os: ubuntu-latest - use-cross: true - - target: armv7-unknown-linux-musleabihf - os: ubuntu-latest - use-cross: true - - target: x86_64-apple-darwin - os: macos-latest - use-cross: false - - target: x86_64-pc-windows-msvc - os: windows-latest - use-cross: false - - target: x86_64-unknown-linux-musl - os: ubuntu-latest - use-cross: true + - os: ubuntu-latest + target: x86_64-unknown-linux-musl + - os: ubuntu-latest + target: arm-unknown-linux-musleabihf + - os: ubuntu-latest + target: armv7-unknown-linux-musleabihf + - os: ubuntu-latest + target: aarch64-unknown-linux-musl + + - os: macos-11 + target: x86_64-apple-darwin + - os: macos-11 + target: aarch64-apple-darwin + + - os: windows-latest + target: x86_64-pc-windows-msvc + - os: windows-latest + target: aarch64-pc-windows-msvc 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 uses: actions/checkout@v2 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 uses: actions-rs/toolchain@v1 with: @@ -53,52 +55,45 @@ jobs: profile: minimal override: true target: ${{ matrix.target }} + - name: Build binary uses: actions-rs/cargo@v1 with: command: build - args: --color=always --release --target=${{ matrix.target }} - use-cross: ${{ matrix.use-cross }} - - name: Build archive - shell: bash - run: | - # Build archive - tmpdir="zoxide-${{ env.RELEASE_VERSION }}-${{ matrix.target }}" - mkdir "$tmpdir/" - cp -r {man,CHANGELOG.md,LICENSE,README.md} "$tmpdir/" - if [[ "${{ matrix.target }}" = *"windows"* ]]; then - asset="$tmpdir.zip" - cp "target/${{ matrix.target }}/release/zoxide.exe" "$tmpdir/" - 7z a -mm=Deflate -mfb=258 -mpass=15 -r "$asset" "./$tmpdir/*" - else - asset="$tmpdir.tar.gz" - cp "target/${{ matrix.target }}/release/zoxide" "$tmpdir/" - tar -cv "$tmpdir/" | gzip --best > "$asset" - fi - echo "ASSET=$asset" >> $GITHUB_ENV - - name: Upload archive + args: --release --locked --target=${{ matrix.target }} --color=always --verbose + use-cross: ${{ runner.os == 'Linux' }} + + - name: Package (*nix) + if: runner.os != 'Windows' + run: > + tar -cv + CHANGELOG.md LICENSE README.md + man/ + -C contrib/ completions/ -C ../ + -C target/${{ matrix.target }}/release/ zoxide + | gzip --best > '${{ env.ARTIFACT_NAME }}.tar.gz' + - name: Package (Windows) + if: runner.os == 'Windows' + run: > + 7z a ${{ env.ARTIFACT_NAME }}.zip + CHANGELOG.md LICENSE README.md + ./man/ + ./contrib/completions/ + ./target/${{ matrix.target }}/release/zoxide.exe + + - name: Upload artifact uses: actions/upload-artifact@v2 with: - name: ${{ env.ASSET }} - path: ${{ env.ASSET }} - release: - runs-on: ubuntu-latest - 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: ${{ matrix.target }} + path: | + *.zip + *.tar.gz + - name: Create release + if: startsWith(github.ref, 'refs/tags/v') uses: softprops/action-gh-release@v1 with: draft: true - files: artifact/*/* - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + files: | + *.zip + *.tar.gz diff --git a/build.rs b/build.rs index af4adae..aef6d7f 100644 --- a/build.rs +++ b/build.rs @@ -22,7 +22,7 @@ fn main() { fn git_version() -> Option { let dir = env!("CARGO_MANIFEST_DIR"); 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()?; if !output.status.success() || output.stdout.is_empty() || !output.stderr.is_empty() { diff --git a/shell.nix b/shell.nix index 4b2edcd..7f9a96d 100644 --- a/shell.nix +++ b/shell.nix @@ -2,7 +2,7 @@ let rust = import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/ad311f5bb5c5ef475985f1e0f264e831470a8510.tar.gz"); pkgs = import { overlays = [ rust ]; }; - pkgs-latest = import (fetchTarball + pkgs-latest = import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/3ef1d2a9602c18f8742e1fb63d5ae9867092e3d6.tar.gz") { }; in pkgs.mkShell {