Skip to content

Commit

Permalink
better rust github actions (#66)
Browse files Browse the repository at this point in the history
* rustfmt edition 2018

* rust cargo-audit

* add rustfmt checks

* rename job

* test on nightly and stable

* fix audit workflow syntax

* every day at midnight

* add wasm toolchain

* audit for every push

* use the toolchain init script

* re-enable audit on PR

* back to matrix

* install native packages

* docker only on release publishing

* use officially supported actions

* lowercase repo name

* test docker on push

* attempt to save space by not testing against the stable toolchain

* remove cron in favor of dependabot

* docker image only on published release

* keep it simple, run audits all the times

* simplify rust tests

* only cash our deps

* apt clean ubuntu

* tests with without a third party action
  • Loading branch information
ETeissonniere authored Apr 29, 2020
1 parent 2123078 commit c82df92
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 51 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Security audit

on: [push]

jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/audit-check@issue-104
with:
token: ${{ secrets.GITHUB_TOKEN }}
40 changes: 22 additions & 18 deletions .github/workflows/github_package_registry.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
name: Create node docker image
name: Create docker image

on:
push:
branches:
- master
release:
types: [published]

jobs:
build:

runs-on: ubuntu-latest
push_to_registry:

name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest

steps:
- name: Copy Repo Files
uses: actions/checkout@master
- name: Publish Docker Image to GPR
uses: machine-learning-apps/gpr-docker-publish@master
with:
cache: true
IMAGE_NAME: 'nodle-chain'
TAG: 'latest'
DOCKERFILE_PATH: '.maintain/docker/Dockerfile'
BUILD_CONTEXT: '.'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check out the repo
uses: actions/checkout@v2

- name: Push to GitHub Packages
uses: docker/build-push-action@v1
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
repository: nodlecode/chain/nodle-chain
tag_with_ref: true
dockerfile: '.maintain/docker/Dockerfile'
cache_froms: nodlecode/chain/nodle-chain:latest
add_git_labels: true
49 changes: 35 additions & 14 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,51 @@ name: Test rust code
on: [push]

jobs:
build:

runs-on: ubuntu-latest
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v2

- name: Cache cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Toolchain
- name: Install ubuntu native dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt install -y cmake pkg-config libssl-dev git gcc build-essential clang libclang-dev

- name: Cleanup ubuntu filesystem
if: matrix.os == 'ubuntu-latest'
run: sudo apt clean

- name: Install mac os native dependencies
if: matrix.os == 'macos-latest'
run: brew install openssl cmake llvm

- name: Setup toolchain
run: ./scripts/init.sh

- name: Run tests
run: cargo test --all-targets --all-features --workspace
run: cargo test --all-targets --all-features --workspace

fmt:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup toolchain
run: ./scripts/init.sh

- name: Install rustfmt
run: rustup component add rustfmt

- name: Run cargo fmt
run: cargo fmt --all -- --check
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
edition = "2018"
43 changes: 24 additions & 19 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,10 @@ macro_rules! new_full_start {
macro_rules! new_full {
($config:expr, $with_startup_data: expr) => {{
use futures::prelude::*;
use sc_network::Event;
use sc_client_api::ExecutorProvider;
use sc_network::Event;

let (
role,
force_authoring,
name,
disable_grandpa,
) = (
let (role, force_authoring, name, disable_grandpa) = (
$config.role.clone(),
$config.force_authoring,
$config.network.node_name.clone(),
Expand All @@ -131,24 +126,29 @@ macro_rules! new_full {
let service = builder
.with_finality_proof_provider(|client, backend| {
// GenesisAuthoritySetProvider is implemented for StorageAndProofProvider
let provider = client as Arc<dyn sc_finality_grandpa::StorageAndProofProvider<_, _>>;
Ok(Arc::new(sc_finality_grandpa::FinalityProofProvider::new(backend, provider)) as _)
let provider =
client as Arc<dyn sc_finality_grandpa::StorageAndProofProvider<_, _>>;
Ok(Arc::new(sc_finality_grandpa::FinalityProofProvider::new(
backend, provider,
)) as _)
})?
.build()?;

let (block_import, grandpa_link, babe_link) = import_setup.take()
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
let (block_import, grandpa_link, babe_link) = import_setup.take().expect(
"Link Half and Block Import are present for Full Services or setup failed before. qed",
);

($with_startup_data)(&block_import, &babe_link);

if let sc_service::config::Role::Authority { sentry_nodes } = &role {
let proposer = sc_basic_authorship::ProposerFactory::new(
service.client(),
service.transaction_pool()
service.transaction_pool(),
);

let client = service.client();
let select_chain = service.select_chain()
let select_chain = service
.select_chain()
.ok_or(sc_service::Error::SelectChainRequired)?;

let can_author_with =
Expand All @@ -171,10 +171,15 @@ macro_rules! new_full {
service.spawn_essential_task("babe-proposer", babe);

let network = service.network();
let dht_event_stream = network.event_stream("authority-discovery").filter_map(|e| async move { match e {
Event::Dht(e) => Some(e),
_ => None,
}}).boxed();
let dht_event_stream = network
.event_stream("authority-discovery")
.filter_map(|e| async move {
match e {
Event::Dht(e) => Some(e),
_ => None,
}
})
.boxed();
let authority_discovery = sc_authority_discovery::AuthorityDiscovery::new(
service.client(),
network,
Expand Down Expand Up @@ -227,7 +232,7 @@ macro_rules! new_full {
// if it fails we take down the service with it.
service.spawn_essential_task(
"grandpa-voter",
sc_finality_grandpa::run_grandpa_voter(grandpa_config)?
sc_finality_grandpa::run_grandpa_voter(grandpa_config)?,
);
} else {
sc_finality_grandpa::setup_disabled_grandpa(
Expand All @@ -241,7 +246,7 @@ macro_rules! new_full {
}};
($config:expr) => {{
new_full!($config, |_, _| {})
}}
}};
}

type ConcreteBlock = nodle_chain_runtime::opaque::Block;
Expand Down

0 comments on commit c82df92

Please sign in to comment.