Skip to content

Commit

Permalink
build: combine and optimized workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed May 29, 2023
1 parent ef9894b commit 773641e
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 84 deletions.
18 changes: 18 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'Build'
description: 'Prepares the repo for a job by running the build'

runs:
using: 'composite'
steps:
- name: Use cache
id: 'cache'
uses: actions/cache@v3
with:
path: '**/dist/**'
key: ${{ runner.os }}-build-${{ github.sha }}

- name: Build
shell: bash
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm run build
37 changes: 37 additions & 0 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'Install'
description: 'Prepares the repo for a job by checking out and installing dependencies'
inputs:
node-version:
description: 'The node version to setup'
required: true
registry-url:
description: 'Define registry-url'
required: false

runs:
using: 'composite'
steps:
- name: echo github.ref
shell: bash
run: echo ${{ github.ref }}

- name: Use Node.js ${{ inputs.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}
registry-url: ${{ inputs.registry-url }}

- name: Use cache
uses: actions/cache@v3
with:
path: |
node_modules
*/*/node_modules
key: ${{ runner.os }}-install-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-install-
- name: Install
shell: bash
run: |
npm ci
32 changes: 0 additions & 32 deletions .github/workflows/coverage.yml

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/docs.yml

This file was deleted.

155 changes: 136 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,157 @@ on:
push:
branches: [develop, master, next, beta, alpha]
pull_request:
branches: [develop, master, next, beta, alpha]

permissions:
packages: write
contents: write
issues: write
pull-requests: write

env:
PRIMARY_NODE_VERSION: 18

jobs:
build:
install:
name: Checkout and Install
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install
uses: ./.github/actions/install
with:
node-version: ${{ env.PRIMARY_NODE_VERSION }}

lint:
name: Lint
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install
uses: ./.github/actions/install
with:
node-version: ${{ env.PRIMARY_NODE_VERSION }}

- name: Build
uses: ./.github/actions/build

strategy:
matrix:
node-version: [16.x, 18.x]
- name: Lint
run: |
npm run lint
build:
name: Build
needs: [install]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
- name: Install
uses: ./.github/actions/install
with:
persist-credentials: false
node-version: ${{ env.PRIMARY_NODE_VERSION }}
- name: Build
uses: ./.github/actions/build

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
tests:
name: Test
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install
uses: ./.github/actions/install
with:
node-version: ${{ env.PRIMARY_NODE_VERSION }}

- name: Build
uses: ./.github/actions/build

- name: Run tests
run: |
npm run test
release:
name: Release
needs: [lint, tests]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install
uses: ./.github/actions/install
with:
node-version: ${{ env.PRIMARY_NODE_VERSION }}

- name: Build
uses: ./.github/actions/build

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release

coverage:
name: Coverage
needs: [release]
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'master' }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install
uses: ./.github/actions/install
with:
node-version: ${{ env.PRIMARY_NODE_VERSION }}

- name: Build
uses: ./.github/actions/build

- name: Coverage
run: |
npm run test:coverage
- name: Upload report
uses: codecov/codecov-action@v3.1.4
with:
token: ${{ secrets.codecov }}
directory: ./coverage/

docs:
name: Docs
needs: [release]
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'master' }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install
uses: ./.github/actions/install
with:
node-version: ${{ env.PRIMARY_NODE_VERSION }}

- name: Install dependencies
run: |
npm ci
- name: Build package
run: npm run docs:build

- name: Build package
run: |
npm run build
- name: CNAME
run: |
cd ./docs/.vitepress/dist/
touch CNAME
echo "typeorm-extension.tada5hi.net" > CNAME
- name: Test package
run: |
npm run test
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/.vitepress/dist

0 comments on commit 773641e

Please sign in to comment.