|
| 1 | +name: CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, master ] |
| 8 | + release: |
| 9 | + types: [created] |
| 10 | + |
| 11 | +jobs: |
| 12 | + test: |
| 13 | + runs-on: ${{ matrix.os }} |
| 14 | + |
| 15 | + strategy: |
| 16 | + matrix: |
| 17 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 18 | + node-version: [18.x, 20.x, 22.x] |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Setup Node.js |
| 25 | + uses: actions/setup-node@v4 |
| 26 | + with: |
| 27 | + node-version: ${{ matrix.node-version }} |
| 28 | + cache: 'npm' |
| 29 | + |
| 30 | + - name: Install dependencies |
| 31 | + run: npm ci |
| 32 | + |
| 33 | + - name: Run linter |
| 34 | + run: npm run lint |
| 35 | + |
| 36 | + - name: Check formatting |
| 37 | + run: npm run format:check |
| 38 | + |
| 39 | + - name: Run unit tests |
| 40 | + run: npm run test:unit |
| 41 | + |
| 42 | + - name: Run integration tests |
| 43 | + run: npm run test:integration |
| 44 | + |
| 45 | + - name: Generate coverage report |
| 46 | + if: matrix.os == 'ubuntu-latest' && matrix.node-version == '20.x' |
| 47 | + run: npm run test:coverage |
| 48 | + |
| 49 | + - name: Upload coverage to Codecov |
| 50 | + if: matrix.os == 'ubuntu-latest' && matrix.node-version == '20.x' |
| 51 | + uses: codecov/codecov-action@v4 |
| 52 | + with: |
| 53 | + file: ./coverage/coverage-final.json |
| 54 | + flags: unittests |
| 55 | + name: codecov-umbrella |
| 56 | + |
| 57 | + - name: Build project |
| 58 | + run: npm run build |
| 59 | + |
| 60 | + - name: Test CLI installation |
| 61 | + run: | |
| 62 | + npm link |
| 63 | + devxp --version |
| 64 | + devxp --help |
| 65 | +
|
| 66 | + publish-npm: |
| 67 | + needs: test |
| 68 | + runs-on: ubuntu-latest |
| 69 | + if: github.event_name == 'release' |
| 70 | + |
| 71 | + steps: |
| 72 | + - name: Checkout code |
| 73 | + uses: actions/checkout@v4 |
| 74 | + |
| 75 | + - name: Setup Node.js |
| 76 | + uses: actions/setup-node@v4 |
| 77 | + with: |
| 78 | + node-version: '20.x' |
| 79 | + registry-url: 'https://registry.npmjs.org' |
| 80 | + |
| 81 | + - name: Install dependencies |
| 82 | + run: npm ci |
| 83 | + |
| 84 | + - name: Build project |
| 85 | + run: npm run build |
| 86 | + |
| 87 | + - name: Publish to npm |
| 88 | + run: npm publish |
| 89 | + env: |
| 90 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 91 | + |
| 92 | + docker: |
| 93 | + needs: test |
| 94 | + runs-on: ubuntu-latest |
| 95 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 96 | + |
| 97 | + steps: |
| 98 | + - name: Checkout code |
| 99 | + uses: actions/checkout@v4 |
| 100 | + |
| 101 | + - name: Set up Docker Buildx |
| 102 | + uses: docker/setup-buildx-action@v3 |
| 103 | + |
| 104 | + - name: Login to DockerHub |
| 105 | + uses: docker/login-action@v3 |
| 106 | + with: |
| 107 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 108 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 109 | + |
| 110 | + - name: Build and push Docker image |
| 111 | + uses: docker/build-push-action@v5 |
| 112 | + with: |
| 113 | + context: . |
| 114 | + push: true |
| 115 | + tags: | |
| 116 | + ${{ secrets.DOCKER_USERNAME }}/devxp-cli:latest |
| 117 | + ${{ secrets.DOCKER_USERNAME }}/devxp-cli:${{ github.sha }} |
0 commit comments