From 30cf91be2486993dcc6da06ce7f1e10804f49408 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Thu, 5 Dec 2024 07:21:26 +0200 Subject: [PATCH] add reusable workflows to helper --- .github/scripts/comment.js | 24 ------- .github/workflows/node.js.yml | 131 +++------------------------------- 2 files changed, 11 insertions(+), 144 deletions(-) delete mode 100644 .github/scripts/comment.js diff --git a/.github/scripts/comment.js b/.github/scripts/comment.js deleted file mode 100644 index e5d0b3f..0000000 --- a/.github/scripts/comment.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = async ({ github, context, header, body }) => { - const comment = [header, body].join("\n") - - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.number, - }) - - const botComment = comments.find( - (comment) => - // github-actions bot user - comment.user.id === 41898282 && comment.body.startsWith(header) - ) - - const commentFn = botComment ? "updateComment" : "createComment" - - await github.rest.issues[commentFn]({ - owner: context.repo.owner, - repo: context.repo.repo, - body: comment, - ...(botComment ? { comment_id: botComment.id } : { issue_number: context.payload.number }), - }) -} diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 2959286..a2089f3 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -1,125 +1,16 @@ -name: Build and Test +name: CI for Solidity Contracts on: - push: - branches: - - master - pull_request: + push: + branches: + - master + pull_request: types: [opened, synchronize, reopened] jobs: - Setup: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "20.9.0" - - - name: Cache node modules - uses: actions/cache@v4 - id: npm-cache - with: - path: | - node_modules - ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - - - name: Install dependencies - if: steps.npm-cache.outputs.cache-hit != 'true' - run: npm i - - Test: - runs-on: ubuntu-latest - if: github.event_name == 'pull_request' # This line ensures that this job only runs on pull requests - needs: Setup - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "20.9.0" - - - name: Cache node modules - uses: actions/cache/restore@v4 - with: - path: | - node_modules - ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - - - name: Run tests - run: npx hardhat test - - Slither-Test: - runs-on: ubuntu-latest - needs: Setup - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "20.9.0" - - - name: Cache node modules - uses: actions/cache/restore@v4 - with: - path: | - node_modules - ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - - - name: Run Slither - uses: crytic/slither-action@v0.3.2 - id: slither - with: - node-version: "20.9.0" - fail-on: high - slither-args: --checklist --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/ - - - name: Create/update checklist as PR comment - uses: actions/github-script@v7 - if: github.event_name == 'pull_request' - env: - REPORT: ${{ steps.slither.outputs.stdout }} - with: - script: | - const script = require('.github/scripts/comment') - const header = '# Slither report' - const body = process.env.REPORT - await script({ github, context, header, body }) - - Coverage-Test: - runs-on: ubuntu-latest - needs: Setup - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "20.9.0" - - - name: Cache node modules - uses: actions/cache/restore@v4 - with: - path: | - node_modules - ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - - - name: Run tests and generate coverage - run: npx hardhat coverage - - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} # required \ No newline at end of file + build: + uses: The-Poolz/solidity-workflows/.github/workflows/build.yml@v0.6.0 + secrets: + codecov_token: ${{ secrets.CODECOV_TOKEN }} + bscscan_api_key: ${{ secrets.BSCSCAN_API_KEY }} + cmc_api_key: ${{ secrets.CMC_API_KEY }} \ No newline at end of file