From dae80484533e75cb84564241571aa590eafe88ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20T=C3=B3th?= Date: Tue, 12 Nov 2024 15:46:55 +0100 Subject: [PATCH] Add test workflow (#30) Related: #1 * Add smoke tests * Add test workflow --- .github/actions/with-docker/Dockerfile | 20 ++++++++ .github/actions/with-docker/action.yml | 46 ++++++++++++++++++ .github/workflows/test-pr.yml | 65 ++++++++++++++++++++++++++ Makefile | 11 ++--- {docker => package}/Dockerfile | 4 +- package/smoke-test.sh | 11 +++++ 6 files changed, 150 insertions(+), 7 deletions(-) create mode 100644 .github/actions/with-docker/Dockerfile create mode 100644 .github/actions/with-docker/action.yml create mode 100644 .github/workflows/test-pr.yml rename {docker => package}/Dockerfile (95%) create mode 100755 package/smoke-test.sh diff --git a/.github/actions/with-docker/Dockerfile b/.github/actions/with-docker/Dockerfile new file mode 100644 index 0000000..47d6bf2 --- /dev/null +++ b/.github/actions/with-docker/Dockerfile @@ -0,0 +1,20 @@ +ARG K_VERSION +FROM runtimeverificationinc/kframework-k:ubuntu-jammy-${K_VERSION} + +RUN apt-get update \ + && apt-get upgrade --yes \ + && apt-get install --yes \ + curl \ + && apt-get clean + +ARG USER=user +ARG GROUP=$USER +ARG USER_ID=1000 +ARG GROUP_ID=$USER_ID + +RUN groupadd -g $GROUP_ID $GROUP && useradd -m -u $USER_ID -s /bin/sh -g $GROUP $USER + +USER $USER:$GROUP + +ENV PATH=/home/$USER/.local/bin:$PATH +RUN curl -sSL https://install.python-poetry.org | python3 - diff --git a/.github/actions/with-docker/action.yml b/.github/actions/with-docker/action.yml new file mode 100644 index 0000000..a77748d --- /dev/null +++ b/.github/actions/with-docker/action.yml @@ -0,0 +1,46 @@ +name: 'With Docker' +description: 'Start a Docker container with the K development environment set up' +inputs: + container-name: + description: 'Docker container name to use' + required: true + type: string +runs: + using: 'composite' + steps: + - name: 'Set up Docker' + shell: bash {0} + run: | + set -euxo pipefail + + CONTAINER_NAME=${{ inputs.container-name }} + TAG=runtimeverificationinc/${CONTAINER_NAME} + DOCKERFILE=${{ github.action_path }}/Dockerfile + K_VERSION=$(cat deps/k_release) + + docker build . \ + --file ${DOCKERFILE} \ + --build-arg K_VERSION=${K_VERSION} \ + --tag ${TAG} + + - name: 'Run Docker container' + shell: bash {0} + run: | + set -euxo pipefail + + CONTAINER_NAME=${{ inputs.container-name }} + TAG=runtimeverificationinc/${CONTAINER_NAME} + WORKDIR=/home/user + + docker run \ + --name ${CONTAINER_NAME} \ + --rm \ + --interactive \ + --tty \ + --detach \ + --user root \ + --workdir ${WORKDIR} \ + ${TAG} + + docker cp . ${CONTAINER_NAME}:${WORKDIR} + docker exec ${CONTAINER_NAME} chown -R user:user ${WORKDIR} diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml new file mode 100644 index 0000000..4c8b620 --- /dev/null +++ b/.github/workflows/test-pr.yml @@ -0,0 +1,65 @@ +name: 'Test PR' +on: + pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + code-quality-checks: + name: 'Code Quality Checks & Unit Tests' + runs-on: ubuntu-latest + timeout-minutes: 5 + defaults: + run: + working-directory: kimp + steps: + - name: 'Check out code' + uses: actions/checkout@v4 + - name: 'Install Python' + uses: actions/setup-python@v5 + with: + python-version: '3.10' + - name: 'Install Poetry' + uses: Gr1N/setup-poetry@v9 + - name: 'Run code quality checks' + run: make check + - name: 'Run pyupgrade' + run: make pyupgrade + - name: 'Run unit tests' + run: make cov-unit + + integration-tests: + name: 'Integration Tests' + runs-on: [self-hosted, linux, normal] + timeout-minutes: 5 + env: + CONTAINER: imp-integration-${{ github.sha }} + steps: + - name: 'Check out code' + uses: actions/checkout@v4 + - name: 'Set up Docker' + uses: ./.github/actions/with-docker + with: + container-name: ${CONTAINER} + - name: 'Build and run integration tests' + run: docker exec -u user ${CONTAINER} make -C kimp cov-integration + - name: 'Tear down Docker container' + if: always() + run: | + docker stop --time=0 ${CONTAINER} + + docker-tests: + name: 'Docker Tests' + runs-on: [self-hosted, linux, normal] + timeout-minutes: 5 + env: + TAG: ${{ github.sha }} + CONTAINER: imp-docker-${{ github.sha }} + steps: + - name: 'Check out code' + uses: actions/checkout@v4 + - name: 'Build Docker image' + run: make docker TAG=${TAG} + - name: 'Run smoke tests' + run: docker run --rm --name ${CONTAINER} ${TAG} ./smoke-test.sh diff --git a/Makefile b/Makefile index c48bd61..51fd603 100644 --- a/Makefile +++ b/Makefile @@ -7,11 +7,12 @@ help: @echo "Please read the Makefile." .PHONY: docker -docker: docker/Dockerfile - docker build \ +docker: TAG=runtimeverificationinc/imp-semantics:$(K_VERSION) +docker: package/Dockerfile + docker build . \ --build-arg K_VERSION=$(K_VERSION) \ - -f $< -t runtimeverificationinc/imp-semantics-k:$(K_VERSION) . - touch $@ + --file $< \ + --tag $(TAG) build: build-kimp @@ -20,8 +21,6 @@ build-kimp: have-k .PHONY: have-k have-k: FOUND_VERSION=$(shell $(KOMPILE) --version | sed -n -e 's/^K version: *v\?\(.*\)$$/\1/p') - -.PHONY: have-k have-k: @[ ! -z "$(KOMPILE)" ] || \ (echo "K compiler (kompile) not found (use variable KOMPILE to override)."; exit 1) diff --git a/docker/Dockerfile b/package/Dockerfile similarity index 95% rename from docker/Dockerfile rename to package/Dockerfile index 77ad348..aa576b1 100644 --- a/docker/Dockerfile +++ b/package/Dockerfile @@ -31,11 +31,13 @@ RUN poetry -C /home/k-user/kimp-src build && \ pip install /home/k-user/kimp-src/dist/*.whl && \ rm -r /home/k-user/kimp-src && \ kdist --verbose build -j2 + WORKDIR /home/k-user/workspace +COPY --chown=k-user:k-group examples examples +COPY --chown=k-user:k-group ./package/smoke-test.sh . ENTRYPOINT ["fixuid", "-q"] - CMD ["printf", "%s\n",\ "Welcome to the K Framework!",\ "",\ diff --git a/package/smoke-test.sh b/package/smoke-test.sh new file mode 100755 index 0000000..6be4246 --- /dev/null +++ b/package/smoke-test.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +kimp --help + +kimp run --verbose --input-file examples/sumto10.imp + +kimp prove --verbose examples/specs/imp-sum-spec.k IMP-SUM-SPEC sum-spec + +kimp show --verbose IMP-SUM-SPEC sum-spec