~ireas/nitrokey-rs

8b87b5ede28805f54261bc93ad83a9c6726d3da5 — Robin Krahl 5 months ago 4fb0cf9
Move CI steps into makefile

This patch moves the CI steps into a Makefile to make it easier to run
the checks locally.
5 files changed, 137 insertions(+), 83 deletions(-)

R .builds/archlinux.yml => .build.yml
D .builds/archlinux-msrv.yml
D .builds/archlinux-use-system-lib.yml
D .builds/lint.yml
A Makefile
R .builds/archlinux.yml => .build.yml +12 -7
@@ 1,20 1,25 @@
# Copyright (C) 2019-2020 Robin Krahl <robin.krahl@ireas.org>
# Copyright (C) 2019-2022 Robin Krahl <robin.krahl@ireas.org>
# SPDX-License-Identifier: CC0-1.0
image: archlinux
packages:
  - rust
  - gcc
  - hidapi
  - libnitrokey
  - libusb
  - gcc
  - reuse
  - rustup
sources:
  - https://git.sr.ht/~ireas/nitrokey-rs
tasks:
  - build: |
  - setup: |
      cd nitrokey-rs
      cargo build --release
  - test: |
      rustup set profile minimal
      make install-toolchain TOOLCHAIN=stable
      rustup set profile default
      make install-toolchain TOOLCHAIN=msrv
  - ci: |
      cd nitrokey-rs
      cargo test
      make ci
triggers:
  - action: email
    condition: failure

D .builds/archlinux-msrv.yml => .builds/archlinux-msrv.yml +0 -26
@@ 1,26 0,0 @@
# Copyright (C) 2019-2020 Robin Krahl <robin.krahl@ireas.org>
# SPDX-License-Identifier: CC0-1.0
image: archlinux
packages:
  - rustup
  - libnitrokey
environment:
  USE_SYSTEM_LIBNITROKEY: "1"
sources:
  - https://git.sr.ht/~ireas/nitrokey-rs
tasks:
  - setup: |
      rustup set profile minimal
      rustup default 1.40.0
  - version: |
      rustc -V
  - build: |
      cd nitrokey-rs
      cargo build --release
  - test: |
      cd nitrokey-rs
      cargo test
triggers:
  - action: email
    condition: failure
    to: robin.krahl@ireas.org

D .builds/archlinux-use-system-lib.yml => .builds/archlinux-use-system-lib.yml +0 -29
@@ 1,29 0,0 @@
# Copyright (C) 2019-2020 Robin Krahl <robin.krahl@ireas.org>
# SPDX-License-Identifier: CC0-1.0
image: archlinux
packages:
  - rust
  - libnitrokey
environment:
  USE_SYSTEM_LIBNITROKEY: "1"
sources:
  - https://git.sr.ht/~ireas/nitrokey-rs
tasks:
  - version: |
      rustc -V
  - build: |
      cd nitrokey-rs
      cargo build --release
  - test: |
      cd nitrokey-rs
      cargo test
  - format: |
      cd nitrokey-rs
      cargo fmt -- --check
  - clippy: |
      cd nitrokey-rs
      cargo clippy -- -D warnings
triggers:
  - action: email
    condition: failure
    to: robin.krahl@ireas.org

D .builds/lint.yml => .builds/lint.yml +0 -21
@@ 1,21 0,0 @@
# Copyright (C) 2019-2020 Robin Krahl <robin.krahl@ireas.org>
# SPDX-License-Identifier: CC0-1.0
image: archlinux
packages:
  - gnupg
  - python-pip
  - reuse
sources:
  - https://git.sr.ht/~ireas/nitrokey-rs
tasks:
  - verify: |
      cd nitrokey-rs
      curl -s "https://pgp.ireas.org/0x6D533958F070C57C.txt" | gpg --import
      git verify-commit HEAD || [ `git config user.email` == "builds@sr.ht" ]
  - reuse: |
      cd nitrokey-rs
      reuse lint
triggers:
  - action: email
    condition: failure
    to: robin.krahl@ireas.org

A Makefile => Makefile +125 -0
@@ 0,0 1,125 @@
# Copyright (C) 2022 Robin Krahl <robin.krahl@ireas.org>
# SPDX-License-Identifier: CC0-1.0

# Environment {{{1

# This Makefile supports the following environment variables:
# - TOOLCHAIN: toolchain name to use or msrv to use the MSRV toolchain
# - RELEASE: enables the release profile if set to 1

# Variable definitions {{{1

MSRV := 1.40.0
TOOLCHAINS := stable $(MSRV)
BUILD_FLAGS :=
CARGO_TOOLCHAIN :=
RUSTUP_TOOLCHAIN := stable

ifeq ($(TOOLCHAIN), msrv)
override TOOLCHAIN := $(MSRV)
endif

ifdef TOOLCHAIN
CARGO_TOOLCHAIN := +$(TOOLCHAIN)
RUSTUP_TOOLCHAIN := $(TOOLCHAIN)
endif

CARGO := cargo $(CARGO_TOOLCHAIN)

ifeq ($(RELEASE), 1)
BUILD_FLAGS += --release
endif

# Basic recipes {{{1

.PHONY: all
all: lint build

.PHONY: build
build:
	$(CARGO) build $(BUILD_FLAGS) --all-targets

.PHONY: check
check:
	$(CARGO) check $(BUILD_FLAGS) --all-targets

.PHONY: lint
lint: check
	$(CARGO) fmt -- --check
	$(CARGO) clippy -- -D warnings
	reuse lint

.PHONY: fix
fix:
	$(CARGO) fix
	$(CARGO) fmt
	$(CARGO) clippy --fix

.PHONY: clean
clean:
	$(CARGO) clean

.PHONY: clean-nitrokey-sys
clean-nitrokey-sys:
	$(CARGO) clean --package nitrokey-sys

# Test execution {{{1

.PHONY: test
test:
	$(CARGO) test

.PHONY: test-nodev
test-nodev: export NITROKEY_TEST_GROUP=nodev
test-nodev: test

.PHONY: test-librem
test-librem: export NITROKEY_TEST_GROUP=librem
test-librem: test

.PHONY: test-pro
test-pro: export NITROKEY_TEST_GROUP=pro
test-pro: test

.PHONY: test-storage
test-storage: export NITROKEY_TEST_GROUP=storage
test-storage: test

# Toolchain installation {{{1

.PHONY: install-toolchain
install-toolchain:
	rustup install $(RUSTUP_TOOLCHAIN)

.PHONY: install-all-toolchains
install-all-toolchains:
	rustup install $(TOOLCHAINS)

# CI tasks {{{1

.PHONY: ci
ci: ci-msrv ci-stable

.PHONY: ci-lint
ci-lint:
	$(MAKE) lint

.PHONY: ci-build
ci-build: export RELEASE=1
ci-build:
	$(MAKE) build
	$(MAKE) test-nodev
	$(MAKE) clean-nitrokey-sys
	USE_SYSTEM_LIBNITROKEY=1 $(MAKE) build
	USE_SYSTEM_LIBNITROKEY=1 $(MAKE) test-nodev

.PHONY: ci-msrv
ci-msrv: export TOOLCHAIN=msrv
ci-msrv:
	$(MAKE) ci-lint
	$(MAKE) ci-build

.PHONY: ci-stable
ci-stable: export TOOLCHAIN=stable
ci-stable:
	$(MAKE) ci-build