From 4e8b3eb422773f0d6e9c10a8ec756e875780d754 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 6 Sep 2023 15:54:25 -0400 Subject: [PATCH] Introduce a foreign document test docker container. This test will grab documents from external sources and compare Organic's parser vs the official org-mode parser to ensure they are parsing the same. This is so we do not introduce large irrelevant documents in the git history and so we do not introduce documents with restrictive licenses into the repository. --- .lighthouse/pipeline-rust-test.yaml | 1 + docker/organic_test/Dockerfile | 15 +++++- docker/organic_test/Makefile | 10 +++- .../foreign_document_test_entrypoint.sh | 54 +++++++++++++++++++ 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 docker/organic_test/foreign_document_test_entrypoint.sh diff --git a/.lighthouse/pipeline-rust-test.yaml b/.lighthouse/pipeline-rust-test.yaml index c1b2716f..e5b05bfa 100644 --- a/.lighthouse/pipeline-rust-test.yaml +++ b/.lighthouse/pipeline-rust-test.yaml @@ -83,6 +83,7 @@ spec: value: "gcr.io/kaniko-project/executor:v1.12.1" - name: EXTRA_ARGS value: + - --target=tester - --cache=true - --cache-copy-layers - --cache-repo=harbor.fizz.buzz/kanikocache/cache diff --git a/docker/organic_test/Dockerfile b/docker/organic_test/Dockerfile index 05a3216c..fab4a46c 100644 --- a/docker/organic_test/Dockerfile +++ b/docker/organic_test/Dockerfile @@ -25,7 +25,7 @@ RUN make compile RUN make DESTDIR="/root/dist" install -FROM rustlang/rust:nightly-alpine3.17 +FROM rustlang/rust:nightly-alpine3.17 AS tester ENV LANG=en_US.UTF-8 RUN apk add --no-cache musl-dev ncurses gnutls RUN cargo install --locked --no-default-features --features ci-autoclean cargo-cache @@ -33,3 +33,16 @@ COPY --from=build-emacs /root/dist/ / COPY --from=build-org-mode /root/dist/ / ENTRYPOINT ["cargo", "test"] + + +FROM build as foreign-document-gather +RUN mkdir /foreign_documents + + +FROM tester as foreign-document-test +RUN apk add --no-cache bash +RUN mkdir /foreign_documents +COPY --from=build-org-mode /root/org-mode/doc /foreign_documents/org-mode +COPY docker/organic_test/foreign_document_test_entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/organic_test/Makefile b/docker/organic_test/Makefile index f8133adf..e0f82ab0 100644 --- a/docker/organic_test/Makefile +++ b/docker/organic_test/Makefile @@ -6,7 +6,11 @@ all: build push .PHONY: build build: - docker build -t $(IMAGE_NAME) -f Dockerfile ../../ + docker build -t $(IMAGE_NAME) -f Dockerfile --target tester ../../ + +.PHONY: build_foreign_document_test +build_foreign_document_test: + docker build -t $(IMAGE_NAME)-foreign-document -f Dockerfile --target foreign-document-test ../../ .PHONY: push push: @@ -34,3 +38,7 @@ run: build .PHONY: shell shell: build docker run --rm -i -t --entrypoint /bin/sh --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source:ro" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target $(IMAGE_NAME) + +.PHONY: run_foreign_document_test +run_foreign_document_test: build_foreign_document_test + docker run --rm --init --read-only --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source:ro" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target $(IMAGE_NAME)-foreign-document diff --git a/docker/organic_test/foreign_document_test_entrypoint.sh b/docker/organic_test/foreign_document_test_entrypoint.sh new file mode 100644 index 00000000..29a73638 --- /dev/null +++ b/docker/organic_test/foreign_document_test_entrypoint.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# +# Run the Organic compare script against a series of documents sourced from exterior places. +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +function log { + (>&2 echo "${@}") +} + +function die { + local status_code="$1" + shift + (>&2 echo "${@}") + exit "$status_code" +} + +function main { + cargo build --no-default-features --features compare --profile release-lto + PARSE="${CARGO_TARGET_DIR}/release-lto/parse" + + run_compare "org-mode/org-guide.org" "/foreign_documents/org-mode/org-guide.org" + run_compare "org-mode/org-manual.org" "/foreign_documents/org-mode/org-manual.org" +} + +function run_compare { + local name="$1" + local target_document="$2" + set +e + $PARSE "$target_document" &> /dev/null + local status=$? + set -e + if [ "$status" -eq 0 ]; then + echo "$(green_text "GOOD") $name" + else + echo "$(red_text "FAIL") $name" + return 1 + fi +} + +function green_text { + (IFS=' '; printf '\x1b[38;2;0;255;0m%s\x1b[0m' "${*}") +} + +function red_text { + (IFS=' '; printf '\x1b[38;2;255;0;0m%s\x1b[0m' "${*}") +} + +function yellow_text { + (IFS=' '; printf '\x1b[38;2;255;255;0m%s\x1b[0m' "${*}") +} + +main "${@}"