Push latest ci-cd yaml file #2
This file contains hidden or 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/CD Pipeline | ||
| # Trigger CI on pushes to main and pull requests | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| jobs: | ||
| ci: | ||
| name: Continuous Integration | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: '24' | ||
| cache: 'npm' | ||
| - name: Install dependencies | ||
| run: npm ci | ||
| - name: Run linter | ||
| run: npm run lint | ||
| - name: Check code formatting | ||
| run: npm run format:check | ||
| - name: Run tests | ||
| run: npm test | ||
| - name: Build project | ||
| run: npm run build | ||
| - name: Generate log file | ||
| run: | | ||
| mkdir -p logs | ||
| echo "CI Pipeline ran at $(date)" > logs/ci-pipeline.log | ||
| echo "Tests passed" > logs/ci-pipeline.log | ||
| - name: Generate demp HTML page | ||
| run: | | ||
| mkdir -p public | ||
| cp demo/index.html public/ | ||
| cp dist/sum.js public/ | ||
| - name: Upload build logs artifact | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| name: build-logs | ||
| path: logs/ | ||
| retention-days: 30 | ||
| - name: Upload demo site artifact | ||
| uses: actions/upload-artifact@v6 | ||
| with: | ||
| name: demo-site | ||
| path: public/ | ||
| retention-days: 30 | ||
| deploy: | ||
| name: Deploy to Github pages | ||
| needs: ci | ||
| runs-on: ubuntu-latest | ||
| # Only deploy on push to main branch | ||
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
| environment: | ||
| name: github-pages | ||
| url: ${{ steps.deployment.outputs.page_url }} | ||
| steps: | ||
| - name: Download artifact | ||
| uses: actions/download-artifact@v7 | ||
| with: | ||
| name: demo-site | ||
| path: ./public | ||
| - name: Upload to Github Pages | ||
| uses: actions/upload-pages-artifact@v3 | ||
| with: | ||
| path: ./public | ||
| - name: Deploy to Github Pages | ||
| id: deployment | ||
| uses: actions/deploy-pages@v4 | ||