Refacto - update CI #126
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/mainFALSE' | |
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 package version" | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/mainFALSE' | |
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: | | |
version=v$(pnpm pkg get version | tr -d '"') | |
echo "version=$version" >> $GITHUB_OUTPUT | |
echo "====> $version" | |
shell: bash | |
create-tag: | |
needs: [ extract-version ] | |
name: "Create Tag" | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/mainFALSE' | |
environment: | |
name: Production | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: rickstaa/action-create-tag@v1 | |
id: create-tag | |
with: | |
tag: ${{ needs.extract-version.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: [ test ] | |
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: Get package version | |
id: get-version | |
run: | | |
version=v$(pnpm pkg get version | tr -d '"') | |
echo "version=$version" >> $GITHUB_OUTPUT | |
echo "====> $version" | |
shell: bash | |
- uses: rickstaa/action-create-tag@v1 | |
id: create-tag | |
with: | |
tag: ${{ steps.get-version.outputs.version }} | |
tag_exists_error: false | |
message: ${{ steps.get-version.outputs.version }} | |
- run: | | |
echo "Tag already present: ${{ steps.create-tag.outputs.tag_exists }}" | |
## # | |
- name: Extract release notes from CHANGELOG.md | |
id: extract-release-notes | |
uses: ffurrer2/extract-release-notes@v1 | |
with: | |
changelog_file: CHANGELOG.md | |
- name: "Create a GitHub release ${{ steps.get-version.outputs.version }}" | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: "v${{ steps.get-version.outputs.version }}" | |
name: "Release v${{ steps.get-version.outputs.version }}" | |
body: | | |
## Release notes: | |
${{ steps.extract-release-notes.outputs.release_notes }} |