Skip to content

Commit

Permalink
chore: refactor github actions using reusable workflows
Browse files Browse the repository at this point in the history
Architecture:

- on push to main branch will trigger:
  - publish-gh-pages:
    1. trigger run-frontend-test.yml
    2. publish gh-pages
  - publish-tauri-apps:
    1. trigger run-frontend-test.yml
    2. publish tauri app
- on push to other branches will trigger:
  - trigger run-frontend-test.yml
- on pull request will trigger:
  - run-build-test-on-pr:
    1. trigger run-frontend-test.yml
    2. build tauri app (don't publish)

Changes:

publish -> publish-tauri-apps
test-on-pr -> run-build-test-on-pr

New:

run-frontend-test.yml:
  Reusable workflow for running frontend test.
  This is used by publish-gh-pages, publish-tauri-apps, run-build-test-on-pr.
  • Loading branch information
r4ai committed Mar 31, 2023
1 parent 7b0ce25 commit f4c716c
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 20 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/publish-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ name: publish-gh-pages

on:
push:
branches: ["main"]
branches:
- "main"

permissions:
contents: read
pages: write
id-token: write

jobs:
# Build job
run-frontend-test:
uses: ./.github/workflows/run-frontend-test.yml

build:
needs: [run-frontend-test]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ on:
- main

jobs:
run-frontend-test:
uses: ./.github/workflows/run-frontend-test.yml

publish-tauri:
needs: [run-frontend-test]
permissions:
contents: write
strategy:
Expand Down Expand Up @@ -58,11 +62,7 @@ jobs:
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: install frontend dependencies
run: pnpm install # change this to npm or pnpm depending on which one you use

- name: run frontend test
if: matrix.platform != 'windows-latest'
run: pnpm test
run: pnpm install

- uses: tauri-apps/tauri-action@v0
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: "test-on-pr"
on: [pull_request]

jobs:
test-tauri:
run-frontend-test:
uses: ./.github/workflows/run-frontend-test.yml

run-tauri-build-test:
needs: [run-frontend-test]
strategy:
fail-fast: false
matrix:
Expand All @@ -12,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: setup node
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
Expand All @@ -38,27 +42,24 @@ jobs:
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: install Rust stable
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable

- name: chache cargo
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: "src-tauri -> target"

- name: install dependencies (ubuntu only)
- name: Install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-20.04'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: install frontend dependencies
run: pnpm install # change this to npm or pnpm depending on which one you use

- name: run frontend test
if: matrix.platform != 'windows-latest'
run: pnpm test
- name: Install frontend dependencies
run: pnpm install

- uses: tauri-apps/tauri-action@v0
- name: Build tauri app
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52 changes: 52 additions & 0 deletions .github/workflows/run-frontend-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: run-frontend-tests

on:
push:
branches-ignore:
- main
workflow_call:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install pnpm
uses: pnpm/action-setup@v2
id: pnpm-install
with:
version: 7
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Selte Check
run: pnpm check

- name: Run test
run: pnpm test
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "tinnitus-reducer-ACRN",
"version": "0.1.1"
"version": "0.1.2"
},
"tauri": {
"allowlist": {
Expand Down

0 comments on commit f4c716c

Please sign in to comment.