Skip to content

Commit

Permalink
feat: ci/cd (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasyl-ivanchuk authored Sep 20, 2023
1 parent 5471d76 commit 03de076
Show file tree
Hide file tree
Showing 16 changed files with 874 additions and 872 deletions.
File renamed without changes.
72 changes: 72 additions & 0 deletions .github/workflows/app-deploy-feature-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Deploy App To Feature Branch
on: pull_request

jobs:
build:
name: Build and Test App
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./packages/app
outputs:
dappUrl: ${{ steps.deploy.outputs.details_url }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
working-directory: ./
run: |
npm pkg delete scripts.prepare
npm ci
- name: Lint
run: |
npm run lint -- --no-fix --max-warnings 0
- name: Test
run: npm run test:unit:ci

- name: Type check
run: npm run typecheck

- name: Build
run: |
VITE_VERSION=${{ github.head_ref }} \
npm run build
- name: Build Storybook
run: npm run build-storybook

- name: Update config
run: |
echo "window[\"##runtimeConfig\"] = { appEnvironment: \"staging\" };" > dist/config.js
- name: Deploy
uses: matter-labs/action-hosting-deploy@main
id: deploy
with:
repoToken: "${{ github.token }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_STAGING_SCAN_V2 }}"
expires: 7d
projectId: staging-scan-v2
entryPoint: ./packages/app

mainnet:
needs: build
name: Feature Env, Mainnet+
uses: ./.github/workflows/app-e2e.yml
secrets: inherit
with:
targetUrl: ${{ needs.build.outputs.dappUrl }}
default_network_value_for_e2e: "/?network=mainnet"
publish_to_allure: true
environmentTags: "and not @stagingEnv"
70 changes: 70 additions & 0 deletions .github/workflows/app-deploy-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Deploy App to Preview
"on":
workflow_dispatch:
inputs:
version:
type: string
description: "A release version to deploy, e.g. v2.0.0"
required: true
default: "v2.0.0"
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
outputs:
dappUrl: ${{ steps.deploy.outputs.details_url }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download Dist package
uses: dsaltares/fetch-gh-release-asset@master
with:
version: "tags/${{ github.event.inputs.version }}"
file: "dist.zip"
target: "dist.zip"
token: ${{ secrets.GITHUB_TOKEN }}

- name: Unzip Dist package
run: |
unzip dist.zip
- name: Download Storybook package
uses: dsaltares/fetch-gh-release-asset@master
with:
version: "tags/${{ github.event.inputs.version }}"
file: "storybook-static.zip"
target: "storybook-static.zip"
token: ${{ secrets.GITHUB_TOKEN }}

- name: Unzip Storybook package
run: |
unzip storybook-static.zip
- name: Deploy
id: deploy
uses: matter-labs/action-hosting-deploy@main
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SCAN_V2 }}'
expires: 7d
projectId: scan-v2
channelID: ${{ github.event.inputs.version }}

- name: Output version url on success
run: |
run: |
echo "Block explorer app has been deployed to: ${{ steps.deploy.outputs.details_url }}"
mainnet:
needs: deploy
name: Staging Env, Mainnet+
uses: ./.github/workflows/app-e2e.yml
secrets: inherit
with:
targetUrl: ${{ needs.deploy.outputs.dappUrl }}
default_network_value_for_e2e: "/?network=mainnet"
publish_to_allure: true
environmentTags: "and not @featureEnv"
51 changes: 51 additions & 0 deletions .github/workflows/app-deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Deploy App to Production
"on":
workflow_dispatch:
inputs:
version:
type: string
description: "A release version to deploy, e.g. v2.0.0"
required: true
default: "v2.0.0"
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Download Dist package
uses: dsaltares/fetch-gh-release-asset@master
with:
version: "tags/${{ github.event.inputs.version }}"
file: "dist.zip"
target: "dist.zip"
token: ${{ secrets.GITHUB_TOKEN }}

- name: Unzip Dist package
run: |
unzip dist.zip
- name: Download Storybook package
uses: dsaltares/fetch-gh-release-asset@master
with:
version: "tags/${{ github.event.inputs.version }}"
file: "storybook-static.zip"
target: "storybook-static.zip"
token: ${{ secrets.GITHUB_TOKEN }}

- name: Unzip Storybook package
run: |
unzip storybook-static.zip
- name: Deploy
id: deploy
uses: matter-labs/action-hosting-deploy@main
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SCAN_V2 }}'
projectId: scan-v2
channelID: live
144 changes: 144 additions & 0 deletions .github/workflows/app-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: BE App E2E tests
on:
workflow_call:
secrets:
ALLURE_TOKEN:
description: 'A token passed from the caller workflow'
required: true
inputs:
environmentTags:
type: string
default: ''
required: false
targetUrl:
type: string
default: 'https://staging-scan-v2.zksync.dev/'
required: true
default_network_value_for_e2e:
type: string
default: '/?network=mainnet'
required: true
publish_to_allure: #Here we define the variable that can be overwritten by caller workflow
type: boolean
description: "Publish test results to allure"
default: true
required: false

