Skip to content

Commit a42cfc5

Browse files
Copilotneilime
andcommitted
feat(continuous-integration): add container input for OCI-based CI execution
Co-authored-by: neilime <[email protected]> Signed-off-by: Emilien Escalle <[email protected]>
1 parent 5f50f1a commit a42cfc5

File tree

10 files changed

+308
-4186
lines changed

10 files changed

+308
-4186
lines changed

.github/workflows/__main-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ on:
1313
permissions:
1414
actions: write
1515
contents: write
16+
issues: read
17+
packages: write
1618
pages: write
1719
pull-requests: write
1820
security-events: write

.github/workflows/__pull-request-ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
permissions:
99
actions: read
1010
contents: read
11+
issues: read
12+
packages: write
13+
pull-requests: read
1114
security-events: write
1215
statuses: write
1316
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659

.github/workflows/__shared-ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
permissions:
77
actions: read
88
contents: read
9+
issues: read
10+
packages: write
11+
pull-requests: read
912
security-events: write
1013
statuses: write
1114
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659

.github/workflows/__test-workflow-continuous-integration.yml

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ permissions:
1010
id-token: write
1111

1212
jobs:
13-
act:
14-
name: Act - Run the continuous integration workflow
13+
act-without-container:
14+
name: Act - Run the continuous integration workflow (without container)
1515
uses: ./.github/workflows/continuous-integration.yml
1616
with:
17+
working-directory: tests/npm
1718
build: |
1819
{
1920
"artifact": "dist"
2021
}
2122
22-
assert:
23-
name: Assert - Ensure build artifact has been uploaded
23+
assert-without-container:
24+
name: Assert - Ensure build artifact has been uploaded (without container)
2425
runs-on: ubuntu-latest
25-
needs: act
26+
needs: act-without-container
2627
steps:
2728
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2829
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
@@ -31,4 +32,52 @@ jobs:
3132
path: "/"
3233

3334
- name: Check the build artifacts
34-
run: test -f dist/test.txt
35+
run: test -f tests/npm/dist/test.txt
36+
37+
arrange-with-container:
38+
permissions:
39+
id-token: write
40+
contents: read
41+
packages: write
42+
issues: read
43+
pull-requests: read
44+
uses: hoverkraft-tech/ci-github-container/.github/workflows/docker-build-images.yml@f9e149b6cdfa8443994994f10085691a57b8cf0e # 0.27.1
45+
with:
46+
sign: false
47+
images: |
48+
[{
49+
"name": "ci-npm",
50+
"context": ".",
51+
"dockerfile": "./tests/npm/Dockerfile",
52+
"build-args": { "APP_PATH": "./tests/npm/" },
53+
"target": "ci",
54+
"platforms": ["linux/amd64"]
55+
}]
56+
secrets:
57+
oci-registry-password: ${{ secrets.GITHUB_TOKEN }}
58+
59+
act-with-container:
60+
name: Act - Run the continuous integration workflow (with container)
61+
uses: ./.github/workflows/continuous-integration.yml
62+
needs: arrange-with-container
63+
with:
64+
container: ${{ fromJSON(needs.arrange-with-container.outputs.built-images).ci-npm.images[0] }}
65+
working-directory: /usr/src/app/
66+
build: |
67+
{
68+
"artifact": { "name": "build-in-container", "paths": "dist" }
69+
}
70+
71+
assert-with-container:
72+
name: Assert - Ensure build artifact has been uploaded (with container)
73+
runs-on: ubuntu-latest
74+
needs: act-with-container
75+
steps:
76+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
77+
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
78+
with:
79+
name: build-in-container
80+
path: ${{ runner.temp }}
81+
82+
- name: Check the build artifacts
83+
run: test -f ${{ runner.temp }}/usr/src/app/dist/test.txt

.github/workflows/continuous-integration.md

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# GitHub Reusable Workflow: Node.js Continuous Integration
44

55
<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" />
77
</div>
88

99
---
@@ -54,7 +54,7 @@ permissions:
5454
id-token: write
5555
jobs:
5656
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
5858
secrets:
5959
# Secrets to be used during the build step.
6060
# Must be a multi-line env formatted string.
@@ -112,13 +112,16 @@ jobs:
112112
# Default: `true`
113113
test: true
114114

115-
# Specifify code coverage reporter. Supported values: `codecov`.
115+
# Specify code coverage reporter. Supported values: `codecov`.
116116
# Default: `codecov`
117117
coverage: codecov
118118

119119
# Working directory where the dependencies are installed.
120120
# Default: `.`
121121
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: ""
122125
````
123126

124127
<!-- usage:end -->
@@ -146,8 +149,9 @@ jobs:
146149
| **`code-ql`** | Code QL analysis language. See <https://github.com/github/codeql-action>. | **false** | **string** | `typescript` |
147150
| **`dependency-review`** | Enable dependency review scan. See <https://github.com/actions/dependency-review-action>. | **false** | **boolean** | `true` |
148151
| **`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` |
150153
| **`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** | - |
151155

152156
<!-- inputs:end -->
153157

@@ -184,7 +188,7 @@ on:
184188
185189
jobs:
186190
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
188192
permissions:
189193
id-token: write
190194
security-events: write
@@ -219,6 +223,54 @@ jobs:
219223
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
220224
```
221225

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+
uses: actions/[email protected]
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+
222274
<!-- examples:end -->
223275

224276
<!-- contributing:start -->

0 commit comments

Comments
 (0)