Skip to content

Commit

Permalink
[workflow] Extract linting into a reusable workflow (#953)
Browse files Browse the repository at this point in the history
* Extract linting into a reusable workflow
  • Loading branch information
rimrakhimov authored Jun 27, 2024
1 parent 5e5811d commit eafa3da
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: 'Setup'
description: 'Checkout repository, setup rust toolchain and dependencies'

inputs:
service-name:
description: 'A directory name where the service target is located'
working-directory:
description: 'A directory where the service code is located'
required: true
components:
description: Comma-separated list of components to be additionally installed
Expand All @@ -24,4 +24,4 @@ runs:
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
workspaces: '${{ inputs.workspaces }} -> target'
workspaces: '${{ inputs.working-directory }} -> target'
23 changes: 6 additions & 17 deletions .github/workflows/da-indexer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ on:
- da-indexer/**
- .github/workflows/da-indexer.yml
- .github/workflows/_*.yml
- .github/workflows/r_*.yml
- .github/actions/**
pull_request:
paths:
- da-indexer/**
- .github/workflows/da-indexer.yml
- .github/workflows/_*.yml
- .github/workflows/r_*.yml
- .github/actions/**

name: Test, lint and docker (da-indexer)
Expand Down Expand Up @@ -46,7 +48,7 @@ jobs:
- name: Setup
uses: ./.github/actions/setup
with:
service-name: da-indexer
working-directory: da-indexer

- name: Unit tests
run: RUST_BACKTRACE=1 RUST_LOG=info cargo test --locked --workspace --all-features --lib --bins -- --nocapture
Expand All @@ -67,22 +69,9 @@ jobs:

lint:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup
with:
service-name: da-indexer
components: rustfmt, clippy

- name: cargo fmt
run: cargo fmt --all -- --check --config imports_granularity=Crate

- name: cargo clippy
run: cargo clippy --all --all-targets --all-features -- -D warnings
uses: ./.github/workflows/r_linting.yml
with:
working-directory: da-indexer

docker:
name: Docker build and docker push
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/r_linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Linting (reusable)

on:
workflow_call:
inputs:
working-directory:
required: true
type: string

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup
with:
working-directory: ${{ inputs.working-directory }}
components: rustfmt, clippy

- name: cargo fmt
run: cargo fmt --all -- --check --config imports_granularity=Crate
working-directory: ${{ inputs.working-directory }}

- name: cargo clippy
run: cargo clippy --all --all-targets --all-features -- -D warnings
working-directory: ${{ inputs.working-directory }}

0 comments on commit eafa3da

Please sign in to comment.