Skip to content

Commit 9a116f4

Browse files
Copilotneilime
andcommitted
feat(continuous-integration): support container options with env and docker options
Co-authored-by: neilime <[email protected]>
1 parent 705ea03 commit 9a116f4

File tree

4 files changed

+274
-31
lines changed

4 files changed

+274
-31
lines changed

.github/linters/actionlint.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# FIXME: Temporary ignores to bypass actionlint limitations. See https://github.com/rhysd/actionlint/issues/590.
2+
paths:
3+
.github/workflows/continuous-integration.yml:
4+
ignore:
5+
- 'both "username" and "password" must be specified in "credentials" section'
6+
- '"credentials" section is scalar node but mapping node is expected'
7+
- '"container" section is alias node but mapping node is expected'

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,50 @@ jobs:
109109

110110
- name: Check the build artifacts
111111
run: test -f ${{ runner.temp }}/usr/src/app/dist/test.txt
112+
113+
act-with-container-advanced:
114+
name: Act - Run the continuous integration workflow (with container and advanced options)
115+
uses: ./.github/workflows/continuous-integration.yml
116+
needs: arrange-with-container
117+
permissions:
118+
contents: read
119+
pull-requests: write
120+
security-events: write
121+
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
122+
id-token: write
123+
with:
124+
container: |
125+
{
126+
"image": "${{ fromJSON(needs.arrange-with-container.outputs.built-images).ci-npm.images[0] }}",
127+
"env": {
128+
"NODE_ENV": "test",
129+
"CI": "true"
130+
},
131+
"options": "--cpus 1",
132+
"credentials": {
133+
"username": "${{ github.actor }}"
134+
}
135+
}
136+
working-directory: /usr/src/app/
137+
build: |
138+
{
139+
"artifact": "dist"
140+
}
141+
test: |
142+
{"coverage": "codecov"}
143+
secrets:
144+
container-password: ${{ secrets.GITHUB_TOKEN }}
145+
146+
assert-with-container-advanced:
147+
name: Assert - Ensure build artifact has been uploaded (with container advanced)
148+
runs-on: ubuntu-latest
149+
needs: act-with-container-advanced
150+
steps:
151+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
152+
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
153+
with:
154+
artifact-ids: ${{ needs.act-with-container-advanced.outputs.build-artifact-id }}
155+
path: ${{ runner.temp }}
156+
157+
- name: Check the build artifacts
158+
run: test -f ${{ runner.temp }}/usr/src/app/dist/test.txt

.github/workflows/continuous-integration.md

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,29 @@ jobs:
126126
# Default: `.`
127127
working-directory: .
128128

129-
# 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.
129+
# Container configuration to run CI steps in.
130+
# Accepts either a string (container image name) or a JSON object with container options.
131+
#
132+
# String format (simple):
133+
# container: "node:18"
134+
#
135+
# JSON object format (advanced):
136+
# container: |
137+
# {
138+
# "image": "node:18",
139+
# "env": {
140+
# "NODE_ENV": "production"
141+
# },
142+
# "ports": [8080],
143+
# "volumes": ["/tmp:/tmp"],
144+
# "options": "--cpus 2"
145+
# }
146+
#
147+
# All properties from GitHub's container specification are supported except credentials (use secrets instead).
148+
# See https://docs.github.com/en/actions/how-tos/write-workflows/choose-where-workflows-run/run-jobs-in-a-container
149+
#
150+
# When specified, steps will execute inside this container instead of checking out code.
151+
# The container should have the project code and dependencies pre-installed.
130152
container: ""
131153
````
132154

@@ -162,10 +184,45 @@ jobs:
162184
| | Set to `null` or empty to disable. | | | |
163185
| | Accepts a JSON object for test options. See [test action](../actions/test/README.md). | | | |
164186
| **`working-directory`** | Working directory where the dependencies are installed. | **false** | **string** | `.` |
165-
| **`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** | - |
187+
| **`container`** | Container configuration to run CI steps in. Accepts string or JSON object. See Container Configuration below | **false** | **string** | - |
166188

167189
<!-- inputs:end -->
168190

191+
### Container Configuration
192+
193+
The `container` input accepts either:
194+
195+
**Simple string format** (image name only):
196+
197+
```yaml
198+
container: "node:18"
199+
```
200+
201+
**Advanced JSON format** (with container options):
202+
203+
```yaml
204+
container: |
205+
{
206+
"image": "node:18",
207+
"env": {
208+
"NODE_ENV": "production"
209+
},
210+
"options": "--cpus 2"
211+
}
212+
```
213+
214+
**Supported properties:**
215+
216+
- `image` (string, required) - Container image name
217+
- `env` (object) - Environment variables
218+
- `options` (string) - Additional Docker options
219+
220+
**Note:** `ports`, `volumes`, and `credentials` are not currently supported due to GitHub Actions workflow syntax limitations.
221+
222+
See [GitHub's container specification](https://docs.github.com/en/actions/how-tos/write-workflows/choose-where-workflows-run/run-jobs-in-a-container) for more details.
223+
224+
When specified, steps will execute inside this container instead of checking out code. The container should have the project code and dependencies pre-installed.
225+
169226
<!-- secrets:start -->
170227

171228
## Secrets
@@ -289,6 +346,43 @@ jobs:
289346
test: true
290347
```
291348

349+
### Continuous Integration with Advanced Container Options
350+
351+
This example shows how to use advanced container options like environment variables, credentials, and additional Docker options.
352+
353+
```yaml
354+
name: Continuous Integration - Advanced Container Options
355+
356+
on:
357+
push:
358+
branches: [main]
359+
360+
jobs:
361+
continuous-integration:
362+
uses: hoverkraft-tech/ci-github-nodejs/.github/workflows/continuous-integration.yml@32a69b7b8fd5f7ab7bf656e7e88aa90ad235cf8d # 0.18.0
363+
permissions:
364+
id-token: write
365+
security-events: write
366+
contents: read
367+
with:
368+
container: |
369+
{
370+
"image": "node:18-alpine",
371+
"env": {
372+
"NODE_ENV": "production",
373+
"CI": "true"
374+
},
375+
"options": "--cpus 2 --memory 4g"
376+
}
377+
# When using container mode, code-ql and dependency-review are typically disabled
378+
# as they require repository checkout
379+
code-ql: ""
380+
dependency-review: false
381+
build: "build"
382+
lint: true
383+
test: true
384+
```
385+
292386
<!-- examples:end -->
293387

294388
<!-- contributing:start -->

0 commit comments

Comments
 (0)