Skip to content

Commit

Permalink
apply ci tests to node20 rock
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas Husseini committed Mar 28, 2024
1 parent 2087eff commit f203c8c
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 11 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push, pull_request]

env:
node18-image: ubuntu/chiselled-node:18-test
node20-image: ubuntu/nodejs:20-test
ubuntu-release: 24.04

jobs:
Expand Down Expand Up @@ -35,14 +36,23 @@ jobs:
--output type=oci,dest="chiselled-node.${{ matrix.arch }}.tar" \
node18
- name: Build the ${{ env.node20-image }} image on ${{ matrix.arch }}
id: build
uses: canonical/craft-actions/rockcraft-pack@main
with:
path: node20/
verbosity: debug

- name: Run tests
if: ${{ matrix.arch == 'amd64' }}
run: |
set -ex
sudo apt-get update
sudo apt-get install -y skopeo
skopeo copy oci-archive:"chiselled-node.${{ matrix.arch }}.tar" docker-daemon:${{ env.node18-image }}
skopeo copy oci-archive:node20/nodejs_20_amd64.rock docker-daemon:${{ env.node20-image }}
./tests/run-all-tests ${{ env.node18-image }}
./tests/run-all-tests ${{ env.node20-image }}
- uses: actions/upload-artifact@v3
with:
Expand Down
8 changes: 6 additions & 2 deletions tests/app_hello-world/runtest
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ set -ex
echo "Running test for Hello World app..."

test() {
docker run --rm -v "$PWD/src":/src:ro "$1" /src/main.js
if [ "$1" == "$NODE18" ]; then
docker run --rm -v "$PWD/src":/src:ro "$1" /src/main.js
else
docker run --rm -v "$PWD/src":/src:ro "$1" exec node /src/main.js
fi
}

test "$NODE18"
test "$NODE_X"
8 changes: 6 additions & 2 deletions tests/app_http-server/runtest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ echo "Running test for HTTP Server app..."

test() {
port=1234
container="$(docker run -d --rm -v "$PWD/src":/src:ro -p $port:8080 "$1" /src/main.js)"
if [ "$1" == "$NODE18" ]; then
container="$(docker run -d --rm -v "$PWD/src":/src:ro -p $port:8080 "$1" /src/main.js)"
else
container="$(docker run -d --rm -v "$PWD/src":/src:ro -p $port:8080 "$1" exec node /src/main.js)"
fi
sleep 1
output="$(curl http://localhost:$port/)"
[ "$output" == "Hello world!" ] || exit 1
Expand All @@ -16,4 +20,4 @@ cleanup() {
}
trap cleanup EXIT

test "$NODE18"
test "$NODE_X"
8 changes: 6 additions & 2 deletions tests/app_simple-modules/runtest
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ build() {
}

test() {
docker run --rm -v "$PWD/dist":/src:ro "$1" /src/index.js
if [ "$1" == "$NODE18" ]; then
docker run --rm -v "$PWD/dist":/src:ro "$1" /src/index.js
else
docker run --rm -v "$PWD/dist":/src:ro "$1" exec node /src/index.js
fi
}

build
test "$NODE18"
test "$NODE_X"
8 changes: 6 additions & 2 deletions tests/app_simple-typescript/runtest
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ build() {

test() {
port=1234
container="$(docker run -d --rm -v "$PWD/dist":/src:ro -p $port:3000 "$1" /src/index.js)"
if [ "$1" == "$NODE18" ]; then
container="$(docker run -d --rm -v "$PWD/dist":/src:ro -p $port:3000 "$1" /src/index.js)"
else
container="$(docker run -d --rm -v "$PWD/dist":/src:ro -p $port:3000 "$1" exec node /src/index.js)"
fi
sleep 1
local output expected
output="$(curl http://localhost:$port/)"
Expand All @@ -27,4 +31,4 @@ cleanup() {
trap cleanup EXIT

build
test "$NODE18"
test "$NODE_X"
8 changes: 6 additions & 2 deletions tests/app_simple-wasm/runtest
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ build() {
}

test() {
docker run --rm -v "$PWD/dist":/src:ro "$1" /src/index.mjs
if [ "$1" == "$NODE18" ]; then
docker run --rm -v "$PWD/dist":/src:ro "$1" /src/index.mjs
else
docker run --rm -v "$PWD/dist":/src:ro "$1" exec node /src/index.mjs
fi
}

build
test "$NODE18"
test "$NODE_X"
4 changes: 3 additions & 1 deletion tests/run-all-tests
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ set -ex

echo "Running tests..."

export NODE18=${1:-"ubuntu/chiselled-node:18-test"}
export NODE_X=${1:-"ubuntu/chiselled-node:18-test"}
export NODE18="ubuntu/chiselled-node:18-test"
export NODE20="ubuntu/nodejs:20-test"

CURRENT_DIR="$(dirname "$(readlink -f "$0")")"

Expand Down

0 comments on commit f203c8c

Please sign in to comment.