Skip to content

Commit

Permalink
ci: split Update Coverage Badges workflow into separate phases
Browse files Browse the repository at this point in the history
- Rename workflow to CI Workflow
- Add pull_request phase for validations (tests, linting, and coverage)
- Add post-merge phase for badge and summary generation
  • Loading branch information
abdullahbayram committed Dec 24, 2024
1 parent 78aa7e3 commit dede68c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
39 changes: 25 additions & 14 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
name: Update Coverage Badges and Summary
name: CI Workflow

# Trigger the workflow on pushes to the main branch
on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
update-assets:
validate-pr:
if: github.event_name == 'pull_request'
runs-on: ubuntu-22.04

steps:
# Step 1: Check out the repository
- name: Checkout repository
uses: actions/checkout@v3

# Step 2: Set up Node.js environment
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 22.2.0

# Step 3: Install dependencies
- name: Install dependencies
run: npm install

# Step 4: Run tests and generate coverage report
- name: Run test coverage
run: npm run test:coverage
- name: Validate PR
run: npm run validate:pr

post-merge-assets:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 22.2.0

- name: Install dependencies
run: npm install

# Step 5: Generate coverage assets (badges and summary)
- name: Generate coverage assets
- name: Generate Coverage Assets
run: npm run generate-coverage-assets

# Step 6: Commit and push updated assets
- name: Commit and push changes
- name: Commit and Push Coverage Assets
run: |
git config user.name "GitHub Actions Bot"
git config user.email "github-actions[bot]@users.noreply.github.com"
Expand Down
6 changes: 1 addition & 5 deletions .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@ export NVM_DIR="$HOME/.nvm"

# Run linting, tests, and coverage validation
echo "Running code validation and coverage checks..."
npm run validate:coverage

# Generate coverage badges, update report, and README
echo "Updating coverage badges, report, and README..."
npm run generate-coverage-assets
npm run validate:push
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,11 @@ Test coverage reports are automatically generated in the `coverage` directory fo

## Test Coverage

![statements](././badges/statements.svg)
![branches](././badges/branches.svg)
![functions](././badges/functions.svg)
![statements](././badges/statements.svg) ![branches](././badges/branches.svg) ![functions](././badges/functions.svg)
![lines](././badges/lines.svg)

![Coverage Report](././badges/coverage-summary.png)


## 🌟 Contributing

Contributions are welcome! Please follow these steps:
Expand Down
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,35 @@
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"help": "echo 'Validation scripts:\n - validate:commit: Validate staged files.\n - validate:push: Validate entire codebase before push.\n - validate:pr: Validate pull request with coverage.'",
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"clean": "npx rimraf node_modules && npm install",
"check:husky": "ls -l .husky/",
"lint": "eslint .",
"prettier": "prettier --check .",
"fix:prettier": "prettier --write .",
"fix:lint": "eslint . --fix",
"fix:all": "npm run fix:prettier && npm run fix:lint",
"lint:all": "npm run lint && npm run prettier",
"test": "jest",
"test:related": "jest --bail --findRelatedTests --passWithNoTests",
"coverage:open": "jest --coverage && open coverage/lcov-report/index.html || xdg-open coverage/lcov-report/index.html",
"test:coverage": "jest --coverage",
"generate-coverage-assets": "node ./scripts/generate-coverage-assets.js",
"validate:coverage": "npm run fix:all && npm run test:coverage",
"validate:commit": "npm run lint:all && npm run test:related",
"validate:push": "npm run lint:all && npm run test",
"validate:pr": "npm run lint:all && npm run test:coverage",
"prepare": "husky",
"watch": "jest --watch",
"watch-all": "jest --watchAll",
"clear-jest": "jest --clearCache",
"test detect": "jest --runInBand --detectOpenHandles",
"validate": "npm run fix:all && npm run test:related",
"prepare": "husky",
"logcat": "adb logcat | grep 'shopping-basket'",
"devices": "adb devices",
"list-ios": "xcrun simctl list devices",
"check:husky": "ls -l .husky/",
"clear-npm": "npm cache clean",
"clear-npm-force": "npm cache clean --force",
"cross-env": "npx cross-env NODE_ENV=development expo start -c"
Expand Down Expand Up @@ -84,7 +87,13 @@
},
"lint-staged": {
"*.js": [
"npm run validate"
"npm run validate:commit"
],
"*.json": [
"prettier --write"
],
"*.md": [
"prettier --write"
]
},
"private": true
Expand Down

0 comments on commit dede68c

Please sign in to comment.