Skip to content

Commit

Permalink
Merge branch 'master' into wsdeps
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Aug 17, 2023
2 parents 88f7ca4 + 41d87a8 commit b097bcc
Show file tree
Hide file tree
Showing 114 changed files with 13,990 additions and 1,340 deletions.
51 changes: 51 additions & 0 deletions .github/actions/common-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Common setup"
description: "Apply the common setup steps for this codebase"
inputs:
platformCacheKey:
description: "The key for the cache for the platform; if empty the caching will be disabled"
required: false
default: ""
modeCacheKey:
description: "The key for the cache for the mode"
required: false
default: ""
requiresRust:
description: "Requires rust to be installed"
required: false
default: "true"
isOnSelfHostedRunner:
description: "Enable if running on a self-hosted runner"
required: false
default: "false"
buildEnvScript:
description: "The script to run to bootstrap the given environment"
required: false
default: ""
runs:
using: "composite"
steps:
- name: Cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ inputs.modeCacheKey == '' && inputs.platformCacheKey || ''}}
shared-key: ${{ inputs.modeCacheKey != '' && format('{0}-{1}', inputs.platformCacheKey, inputs.modeCacheKey) || '' }}
if: ${{ inputs.platformCacheKey != '' && inputs.isOnSelfHostedRunner != 'true' && inputs.requiresRust == 'true' }}

- name: Install rust toolchain
shell: bash
run: rustup show
if: ${{ inputs.requiresRust == 'true' }}

- name: Prepare the build environment
uses: ./.github/actions/env
with:
script: ${{ inputs.buildEnvScript }}
if: ${{ inputs.buildEnvScript != 'skip' }}

- name: Print build environment info
shell: bash
run: |
set -x
cargo --version
cargo clippy --version
env
18 changes: 9 additions & 9 deletions .github/actions/env/action.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: 'Prepare environment'
description: 'Prepare the environment for the build/deployment/etc'
name: "Prepare environment"
description: "Prepare the environment for the build/deployment/etc"
inputs:
script:
description: 'The script to run to bootstrap the given environment'
description: "The script to run to bootstrap the given environment"
required: false
runs:
using: "composite"
steps:
- name: Prepare the build environment
run: ${{ inputs.script }}
shell: bash
- name: Prepare the build environment
run: ${{ inputs.script }}
shell: bash

- name: Set up Vistual Studio Command Prompt (Windows only)
uses: ilammy/msvc-dev-cmd@v1
if: runner.os == 'Windows'
- name: Set up Vistual Studio Command Prompt (Windows only)
uses: ilammy/msvc-dev-cmd@v1
if: runner.os == 'Windows'
25 changes: 9 additions & 16 deletions .github/actions/plan/action.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
name: 'Plan'
description: 'Plan the execution and output a build matrix'
name: "Plan"
description: "Plan the execution and output a build matrix"
inputs:
plan-name:
description: 'What plan to use'
description: "What plan to use"
required: true
outputs:
matrix:
description: 'The build matrix generated from planning'
value: ${{ steps.set-matrix.outputs.matrix }}
description: "The build matrix generated from planning"
value: ${{ steps.plan.outputs.matrix }}
runs:
using: "composite"
steps:
- name: Compute matrix
uses: actions/github-script@v6
id: set-matrix
env:
PLAN_NAME: ${{ inputs.plan-name }}
ACTION_PATH: ${{ github.action_path }}
- uses: MOZGIII/[email protected]
id: plan
with:
script: |
const planners = require(`${process.env.ACTION_PATH}/plan.js`);
const planner = planners[process.env.PLAN_NAME];
const matrix = planner();
core.setOutput('matrix', matrix);
plan-file: ${{ github.action_path }}/plan.ts
plan: ${{ inputs.plan-name }}
34 changes: 34 additions & 0 deletions .github/actions/plan/matrix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export const matrixItems = <T extends Record<string, any>>(
map: T
): Array<T[keyof T]> => Object.values(map);

export const matrixItemsFiltered = <T extends Record<string, any>>(
map: T,
predicate: <K extends keyof T>(item: T[K]) => boolean
): Array<T[keyof T]> => matrixItems<T>(map).filter(predicate);

export const evalMatrix = <Keys extends string>(
dimensions: Record<Keys, Array<any>>,
includes: Array<Record<Keys, any>>
): Array<Record<Keys, any>> => {
const evalNext = (
allVariants: Array<Partial<Record<Keys, any>>>,
key: Keys,
values: Array<any>
) =>
allVariants.flatMap((variant) =>
values.map((value) => ({ ...variant, [key]: value }))
);
const dimensionKeys = Object.keys(dimensions) as Array<
keyof typeof dimensions
>;
const evaluated = dimensionKeys.reduce(
(allVariants, dimensionKey) =>
evalNext(allVariants, dimensionKey, dimensions[dimensionKey]),
[{}] as Array<Partial<Record<Keys, any>>>
) as Array<Record<Keys, any>>;
return [...evaluated, ...includes];
};

export const logMatrix = (matrix: any) =>
console.log(JSON.stringify(matrix, null, " "));
72 changes: 72 additions & 0 deletions .github/actions/plan/modes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
export type Mode = {
name: string;
cargoCommand: string;
cargoArgs: string;
cargoCacheKey: string;
platformIndependent?: true;
};

export type Modes = Record<string, Mode>;

export const code = {
clippy: {
name: "clippy",
cargoCommand: "clippy",
cargoArgs: "--workspace --all-targets -- -D warnings",
cargoCacheKey: "clippy",
},
test: {
name: "test",
cargoCommand: "test",
cargoArgs: "--workspace",
cargoCacheKey: "test",
},
build: {
name: "build",
cargoCommand: "build",
cargoArgs: "--workspace",
cargoCacheKey: "build",
},
fmt: {
name: "fmt",
cargoCommand: "fmt",
cargoArgs: "-- --check",
platformIndependent: true,
cargoCacheKey: "code",
},
docs: {
name: "doc",
cargoCommand: "doc",
cargoArgs: "--workspace --document-private-items",
platformIndependent: true,
cargoCacheKey: "doc",
},
testBenchmark: {
name: "test benchmark",
cargoCommand: "test",
cargoArgs: "--workspace --features runtime-benchmarks",
cargoCacheKey: "test-benchmark",
},
runBenchmark: {
name: "test-run pallet benchmarks",
cargoCommand: "run",
cargoArgs:
"-p humanode-peer --release --features runtime-benchmarks benchmark pallet --chain benchmark --execution native --pallet '*' --extrinsic '*' --steps 2 --repeat 0 --external-repeat 0",
cargoCacheKey: "run-benchmark",
},
buildTryRuntime: {
name: "build with try-runtime",
cargoCommand: "build",
cargoArgs: "--workspace --features try-runtime",
cargoCacheKey: "try-runtime",
},
} satisfies Modes;

export const build = {
build: {
name: "build",
cargoCommand: "build",
cargoArgs: "--workspace --release",
cargoCacheKey: "release-build",
},
} satisfies Modes;
Loading

0 comments on commit b097bcc

Please sign in to comment.