|
3 | 3 | # GitHub Reusable Workflow: Node.js Continuous Integration |
4 | 4 |
|
5 | 5 | <div align="center"> |
6 | | - <img src="https://opengraph.githubassets.com/0117dcf638f02d4da90af545ea1cae44cc8215860dbd273d47e78d65b56a6cfa/hoverkraft-tech/ci-github-nodejs" width="60px" align="center" alt="Node.js Continuous Integration" /> |
| 6 | + <img src="https://opengraph.githubassets.com/18a765fa9c9c81cb07807356ca5cd6b7f081abeef5ae263581ba407bebfb6ac0/hoverkraft-tech/ci-github-nodejs" width="60px" align="center" alt="Node.js Continuous Integration" /> |
7 | 7 | </div> |
8 | 8 |
|
9 | 9 | --- |
@@ -54,7 +54,7 @@ permissions: |
54 | 54 | id-token: write |
55 | 55 | jobs: |
56 | 56 | continuous-integration: |
57 | | - uses: hoverkraft-tech/ci-github-nodejs/.github/workflows/continuous-integration.yml@4d7c1ed87c18493fc4c2dbae4dbde46cf251c9a7 # 0.16.1 |
| 57 | + uses: hoverkraft-tech/ci-github-nodejs/.github/workflows/continuous-integration.yml@acb0215bd991fe9aa6e8309fe0612620f40186f8 # copilot/update-workflow-for-docker-image |
58 | 58 | secrets: |
59 | 59 | # Secrets to be used during the build step. |
60 | 60 | # Must be a multi-line env formatted string. |
@@ -112,13 +112,16 @@ jobs: |
112 | 112 | # Default: `true` |
113 | 113 | test: true |
114 | 114 |
|
115 | | - # Specifify code coverage reporter. Supported values: `codecov`. |
| 115 | + # Specify code coverage reporter. Supported values: `codecov`. |
116 | 116 | # Default: `codecov` |
117 | 117 | coverage: codecov |
118 | 118 |
|
119 | 119 | # Working directory where the dependencies are installed. |
120 | 120 | # Default: `.` |
121 | 121 | working-directory: . |
| 122 | + |
| 123 | + # Docker container image to run CI steps in. When specified, steps will execute inside this container instead of checking out code. The container should have the project code and dependencies pre-installed. |
| 124 | + container: "" |
122 | 125 | ```` |
123 | 126 |
|
124 | 127 | <!-- usage:end --> |
@@ -146,8 +149,9 @@ jobs: |
146 | 149 | | **`code-ql`** | Code QL analysis language. See <https://github.com/github/codeql-action>. | **false** | **string** | `typescript` | |
147 | 150 | | **`dependency-review`** | Enable dependency review scan. See <https://github.com/actions/dependency-review-action>. | **false** | **boolean** | `true` | |
148 | 151 | | **`test`** | Optional flag to enable test. | **false** | **boolean** | `true` | |
149 | | -| **`coverage`** | Specifify code coverage reporter. Supported values: `codecov`. | **false** | **string** | `codecov` | |
| 152 | +| **`coverage`** | Specify code coverage reporter. Supported values: `codecov`. | **false** | **string** | `codecov` | |
150 | 153 | | **`working-directory`** | Working directory where the dependencies are installed. | **false** | **string** | `.` | |
| 154 | +| **`container`** | Docker container image to run CI steps in. When specified, steps will execute inside this container instead of checking out code. The container should have the project code and dependencies pre-installed. | **false** | **string** | - | |
151 | 155 |
|
152 | 156 | <!-- inputs:end --> |
153 | 157 |
|
|
184 | 188 |
|
185 | 189 | jobs: |
186 | 190 | continuous-integration: |
187 | | - uses: hoverkraft-tech/ci-github-nodejs/.github/workflows/continuous-integration.yml@4d7c1ed87c18493fc4c2dbae4dbde46cf251c9a7 # 0.16.1 |
| 191 | + uses: hoverkraft-tech/ci-github-nodejs/.github/workflows/continuous-integration.yml@acb0215bd991fe9aa6e8309fe0612620f40186f8 # copilot/update-workflow-for-docker-image |
188 | 192 | permissions: |
189 | 193 | id-token: write |
190 | 194 | security-events: write |
@@ -219,6 +223,54 @@ jobs: |
219 | 223 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
220 | 224 | ``` |
221 | 225 |
|
| 226 | +### Continuous Integration in a Docker container |
| 227 | + |
| 228 | +This example runs CI checks inside a pre-built Docker container that contains the project code and dependencies. This ensures the same environment that will be deployed to production is tested. |
| 229 | + |
| 230 | +```yaml |
| 231 | +name: Continuous Integration - Container Mode |
| 232 | +
|
| 233 | +on: |
| 234 | + push: |
| 235 | + branches: [main] |
| 236 | +
|
| 237 | +jobs: |
| 238 | + # Build the Docker image with project code and dependencies |
| 239 | + build-image: |
| 240 | + runs-on: ubuntu-latest |
| 241 | + steps: |
| 242 | + - name: Checkout |
| 243 | + |
| 244 | +
|
| 245 | + - name: Build Docker image |
| 246 | + run: | |
| 247 | + docker build -t my-app:${{ github.sha }} . |
| 248 | +
|
| 249 | + - name: Push to registry |
| 250 | + run: | |
| 251 | + docker tag my-app:${{ github.sha }} ghcr.io/${{ github.repository }}:${{ github.sha }} |
| 252 | + docker push ghcr.io/${{ github.repository }}:${{ github.sha }} |
| 253 | +
|
| 254 | + # Run CI checks inside the Docker container |
| 255 | + continuous-integration: |
| 256 | + needs: build-image |
| 257 | + uses: hoverkraft-tech/ci-github-nodejs/.github/workflows/continuous-integration.yml@acb0215bd991fe9aa6e8309fe0612620f40186f8 # copilot/update-workflow-for-docker-image |
| 258 | + permissions: |
| 259 | + id-token: write |
| 260 | + security-events: write |
| 261 | + contents: read |
| 262 | + with: |
| 263 | + container: ghcr.io/${{ github.repository }}:${{ github.sha }} |
| 264 | + # When using container mode, code-ql and dependency-review are typically disabled |
| 265 | + # as they require repository checkout |
| 266 | + code-ql: "" |
| 267 | + dependency-review: false |
| 268 | + # Specify which build/test commands to run (they should exist in package.json) |
| 269 | + build: "" # Skip build as it was done in the Docker image |
| 270 | + lint: true |
| 271 | + test: true |
| 272 | +``` |
| 273 | + |
222 | 274 | <!-- examples:end --> |
223 | 275 |
|
224 | 276 | <!-- contributing:start --> |
|
0 commit comments