Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CI workflow #8

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ ENV DEVCONTAINER=true

# Install additional tools for devcontainer template development
RUN apt install -y jq shellcheck
RUN npm install -g @devcontainers/cli
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
"postCreateCommand": "npm install",
"customizations": {
"vscode": {
"extensions": [
Expand Down
54 changes: 42 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,56 @@ on:
pull_request:

jobs:
test:
name: "Run test suite for templates"
setup:
name: "Setup environment and determine templates"
runs-on: ubuntu-latest
outputs:
template_dirs: ${{ steps.get-dirs.outputs.dirs }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: npm

- name: Install devcontainer CLI
run: npm install -g @devcontainers/cli
- name: Install Node.js dependencies
run: npm ci

- name: Get list of test directories
id: get-dirs
run: echo "dirs=$(ls -d test/*/ | jq -R -s -c 'split("\n")[:-1] | map(split("/")[1])')" >> $GITHUB_OUTPUT

lint:
name: "Run linting"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Run linting
run: test/lint.sh

# TODO: This'll do for now, but generalise these soon
- name: Run barebones-nodejs template test
run: test/barebones-nodejs/test.sh
- name: Run barebones-ruby template test
run: test/barebones-ruby/test.sh
test-templates:
name: "Run template tests"
needs: setup
runs-on: ubuntu-latest
strategy:
matrix:
template: ${{ fromJson(needs.setup.outputs.template_dirs) }}
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Install Node.js dependencies
run: npm ci

- name: Run test for ${{ matrix.template }}
run: test/${{ matrix.template }}/test.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "devcontainer-templates",
"version": "1.0.0",
"description": "A set of devcontainer templates following the nascent devcontainer template spec.",
"repository": {
"type": "git",
"url": "git+https://github.com/csutter/devcontainer-templates.git"
},
"author": "Christian Sutter",
"license": "MIT",
"bugs": {
"url": "https://github.com/csutter/devcontainer-templates/issues"
},
"homepage": "https://github.com/csutter/devcontainer-templates#readme",
"private": true,
"devDependencies": {
"@devcontainers/cli": "^0.66.0"
}
}
4 changes: 2 additions & 2 deletions test/harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ setup() {
sed -i -e "s/\${templateOption:imageVariant}/${IMAGE_TAG}/g" "$TEST_DIR"/.devcontainer/Dockerfile

# Start devcontainer
devcontainer up --workspace-folder "$TEST_DIR" --id-label "$ID_LABEL"
npx devcontainer up --workspace-folder "$TEST_DIR" --id-label "$ID_LABEL"
}

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

case "$result" in
*$expected_result*)
Expand Down
Loading