Skip to content

Commit

Permalink
Filter github actions in a more granular way
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsgrd committed Aug 17, 2023
1 parent 7b569b0 commit e3bc5d7
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 83 deletions.
59 changes: 59 additions & 0 deletions .github/actions/init-env/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: prepare
description: Determine what kind of change has taken place
inputs:
runs-on:
description: |
Filter by project type, must be named filter from step `changes`
default: 'all'
runs:
using: 'composite'
steps:
- name: Getting changes
id: changes
uses: dorny/paths-filter@v2
with:
filters: |
backend:
- 'src-tauri/**'
frontend:
- 'src/**'
- '.github/**'
- 'package.json'
- '*.config.*'
- 'tsconfig.json'
- '.npmrc'
- '.env.*'
- uses: pnpm/action-setup@v2
name: Install pnpm
if: ${{ inputs.runs-on == 'all' || steps.changes.outputs[inputs.runs-on] == 'true' }}
with:
version: 8.6
run_install: false

- uses: actions/setup-node@v3
name: Setup node
if: ${{ inputs.runs-on == 'all' || steps.changes.outputs[inputs.runs-on] == 'true' }}
with:
node-version: '18'
cache: pnpm

- name: Get pnpm store directory
shell: bash
if: ${{ inputs.runs-on == 'all' || steps.changes.outputs[inputs.runs-on] == 'true' }}
run: |
echo 'STORE_PATH=$(pnpm store path --silent)' >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
if: ${{ inputs.runs-on == 'all' || steps.changes.outputs[inputs.runs-on] == 'true' }}
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
if: ${{ inputs.runs-on == 'all' || steps.changes.outputs[inputs.runs-on] == 'true' }}
shell: bash
run: pnpm install
43 changes: 0 additions & 43 deletions .github/actions/pnpm-install/action.yml

This file was deleted.

74 changes: 34 additions & 40 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup pnpm
uses: ./.github/actions/pnpm-install
- uses: ./.github/actions/init-env
id: init
with:
runs-on: frontend

- name: Lint frontend

run: |
export NODE_OPTIONS="--max_old_space_size=4096"
pnpm lint
check-frontend:
Expand All @@ -23,8 +23,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup pnpm
uses: ./.github/actions/pnpm-install
- uses: ./.github/actions/init-env
id: init
with:
runs-on: frontend

- name: check frontend
run: |
Expand All @@ -36,8 +38,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup pnpm
uses: ./.github/actions/pnpm-install
- uses: ./.github/actions/init-env
id: init
with:
runs-on: frontend

- name: check frontend
run: |
Expand All @@ -49,24 +53,21 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

# Filter on steps instead of on jobs, so that we can keep GitHub branch protection for this job
- name: Getting changes
id: changes
uses: dorny/paths-filter@v2
- uses: ./.github/actions/init-env
id: init
with:
filters: |
rust:
- 'src-tauri/**'
runs-on: backend

- name: Install latest stable rust
if: ${{ steps.changes.outputs.rust == 'true' }}
if: ${{ steps.init.outputs.backend == 'true' }}
uses: actions-rs/toolchain@v1
with:
override: true
toolchain: stable
components: rustfmt

- run: cargo fmt --check
if: ${{ steps.changes.outputs.rust == 'true' }}
if: ${{ steps.init.outputs.backend == 'true' }}
working-directory: src-tauri


Expand All @@ -76,10 +77,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Setup pnpm
uses: ./.github/actions/pnpm-install
- uses: ./.github/actions/init-env
id: init
with:
runs-on: frontend

- name: Build storybook
if: ${{ steps.init.outputs.frontend == 'true' }}
run: pnpm story:build

test:
Expand All @@ -88,57 +92,47 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

# Filter on steps instead of on jobs, so that we can keep GitHub branch protection for this job
- name: Getting changes
id: changes
uses: dorny/paths-filter@v2
with:
filters: |
rust:
- 'src-tauri/**'
- name: Setup pnpm
uses: ./.github/actions/pnpm-install
- uses: ./.github/actions/init-env
id: init
with:
file-type: 'rust'

runs-on: backend

- name: Install latest stable rust
if: ${{ steps.changes.outputs.rust == 'true' }}
if: ${{ steps.init.outputs.backend == 'true' }}
uses: actions-rs/toolchain@v1
with:
override: true
toolchain: stable
components: rustfmt, clippy

- name: Cache rust dependencies
if: ${{ steps.changes.outputs.rust == 'true' }}
if: ${{ steps.init.outputs.backend == 'true' }}
uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri

- run: sudo apt-get update
if: runner.os == 'Linux'
if: ${{ steps.init.outputs.backend == 'true' && runner.os == 'Linux' }}
- name: Install system dependencies
uses: daaku/gh-action-apt-install@v4
if: runner.os == 'Linux'
if: ${{ steps.init.outputs.backend == 'true' && runner.os == 'Linux' }}
with:
# https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux
packages: libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev

- name: Build frontend
if: ${{ steps.changes.outputs.rust == 'true' }}
if: ${{ steps.init.outputs.backend == 'true' }}
run: pnpm build

- name: Install clippy
if: ${{ steps.changes.outputs.rust == 'true' }}
if: ${{ steps.init.outputs.backend == 'true' }}
run: rustup component add clippy

- run: cargo clippy --all-features
if: ${{ steps.changes.outputs.rust == 'true' }}
if: ${{ steps.init.outputs.backend == 'true' }}
working-directory: src-tauri

- name: Test rust
if: ${{ steps.changes.outputs.rust == 'true' }}
if: ${{ steps.init.outputs.backend == 'true' }}
working-directory: src-tauri
run: cargo test --locked

0 comments on commit e3bc5d7

Please sign in to comment.