Skip to content

Commit

Permalink
feat(ci): add release pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
brumhard committed May 9, 2023
1 parent 2f2b6be commit 127b8bb
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 70 deletions.
31 changes: 31 additions & 0 deletions .github/actions/nix-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Setup nix
description: Sets up nix and tools
inputs:
tools_package:
description: Name of the package in the flake.nix file that provides all necessary tools
required: false
default: "tooling"
token:
description: GitHub PAT used for nix cache
required: true

runs:
using: composite
steps:
# https://github.com/actions/cache/issues/749
# there seems to be no way to cache nix stuff really
# setting the store as suggested in the issue doesn't work
- name: Install Nix
uses: cachix/install-nix-action@v20
with:
# token to avoid GitHub rate limiting
extra_nix_config: |
access-tokens = github.com=${{ inputs.token }}
- name: Load environment
# https://lobste.rs/s/qbsbcj/streamline_your_github_actions#c_1alxuy
# NIX_STORE is required by cross to detect nix
# This could break if env vars are set in shellHook etc.
shell: bash
run: |
nix develop -c bash -c 'echo $PATH' >> "$GITHUB_PATH"
echo "NIX_STORE=/nix/store" >> $GITHUB_ENV
60 changes: 60 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: release

on:
push:
tags:
- "*"
jobs:
build:
strategy:
fail-fast: true
matrix:
include:
- { runner: macos-latest, filter: darwin }
- { runner: ubuntu-latest, filter: linux }
name: ${{ matrix.filter }}
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/nix-setup
with:
token: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/actions/cache/blob/main/examples.md#rust---cargo
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
out/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Build ${{ matrix.filter }} targets
run: mask build --filter ${{ matrix.filter }}
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.filter }}
path: out/bin/*
release:
permissions:
contents: write
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# required for goreleaser
fetch-depth: 0
- uses: ./.github/actions/nix-setup
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@v3
with:
path: out/
- name: Move artifacts to /out/bin
run: find out/ -type f -exec cp {} out/bin/ \;
- name: Release
run: goreleaser release --clean
26 changes: 0 additions & 26 deletions .github/workflows/test.yml

This file was deleted.

32 changes: 13 additions & 19 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,6 @@
inherit name version;
src = ./.;
};
# included in packages to make it installable in ci
tooling = pkgs.buildEnv {
name = "tooling";
paths = with pkgs; [
rustup
libiconv
cargo-audit
cargo-outdated
cargo-cross

mask
yq-go
ripgrep
goreleaser
svu
commitlint
];
};
};

apps = {
Expand All @@ -62,7 +44,19 @@
# this seems to be required to cross compile x86_64-apple-darwin on M1
# https://github.com/NixOS/nixpkgs/commit/9b3091a94cad63ebd0bd7aafbcfed7c133ef899d
devShell = mkShellNoCC {
packages = [ packages.tooling ];
packages = [
rustup
cargo-audit
cargo-outdated
cargo-cross

mask
yq-go
ripgrep
goreleaser
svu
commitlint
];

# https://github.com/openebs/mayastor-control-plane/blob/develop/shell.nix
NODE_PATH = "${nodePackages."@commitlint/config-conventional"}/lib/node_modules";
Expand Down
38 changes: 17 additions & 21 deletions maskfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

> initializes the dev env in the repo
```sh
```bash
git config --local core.hooksPath .githooks/
```

## test-run

> builds the test docker image and runs dump
```sh
```bash
image_name="reinlinsen-test"
out_dir="$image_name-fs"
rm -rf "$out_dir"
Expand All @@ -24,15 +24,15 @@ cargo run -- dump "$image_name" -o "$out_dir" --verbose

> runs cargo clippy
```sh
```bash
cargo clippy -- -W clippy::pedantic
```

## audit

> runs audit for dependencies
```sh
```bash
info=$(cargo outdated --root-deps-only --format json)
if [ $(echo "$info" | jq '.dependencies | length') -gt 0 ]; then
echo "dependencies are not up to date:"
Expand All @@ -58,31 +58,27 @@ fi
* type: string
* desc: filter all targets with the given string, e.g. "linux", "aarch64"

```sh
function to_arch_os () {
echo "$1" | rg '^(?P<arch>.+?)-\w+-(?P<os>\w+)(-\w*)?$' -r '$arch-$os'
}

out_dir="out"
```bash
set -eo pipefail
targets=$(yq -o json -p toml -r '.toolchain.targets[]' rust-toolchain.toml)
if [ "$filter" != "" ]; then
targets=$(echo "$targets"|rg "$filter")
targets=$(echo "$targets" | rg "$filter")
fi

out_dir="out"
rm -rf "$out_dir"/bin
mkdir -p "$out_dir"/bin

target_os_list=$(to_arch_os "$targets" | cut -d- -f2 |sort |uniq)
build_cmd="cargo"
if [ "$(echo "$target_os_list" | wc -l)" -gt 1 ]; then
build_cmd="cross"
build_args=""
if [ $verbose ]; then
build_args="--verbose"
fi

for target in $targets; do
echo "building for $target"
# specifying target-dir is a hack for https://github.com/cross-rs/cross/issues/724
$build_cmd build --release --target "$target" --target-dir "$out_dir/$target"
arch_os=$(to_arch_os "$target")
cross build --release --target "$target" --target-dir "$out_dir/$target" $build_args
arch_os=$(echo "$target" | rg '^(?P<arch>.+?)-\w+-(?P<os>\w+)(-\w*)?$' -r '$arch-$os')
cp "$out_dir/$target/$target/release/rl" "$out_dir/bin/rl-$arch_os"
done
```
Expand All @@ -98,7 +94,7 @@ done
* desc: tag for the next release version
* type: string

```sh
```bash
if [ "$(git status --porcelain)" != "" ]; then
echo "nope too dirty"
exit 1
Expand Down Expand Up @@ -132,10 +128,10 @@ git push --tags
* type: bool
* desc: if enabled mask tag will be run prior to release

```sh
```bash
if [ $local ]; then
mask tag
$MASK tag
fi
mask build
$MASK build
goreleaser release --clean
```
6 changes: 3 additions & 3 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[toolchain]
channel = "1.69"
targets = [
"x86_64-apple-darwin",
"aarch64-apple-darwin",
"x86_64-unknown-linux-musl",
"aarch64-unknown-linux-musl"
"x86_64-apple-darwin",
"aarch64-unknown-linux-musl",
"x86_64-unknown-linux-musl"
]
components = [
"rustfmt", "clippy"
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};
use std::fmt::Debug;
use std::fs::{self, File};
use std::io::{self, stdout};
use std::io::stdout;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use tar::Archive;
Expand Down

0 comments on commit 127b8bb

Please sign in to comment.