|
| 1 | +name: CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + release: |
| 9 | + types: [ published ] |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + # ============================================ |
| 14 | + # LINT AND TEST |
| 15 | + # ============================================ |
| 16 | + lint-and-test: |
| 17 | + name: Lint & Test (Node ${{ matrix.node }}) |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + node: ['18', '20', '22'] |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Setup Node.js ${{ matrix.node }} |
| 29 | + uses: actions/setup-node@v4 |
| 30 | + with: |
| 31 | + node-version: ${{ matrix.node }} |
| 32 | + cache: 'npm' |
| 33 | + |
| 34 | + - name: Install dependencies |
| 35 | + run: npm ci |
| 36 | + |
| 37 | + - name: Run ESLint |
| 38 | + run: npm run lint || true |
| 39 | + |
| 40 | + - name: Run tests |
| 41 | + run: npm test |
| 42 | + |
| 43 | + - name: Upload coverage |
| 44 | + uses: codecov/codecov-action@v3 |
| 45 | + with: |
| 46 | + file: ./coverage/lcov.info |
| 47 | + fail_ci_if_error: false |
| 48 | + |
| 49 | + # ============================================ |
| 50 | + # TEST ON WINDOWS |
| 51 | + # ============================================ |
| 52 | + test-windows: |
| 53 | + name: Test on Windows |
| 54 | + runs-on: windows-latest |
| 55 | + |
| 56 | + steps: |
| 57 | + - name: Checkout |
| 58 | + uses: actions/checkout@v4 |
| 59 | + |
| 60 | + - name: Setup Node.js |
| 61 | + uses: actions/setup-node@v4 |
| 62 | + with: |
| 63 | + node-version: '20' |
| 64 | + cache: 'npm' |
| 65 | + |
| 66 | + - name: Install dependencies |
| 67 | + run: npm ci |
| 68 | + |
| 69 | + - name: Run tests |
| 70 | + run: npm test |
| 71 | + |
| 72 | + - name: Test CLI help |
| 73 | + run: node bin/cloudsync.js --help |
| 74 | + |
| 75 | + # ============================================ |
| 76 | + # TEST ON MACOS |
| 77 | + # ============================================ |
| 78 | + test-macos: |
| 79 | + name: Test on macOS |
| 80 | + runs-on: macos-latest |
| 81 | + |
| 82 | + steps: |
| 83 | + - name: Checkout |
| 84 | + uses: actions/checkout@v4 |
| 85 | + |
| 86 | + - name: Setup Node.js |
| 87 | + uses: actions/setup-node@v4 |
| 88 | + with: |
| 89 | + node-version: '20' |
| 90 | + cache: 'npm' |
| 91 | + |
| 92 | + - name: Install dependencies |
| 93 | + run: npm ci |
| 94 | + |
| 95 | + - name: Run tests |
| 96 | + run: npm test |
| 97 | + |
| 98 | + # ============================================ |
| 99 | + # SECURITY AUDIT |
| 100 | + # ============================================ |
| 101 | + security-audit: |
| 102 | + name: Security Audit |
| 103 | + runs-on: ubuntu-latest |
| 104 | + |
| 105 | + steps: |
| 106 | + - name: Checkout |
| 107 | + uses: actions/checkout@v4 |
| 108 | + |
| 109 | + - name: Setup Node.js |
| 110 | + uses: actions/setup-node@v4 |
| 111 | + with: |
| 112 | + node-version: '20' |
| 113 | + |
| 114 | + - name: Install dependencies |
| 115 | + run: npm ci |
| 116 | + |
| 117 | + - name: Run npm audit |
| 118 | + run: npm audit --audit-level=high || true |
| 119 | + |
| 120 | + # ============================================ |
| 121 | + # BUILD PACKAGE |
| 122 | + # ============================================ |
| 123 | + build: |
| 124 | + name: Build Package |
| 125 | + runs-on: ubuntu-latest |
| 126 | + needs: [lint-and-test] |
| 127 | + |
| 128 | + steps: |
| 129 | + - name: Checkout |
| 130 | + uses: actions/checkout@v4 |
| 131 | + |
| 132 | + - name: Setup Node.js |
| 133 | + uses: actions/setup-node@v4 |
| 134 | + with: |
| 135 | + node-version: '20' |
| 136 | + cache: 'npm' |
| 137 | + |
| 138 | + - name: Install dependencies |
| 139 | + run: npm ci |
| 140 | + |
| 141 | + - name: Build package |
| 142 | + run: npm run build || true |
| 143 | + |
| 144 | + - name: Verify CLI |
| 145 | + run: | |
| 146 | + node bin/cloudsync.js --version |
| 147 | + node bin/cloudsync.js doctor |
| 148 | +
|
| 149 | + - name: Upload artifacts |
| 150 | + uses: actions/upload-artifact@v4 |
| 151 | + with: |
| 152 | + name: cloudsync-cli-artifact |
| 153 | + path: | |
| 154 | + bin/ |
| 155 | + src/ |
| 156 | + package.json |
| 157 | + package-lock.json |
| 158 | + LICENSE |
| 159 | + README.md |
| 160 | + retention-days: 7 |
| 161 | + |
| 162 | + # ============================================ |
| 163 | + # PUBLISH TO NPM (on release) |
| 164 | + # ============================================ |
| 165 | + publish-npm: |
| 166 | + name: Publish to npm |
| 167 | + runs-on: ubuntu-latest |
| 168 | + needs: [lint-and-test, test-windows, test-macos] |
| 169 | + if: github.event_name == 'release' |
| 170 | + |
| 171 | + steps: |
| 172 | + - name: Checkout |
| 173 | + uses: actions/checkout@v4 |
| 174 | + |
| 175 | + - name: Setup Node.js |
| 176 | + uses: actions/setup-node@v4 |
| 177 | + with: |
| 178 | + node-version: '20' |
| 179 | + cache: 'npm' |
| 180 | + |
| 181 | + - name: Install dependencies |
| 182 | + run: npm ci |
| 183 | + |
| 184 | + - name: Run tests |
| 185 | + run: npm test |
| 186 | + |
| 187 | + - name: Publish to npm |
| 188 | + run: npm publish |
| 189 | + env: |
| 190 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments