Skip to content

Commit 192d4ac

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 192d4ac

File tree

7 files changed

+94
-15
lines changed

7 files changed

+94
-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

+43-12
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,57 @@ 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+
- run: ~/node_modules/.bin/devcontainer --version
28+
29+
- name: Get list of test directories
30+
id: get-dirs
31+
run: echo "dirs=$(ls -d test/*/ | jq -R -s -c 'split("\n")[:-1] | map(split("/")[1])')" >> $GITHUB_OUTPUT
32+
33+
lint:
34+
name: "Run linting"
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v3
2439

2540
- name: Run linting
2641
run: test/lint.sh
2742

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
43+
test-templates:
44+
name: "Run template tests"
45+
needs: setup
46+
runs-on: ubuntu-latest
47+
strategy:
48+
matrix:
49+
template: ${{ fromJson(needs.setup.outputs.template_dirs) }}
50+
fail-fast: false
51+
steps:
52+
- name: Checkout
53+
uses: actions/checkout@v3
54+
55+
- uses: actions/setup-node@v4
56+
with:
57+
node-version: 20
58+
cache: npm
59+
60+
- run: ~/node_modules/.bin/devcontainer --version
61+
62+
- name: Run test for ${{ matrix.template }}
63+
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+
~/node_modules/.bin/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=$(~/node_modules/.bin/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)