Skip to content

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

Refactor - add build:rollup CI (#13)

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

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]
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 #########################################
tag_main:
needs: [ test ]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment:
name: Production
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: 1 Tag main
run: |
version=$(pnpm pkg get version | tr -d '"')
echo new tag: $version
# git status
# echo create new tag: $version
# git tag -a v$version -m "version $version"
# echo push new tag
# git push --follow-tags origin main
- name: 2 Tag main
run: |
echo new tag: $version
- uses: rickstaa/action-create-tag@v1
id: "tag_create"
with:
tag: $(pnpm pkg get version | tr -d '"')
tag_exists_error: false
message: version $(pnpm pkg get version | tr -d '"')
- run: |
echo "Tag already present: ${{ steps.tag_create.outputs.tag_exists }}"
release:
needs: [ tag_main ]
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