From 1903e3ae5cb7c365e65f16f3e5d47c34feffab7b Mon Sep 17 00:00:00 2001 From: sviatoslav Date: Thu, 29 Oct 2020 14:33:16 +0200 Subject: [PATCH] Added CI/CD workflows --- .github/workflows/linting.yml | 97 ++++++++++++++++++++++++++++++++++ .github/workflows/node.js.yml | 36 ------------- .github/workflows/security.yml | 93 ++++++++++++++++++++++++++++++++ .github/workflows/testing.yml | 66 +++++++++++++++++++++++ 4 files changed, 256 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/linting.yml delete mode 100644 .github/workflows/node.js.yml create mode 100644 .github/workflows/security.yml create mode 100644 .github/workflows/testing.yml diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 0000000..6e1bda9 --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,97 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Linting + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + linting: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [12.x] + + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Staring Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Restoring Yarn cache + uses: actions/cache@v2 + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + + - name: Bootstraping packages + if: steps.yarn-cache.outputs.cache-hit != 'true' + run: yarn install + + - name: Get file changes + id: get_file_changes + uses: trilom/file-changes-action@v1.2.3 + with: + output: ' ' + + - name: Echo file changes + id: hello + run: | + echo Added files: ${{ steps.get_file_changes.outputs.files_added }} + echo Changed files: ${{ steps.get_file_changes.outputs.files_modified }} + echo Removed files: ${{ steps.get_file_changes.outputs.files_removed }} + + - name: Prettier Checking + if: ${{ always() && (steps.get_file_changes.outputs.files_added || steps.get_file_changes.outputs.files_modified) }} + run: yarn prettier --config ./prettier.config.js --ignore-path ./.prettierignore ${{ steps.get_file_changes.outputs.files_added }} ${{ steps.get_file_changes.outputs.files_modified }} --fix + + - name: ESLint Checking + if: ${{ always() && (steps.get_file_changes.outputs.files_added || steps.get_file_changes.outputs.files_modified) }} + run: yarn eslint --config ./.eslintrc.js --ignore-path ./.eslintignore ${{ steps.get_file_changes.outputs.files_added }} ${{ steps.get_file_changes.outputs.files_modified }} --fix + + - name: TSLint Checking + if: ${{ always() && (steps.get_file_changes.outputs.files_added || steps.get_file_changes.outputs.files_modified) }} + run: yarn tslint --config ./tslint.json -e "**/*.(js|jsx|css|scss|html|md|json|yml)" ${{ steps.get_file_changes.outputs.files_added }} ${{ steps.get_file_changes.outputs.files_modified }} --fix + + - name: StyleLint Checking + if: ${{ always() && (steps.get_file_changes.outputs.files_added || steps.get_file_changes.outputs.files_modified) }} + run: yarn stylelint --config ./.stylelintrc --ignore-path ./.stylelintignore --allow-empty-input ${{ steps.get_file_changes.outputs.files_added }} ${{ steps.get_file_changes.outputs.files_modified }} --fix + + - name: Commit changes + if: always() + uses: stefanzweifel/git-auto-commit-action@v4.1.2 + with: + commit_message: Apply formatting changes +# branch: ${{ github.head_ref }} + + - name: Slack Notification + uses: 8398a7/action-slack@v3.8.0 + if: failure() + with: + status: custom + fields: workflow,job,commit,repo,ref,author,took + custom_payload: | + { + username: 'React-Apps-CI', + icon_emoji: ':react:', + author_name: 'Linting Test', + attachments: [{ + color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning', + text: `CI Task: ${process.env.AS_WORKFLOW}\ncommit: (${process.env.AS_COMMIT}) ${{ github.event_name }} ${{ job.status }}. Initiated by ${process.env.AS_AUTHOR} in ${process.env.AS_TOOK}`, + }] + } + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + MATRIX_CONTEXT: ${{ toJson(matrix) }} + diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml deleted file mode 100644 index a7bec83..0000000 --- a/.github/workflows/node.js.yml +++ /dev/null @@ -1,36 +0,0 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: Node.js CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [12.x] - - steps: - - uses: actions/checkout@v2 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: Installing Yarn and Lerna - - run: npm install -g yarn lerna - - - name: Bootstaping repo with Lerna - - run: yarn install - - - name: Unit Testing - - run: yarn jest diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml new file mode 100644 index 0000000..7c63c73 --- /dev/null +++ b/.github/workflows/security.yml @@ -0,0 +1,93 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +name: "Security" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '0 15 * * 6' + +jobs: + security: + name: Analyze + runs-on: macos-latest + + strategy: + fail-fast: false + matrix: + # Override automatic language detection by changing the below list + # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] + language: ['javascript', 'typescript'] + # Learn more... + # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + # We must fetch at least the immediate parents so that if this is + # a pull request then we can checkout the head. + fetch-depth: 2 + + # If this run was triggered by a pull request event, then checkout + # the head of the pull request instead of the merge commit. + - run: git checkout HEAD^2 + if: ${{ github.event_name == 'pull_request' }} + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 + + - name: Slack Notification + uses: 8398a7/action-slack@v3.8.0 + if: failure() + with: + status: custom + fields: workflow,job,commit,repo,ref,author,took + custom_payload: | + { + username: 'React-Apps-CI', + icon_emoji: ':react:', + author_name: 'Security Test', + attachments: [{ + color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning', + text: `CI Task: ${process.env.AS_WORKFLOW}\ncommit: (${process.env.AS_COMMIT}) ${{ github.event_name }} ${{ job.status }}. Initiated by ${process.env.AS_AUTHOR} in ${process.env.AS_TOOK}`, + }] + } + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + MATRIX_CONTEXT: ${{ toJson(matrix) }} + diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..203d849 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,66 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Unit + UI Testing + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + unit-ui-testing: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [12.x] + + steps: + - uses: actions/checkout@v2 + - name: Staring Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Restoring Yarn cache + uses: actions/cache@v2 + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + + - name: Bootstraping packages + if: steps.yarn-cache.outputs.cache-hit != 'true' + run: yarn install + + - name: Testing Shared Utils + if: always() + run: yarn jest ./shared + + - name: Testing Storybook UI + if: always() + run: yarn storybook:build + + - name: Slack Notification + uses: 8398a7/action-slack@v3.8.0 + if: failure() + with: + status: custom + fields: workflow,job,commit,repo,ref,author,took + custom_payload: | + { + username: 'React-Apps-CI', + icon_emoji: ':react:', + author_name: 'Unit + UI Integration Test', + attachments: [{ + color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning', + text: `CI Task: ${process.env.AS_WORKFLOW}\ncommit: (${process.env.AS_COMMIT}) ${{ github.event_name }} ${{ job.status }}. Initiated by ${process.env.AS_AUTHOR} in ${process.env.AS_TOOK}`, + }] + } + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + MATRIX_CONTEXT: ${{ toJson(matrix) }} +