env:
ALLURE_TOKEN: ${{ secrets.ALLURE_TOKEN }}
ALLURE_SEARCH_REQUEST: '[{"id":"name","type":"string","value":"#${{ github.run_number }}"}]'
ALLURE_BASIC_TAGS: "${{ github.head_ref }}, #${{ github.run_number }}, ${{ github.event.pull_request.title }}"
ALLURE_PROJECT_ID: ${{ vars.ALLURE_PROJECT_ID }}
ALLURE_ENDPOINT: ${{ vars.ALLURE_ENDPOINT }}

jobs:
e2e:
runs-on: [self-hosted, ci-runner]
defaults:
run:
working-directory: ./packages/app
strategy:
fail-fast: false
matrix:
tags: [
"@artifactsSet1",
"@artifactsSet2",
"@artifactsSet3",
"@artifactsSet4",
"@redirectionSet1",
"@redirectionSet2",
"@redirectionSet3",
"@copying",
"@search",
"@testnetSmokeSuite"
]

name: '${{ matrix.tags }}'
container:
image: mcr.microsoft.com/playwright:v1.27.0-focal
options: --user root
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install dependencies
working-directory: ./
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
run: |
npm pkg delete scripts.prepare
npm ci
- name: Download allurectl
run: wget https://github.com/allure-framework/allurectl/releases/latest/download/allurectl_linux_386 -O ./allurectl

- name: Change permission for allurectl
run: chmod +x ./allurectl

- name: Launch tests
env:
CI: 'true'
TARGET_ENV: ${{ inputs.targetUrl }}
run: |
echo "Run tests"
if [ "${{ matrix.tags }}" = "@testnetSmokeSuite" ]; then
echo "Run in testnetSmokeSuite only"
E2ENETWORK='/?network=goerli' npx cucumber-js --tags "${{ matrix.tags }} ${{ inputs.environmentTags }} and not @mainnet"
else
echo "Run in mainnet"
E2ENETWORK='${{ inputs.default_network_value_for_e2e }}' npx cucumber-js --tags "${{ matrix.tags }} ${{ inputs.environmentTags }} and not @testnet"
fi
- name: Reset tags quotes
if: always()
run: |
echo "MATRIX_TAG_WITHOUT_QUOTES=$(echo ${{ matrix.tags }} | sed -e 's/@//g' )" >> $GITHUB_ENV
- name: Create launch ID
if: always()
env:
ALLURE_LAUNCH_NAME: "#${{ github.run_number }} ${{ env.MATRIX_TAG_WITHOUT_QUOTES }}"
ALLURE_LAUNCH_TAGS: "${{ env.ALLURE_BASIC_TAGS }}, ${{ env.MATRIX_TAG_WITHOUT_QUOTES }}"
run: |
echo "ALLURE_LAUNCH_ID=$(./allurectl launch create --launch-name '${{ env.ALLURE_LAUNCH_NAME }}' --no-header --format ID | tail -n1)" >> $GITHUB_ENV
- name: Upload tests to the Allure proj
if: always() && inputs.publish_to_allure == true
run: |
./allurectl upload allure-results --launch-id ${{ env.ALLURE_LAUNCH_ID }}
./allurectl launch close ${{ env.ALLURE_LAUNCH_ID }}
- if: failure()
name: Save artifacts
uses: actions/upload-artifact@v3
with:
name: portal_e2e_${{ github.run_number }}_artifacts
path: packages/app/tests/e2e/artifacts/*

publish:
name: Publish Allure link to GIT
runs-on: ubuntu-latest
needs: e2e
if: always()
steps:
- name: Prepare a link
run: |
echo "BASE64_SEARCH_REQUEST=$(echo '${{ env.ALLURE_SEARCH_REQUEST }}' | base64)" >> $GITHUB_ENV
- name: Publish Allure link to GIT Summary
run: |
LINK="${{ vars.ALLURE_ENDPOINT }}project/${{ vars.ALLURE_PROJECT_ID }}/launches?search=${{ env.BASE64_SEARCH_REQUEST }}"
echo "Allure [e2e tests]($LINK) :rocket: in git run #${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY
Loading

0 comments on commit 03de076

Please sign in to comment.