Skip to content

Refactor - add build:rollup CI (#13) #116

Refactor - add build:rollup CI (#13)

Refactor - add build:rollup CI (#13) #116

Workflow file for this run

name: GitHub Workflows (Lint, Test, Build) Actions
# run workflow manually or during PR
on:
push:
tags:
- '!**'
branches:
- '**'
# Allow one concurrent deployment
# concurrency:
# group: ${{ github.ref }}
# cancel-in-progress: true
jobs:
################################## SECURITY #########################################
# TODO fix this
# security:
# runs-on: ubuntu-latest
# environment:
# name: Production
# steps:
# - uses: actions/checkout@master
# - name: Run Snyk to check for vulnerabilities
# uses: snyk/actions/node@master
# continue-on-error: true # To make sure that SARIF upload gets called
# env:
# SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
# with:
# args: --sarif-file-output=snyk.sarif
# - name: Upload result to GitHub Code Scanning
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: snyk.sarif
################################## INSTALL-DEP #########################################
install-dependencies:
runs-on: ubuntu-latest
name: Install dependencies
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Step Node
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: zip node_modules
run: tar -czf node_modules.tar.gz ./node_modules
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: my_node_modules_artifact
path: node_modules.tar.gz
################################## LINT #########################################
lint:
needs: [install-dependencies]
runs-on: ubuntu-latest
name: Lint and check TS
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Step Node
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: pnpm
- name: Load artifact node_modules
uses: actions/download-artifact@v3
with:
name: my_node_modules_artifact
- name: unzip node_modules
run: tar -xzf node_modules.tar.gz
- name: Lint and ts check
run: |
pnpm ts:check
pnpm lint
# - name: Dependency validation
# run: pnpm dependency:validation
###################################### BUILD #####################################
build:
needs: [install-dependencies]
runs-on: ubuntu-latest
name: Build
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Step Node
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: pnpm
- name: Load artifact node_modules
uses: actions/download-artifact@v3
with:
name: my_node_modules_artifact
- name: unzip node_modules
run: tar -xzf node_modules.tar.gz
- name: Build Storybook
run: pnpm build
- name: Build Rollup Storybook
run: pnpm build:rollup
- name: zip storybook-static
run: tar -czf storybook-static.tar.gz ./storybook-static
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: my_storybook-static_artifact
path: storybook-static.tar.gz
################################## TEST #########################################
test:
needs: [build]
environment:
name: Production
runs-on: ubuntu-latest
name: Test
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Step Node
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: pnpm
- name: Load artifact node_modules
uses: actions/download-artifact@v3
with:
name: my_node_modules_artifact
- name: unzip node_modules
run: tar -xzf node_modules.tar.gz
- name: Load artifact storybook-static
uses: actions/download-artifact@v3
with:
name: my_storybook-static_artifact
- name: unzip storybook-static
run: tar -xzf storybook-static.tar.gz
- name: Install Playwright
run: pnpm dlx playwright install --with-deps
- name: Test CI
run: pnpm test-coverage:ci
- name: zip coverage
run: tar -czf coverage.tar.gz ./coverage
- name: Upload artifact coverage
uses: actions/upload-artifact@v3
with:
name: coverage_artifact
path: coverage.tar.gz
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage/storybook
fail_ci_if_error: true
files: ./coverage/storybook/coverage-storybook.json
verbose: true
################################## DEPLOYMENT ########################################
deployment:
needs: [test]
name: "Deploy on Chromatic"
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment:
name: Production
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # 👈 Required to retrieve git history
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Step Node
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: pnpm
- name: Load artifact node_modules
uses: actions/download-artifact@v3
with:
name: my_node_modules_artifact
- name: unzip node_modules
run: tar -xzf node_modules.tar.gz
- name: Publish to Chromatic
id: chromatic
uses: chromaui/action@v1
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
buildScriptName: build
- name: Publish Summary
run: echo -e "| Results | |\n| --- | --- |\n| Build Results | ${{steps.chromatic.outputs.buildUrl}} |\n| Storybook Preview | ${{steps.chromatic.outputs.storybookUrl}} |\n| Component Count | ${{steps.chromatic.outputs.componentCount}} |" >> $GITHUB_STEP_SUMMARY
################################## Tag Main #########################################
extract-version:
needs: [ test ]
name: "Extract version (package.json)"
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment:
name: Production
outputs:
version: ${{ steps.get-version.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Step Node
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: pnpm
- name: Get version
id: get-version
run: echo "version=$(pnpm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT
shell: bash
create-tag:
needs: [ extract-version ]
name: "Create Tag"
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment:
name: Production
steps:
- uses: actions/checkout@v3
- uses: rickstaa/action-create-tag@v1
id: create-tag
with:
tag: ${{ needs.check-commit.outputs.version }}
tag_exists_error: false
message: ${{ needs.extract-version.outputs.version }}
- run: |
echo "Tag already present: ${{ steps.create-tag.outputs.tag_exists }}"
release:
needs: [ create-tag ]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment:
name: Production
steps:
- uses: actions/checkout@v3
- name: Prepare repository
run: git fetch --unshallow --tags
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Step Node
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: pnpm
- name: Load artifact node_modules
uses: actions/download-artifact@v3
with:
name: my_node_modules_artifact
- name: unzip node_modules
run: tar -xzf node_modules.tar.gz
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
pnpm release