Skip to content

Commit db2b10a

Browse files
chore: added gh workflow
1 parent d0236f9 commit db2b10a

3 files changed

Lines changed: 175 additions & 0 deletions

File tree

.github/workflows/build-badge.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Build Badge
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
build-badge:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
submodules: 'recursive'
16+
persist-credentials: false
17+
18+
- name: Authenticate using GitHub Token
19+
env:
20+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
21+
run: |
22+
git config user.name "github-actions[bot]"
23+
git config user.email "github-actions[bot]@users.noreply.github.com"
24+
git remote set-url origin https://${GITHUB_ACTOR}:${GH_TOKEN}@github.com/${{ github.repository }}.git
25+
26+
- name: Set up Node.js
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: '20'
30+
31+
- name: Install dependencies
32+
run: npm ci
33+
34+
- name: Compile contracts
35+
id: build
36+
run: |
37+
if npx hardhat compile; then
38+
echo "status=passing" >> "$GITHUB_OUTPUT"
39+
echo "color=green" >> "$GITHUB_OUTPUT"
40+
else
41+
echo "status=failed" >> "$GITHUB_OUTPUT"
42+
echo "color=red" >> "$GITHUB_OUTPUT"
43+
fi
44+
45+
- name: Create badges directory (if not exists)
46+
run: mkdir -p badges
47+
48+
- name: Generate Build Badge SVG
49+
uses: emibcn/badge-action@v2.0.3
50+
with:
51+
label: 'build'
52+
status: '${{ steps.build.outputs.status }}'
53+
color: '${{ steps.build.outputs.color }}'
54+
path: 'badges/build.svg'
55+
56+
- name: Commit and Push Build Badge
57+
run: |
58+
git checkout -B build-badge
59+
git add badges/build.svg
60+
git commit -m "chore: Update build badge [skip ci]" || echo "No changes to commit"
61+
git push -f origin build-badge
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: CI Status Badge
2+
3+
on:
4+
workflow_run:
5+
workflows: ['Build Badge', 'Coverage Badge']
6+
types:
7+
- completed
8+
9+
jobs:
10+
ci-status-badge:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
persist-credentials: false
18+
19+
- name: Authenticate using GitHub Token
20+
env:
21+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
22+
run: |
23+
git config user.name "github-actions[bot]"
24+
git config user.email "github-actions[bot]@users.noreply.github.com"
25+
git remote set-url origin https://${GITHUB_ACTOR}:${GH_TOKEN}@github.com/${{ github.repository }}.git
26+
27+
- name: Determine workflows status
28+
id: status
29+
run: |
30+
if [[ "${{ github.event.workflow_run.conclusion }}" == "success" ]]; then
31+
echo "status=passing" >> "$GITHUB_OUTPUT"
32+
echo "color=green" >> "$GITHUB_OUTPUT"
33+
else
34+
echo "status=failed" >> "$GITHUB_OUTPUT"
35+
echo "color=red" >> "$GITHUB_OUTPUT"
36+
fi
37+
38+
- name: Create badges directory (if not exists)
39+
run: mkdir -p badges
40+
41+
- name: Generate CI Badge
42+
uses: emibcn/badge-action@v2.0.3
43+
with:
44+
label: 'CI'
45+
status: '${{ steps.status.outputs.status }}'
46+
color: '${{ steps.status.outputs.color }}'
47+
path: 'badges/ci.svg'
48+
49+
- name: Commit and Push CI Badge
50+
run: |
51+
git checkout -B ci-badge
52+
git add badges/ci.svg
53+
git commit -m "chore: Update ci badge [skip ci]" || echo "No changes to commit"
54+
git push -f origin ci-badge
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Coverage Badge
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
coverage-badge:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
submodules: 'recursive'
16+
persist-credentials: false
17+
18+
- name: Authenticate using GitHub Token
19+
env:
20+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
21+
run: |
22+
git config user.name "github-actions[bot]"
23+
git config user.email "github-actions[bot]@users.noreply.github.com"
24+
git remote set-url origin https://${GITHUB_ACTOR}:${GH_TOKEN}@github.com/${{ github.repository }}.git
25+
26+
- name: Set up Node.js
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: '20'
30+
31+
- name: Install dependencies
32+
run: |
33+
npm ci
34+
35+
- name: Generate coverage report
36+
run: npx hardhat coverage
37+
38+
- name: Extract coverage via JS script (coverage.js)
39+
id: cov
40+
run: |
41+
COVERAGE=$(node ./coverage.js)
42+
echo "coverage=$COVERAGE" >> "$GITHUB_OUTPUT"
43+
44+
- name: Create badges directory (if not exists)
45+
run: mkdir -p badges
46+
47+
- name: Generate Badge SVG
48+
uses: emibcn/badge-action@v2.0.3
49+
with:
50+
label: 'coverage'
51+
status: '${{ steps.cov.outputs.coverage }}'
52+
color: 'blue'
53+
path: 'badges/coverage.svg'
54+
55+
- name: Commit and Push Coverage Badge
56+
run: |
57+
git checkout -B coverage-badge
58+
git add badges/coverage.svg
59+
git commit -m "chore: Update coverage badge [skip ci]" || echo "No changes to commit"
60+
git push -f origin coverage-badge

0 commit comments

Comments
 (0)