Типичный стек:
name: Angular CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run lint
run: npm run lint
- name: Run tests
run: npm run test -- --watch=false --browsers=ChromeHeadless
- name: Build production
run: npm run build -- --configuration=production
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
- name: Deploy to Firebase
run: |
npm install -g firebase-tools
firebase deploy --token=${{ secrets.FIREBASE_TOKEN }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Deploy to S3
run: |
aws s3 sync dist/ s3://your-bucket-name --delete
aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths "/*"
// angular.json
"configurations": {
"dev": { "fileReplacements": [...] },
"prod": { "optimization": true }
}
- name: Build for environment
run: npm run build -- --configuration=${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
# Dockerfile
FROM nginx:alpine
COPY dist/ /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
push: true
tags: your-repo/angular-app:latest
- name: Canary deploy
if: github.ref != 'refs/heads/main'
run: npm run deploy-canary
- name: Audit dependencies
run: npm audit
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Run Lighthouse
run: |
npm install -g lighthouse
lighthouse https://your-app.com --output=html --output-path=./lighthouse.html
- name: Cache node modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
- name: Affected build
run: nx affected:build --base=origin/main
- name: Slack notification
uses: rtCamp/action-slack-notify@v2
if: failure()
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
- name: Upload test results
uses: actions/upload-artifact@v3
with:
name: test-results
path: coverage/