Add solution for part 4 #63
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: CI | |
on: | |
push: | |
workflow_dispatch: | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Build contracts | |
id: build | |
run: npm run compile | |
- name: 'Add build summary' | |
if: ${{ success() || failure() }} | |
run: | | |
echo "## Build result" >> $GITHUB_STEP_SUMMARY | |
- name: 'Add build result (success)' | |
if: ${{ success() && steps.build.outcome == 'success' }} | |
run: | | |
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY | |
- name: 'Add build result (failed)' | |
if: ${{ failure() && steps.build.outcome == 'failure' }} | |
run: | | |
echo "❌ Failed" >> $GITHUB_STEP_SUMMARY | |
test: | |
name: Test | |
runs-on: ubuntu-latest | |
needs: [build] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Test contracts | |
id: run_tests | |
run: | | |
(npm run --silent test >> /tmp/TEST_OUTPUT) || FAILED=1 | |
{ | |
echo "test_output<<RANDOM_DELIMITER_THAT_MOST_DEFINITELY_WONT_APPEAR_IN_TEXT" | |
cat /tmp/TEST_OUTPUT | |
echo "RANDOM_DELIMITER_THAT_MOST_DEFINITELY_WONT_APPEAR_IN_TEXT" | |
} >> "$GITHUB_OUTPUT" | |
cat /tmp/TEST_OUTPUT | |
if [ ${FAILED:-0} -eq 1 ] | |
then | |
exit 1 | |
fi | |
- name: 'Add test summary' | |
if: ${{ success() || failure() }} | |
run: | | |
echo "## Tests result" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
echo "${{steps.run_tests.outputs.test_output}}" >> $GITHUB_STEP_SUMMARY | |
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
- name: 'Add test result (success)' | |
if: ${{ success() && steps.run_tests.outcome == 'success' }} | |
run: | | |
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY | |
- name: 'Add test result (failed)' | |
if: ${{ failure() && steps.run_tests.outcome == 'failure' }} | |
run: | | |
echo "❌ Failed" >> $GITHUB_STEP_SUMMARY | |
eslint: | |
name: ESLint | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Run ESLint | |
uses: reviewdog/action-eslint@v1 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
reporter: github-check | |
filter_mode: nofilter | |
level: info | |
prettier: | |
name: Prettier | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- uses: EPMatt/reviewdog-action-prettier@v1 | |
with: | |
github_token: ${{ secrets.github_token }} | |
reporter: github-check | |
filter_mode: nofilter | |
prettier_flags: '**/*.{js,sol,ts,json,jsx,tsx}' | |
level: info | |
solhint: | |
name: Solhint | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Setup reviewdog | |
uses: reviewdog/action-setup@v1 | |
with: | |
reviewdog_version: latest | |
- name: Run solhint | |
env: | |
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
npx solhint -f sarif 'contracts/**/*.sol' | reviewdog -f=sarif -reporter=github-check -level=info -fail-level=none -filter-mode=nofilter -name=solhint | |
slither: | |
name: Slither | |
runs-on: ubuntu-latest | |
needs: [build] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Run Slither | |
uses: crytic/[email protected] | |
id: slither | |
with: | |
node-version: 20 | |
sarif: 'results.sarif' | |
fail-on: none | |
slither-args: --filter-paths node_modules/ | |
- name: Upload SARIF file | |
uses: github/codeql-action/upload-sarif@v3 | |
with: | |
sarif_file: ${{ steps.slither.outputs.sarif }} |