Skip to content

Commit 5012de1

Browse files
committed
Improve CI workflow
- Split up testing and linting into separate jobs - Use a matrix job instead of hardcoding steps for all templates in a single job - Set up `package.json` and stop installing `@devcontainer/cli` globally through Dockerfile - Update CI Node to v20
1 parent ea5e231 commit 5012de1

File tree

7 files changed

+92
-15
lines changed

7 files changed

+92
-15
lines changed

.devcontainer/Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ ENV DEVCONTAINER=true
1313

1414
# Install additional tools for devcontainer template development
1515
RUN apt install -y jq shellcheck
16-
RUN npm install -g @devcontainers/cli

.devcontainer/devcontainer.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"features": {
77
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
88
},
9+
"postCreateCommand": "npm install",
910
"customizations": {
1011
"vscode": {
1112
"extensions": [

.github/workflows/tests.yml

+41-12
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,55 @@ on:
77
pull_request:
88

99
jobs:
10-
test:
11-
name: "Run test suite for templates"
10+
setup:
11+
name: "Setup environment and determine templates"
1212
runs-on: ubuntu-latest
13+
outputs:
14+
template_dirs: ${{ steps.get-dirs.outputs.dirs }}
1315
steps:
1416
- name: Checkout
1517
uses: actions/checkout@v3
1618

17-
- name: Setup node
18-
uses: actions/setup-node@v3
19+
- uses: actions/setup-node@v4
1920
with:
20-
node-version: 18
21+
node-version: 20
22+
cache: npm
2123

22-
- name: Install devcontainer CLI
23-
run: npm install -g @devcontainers/cli
24+
- name: Install Node.js dependencies
25+
run: npm ci
26+
27+
- name: Get list of test directories
28+
id: get-dirs
29+
run: echo "dirs=$(ls -d test/*/ | jq -R -s -c 'split("\n")[:-1] | map(split("/")[1])')" >> $GITHUB_OUTPUT
30+
31+
lint:
32+
name: "Run linting"
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v3
2437

2538
- name: Run linting
2639
run: test/lint.sh
2740

28-
# TODO: This'll do for now, but generalise these soon
29-
- name: Run barebones-nodejs template test
30-
run: test/barebones-nodejs/test.sh
31-
- name: Run barebones-ruby template test
32-
run: test/barebones-ruby/test.sh
41+
test-templates:
42+
name: "Run template tests"
43+
needs: setup
44+
runs-on: ubuntu-latest
45+
strategy:
46+
matrix:
47+
template: ${{ fromJson(needs.setup.outputs.template_dirs) }}
48+
fail-fast: false
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v3
52+
53+
- uses: actions/setup-node@v4
54+
with:
55+
node-version: 20
56+
cache: npm
57+
58+
- run: npx devcontainer --version
59+
60+
- name: Run test for ${{ matrix.template }}
61+
run: test/${{ matrix.template }}/test.sh

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

package-lock.json

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "devcontainer-templates",
3+
"version": "1.0.0",
4+
"description": "A set of devcontainer templates following the nascent devcontainer template spec.",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/csutter/devcontainer-templates.git"
8+
},
9+
"author": "Christian Sutter",
10+
"license": "MIT",
11+
"bugs": {
12+
"url": "https://github.com/csutter/devcontainer-templates/issues"
13+
},
14+
"homepage": "https://github.com/csutter/devcontainer-templates#readme",
15+
"private": true,
16+
"devDependencies": {
17+
"@devcontainers/cli": "^0.66.0"
18+
}
19+
}

test/harness.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ setup() {
3737
sed -i -e "s/\${templateOption:imageVariant}/${IMAGE_TAG}/g" "$TEST_DIR"/.devcontainer/Dockerfile
3838

3939
# Start devcontainer
40-
devcontainer up --workspace-folder "$TEST_DIR" --id-label "$ID_LABEL"
40+
npx devcontainer up --workspace-folder "$TEST_DIR" --id-label "$ID_LABEL"
4141
}
4242

4343
# Clean up after ourselves on success or failure
@@ -70,7 +70,7 @@ run_test() {
7070
#
7171
# We _want_ $cmd to be split here as it could include arguments:
7272
# shellcheck disable=SC2086
73-
result=$(devcontainer exec --workspace-folder "$TEST_DIR" --id-label "$ID_LABEL" $cmd || true)
73+
result=$(npx devcontainer exec --workspace-folder "$TEST_DIR" --id-label "$ID_LABEL" $cmd || true)
7474

7575
case "$result" in
7676
*$expected_result*)

0 commit comments

Comments
 (0)