Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve release action #284

Merged
merged 5 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,30 @@ on:
push:
branches: [main]
ajeetdsouza marked this conversation as resolved.
Show resolved Hide resolved
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/[email protected]

- 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' }}
145 changes: 70 additions & 75 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,104 +1,99 @@
name: release
on:
push:
tags: ["v[0-9]+.[0-9]+.[0-9]+"]
branches: [main]
ajeetdsouza marked this conversation as resolved.
Show resolved Hide resolved
pull_request:
tags: ["v[0-9]+.[0-9]+.[0-9]+"]
workflow_dispatch:

jobs:
build:
name: build-${{ matrix.target }}
release:
name: ${{ matrix.target }}
ajeetdsouza marked this conversation as resolved.
Show resolved Hide resolved
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:
toolchain: stable
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
ajeetdsouza marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
fn git_version() -> Option<String> {
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() {
Expand Down
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let
rust = import (builtins.fetchTarball
"https://github.com/oxalica/rust-overlay/archive/ad311f5bb5c5ef475985f1e0f264e831470a8510.tar.gz");
pkgs = import <nixpkgs> { overlays = [ rust ]; };
pkgs-latest = import (fetchTarball
pkgs-latest = import (builtins.fetchTarball
"https://github.com/NixOS/nixpkgs/archive/3ef1d2a9602c18f8742e1fb63d5ae9867092e3d6.tar.gz")
{ };
in pkgs.mkShell {
Expand Down