From 01bc12bf610119ad753786e49d81aa9860b8b6dc Mon Sep 17 00:00:00 2001 From: kazk Date: Fri, 1 Dec 2023 12:11:40 -0800 Subject: [PATCH] Add the current version --- .github/workflows/ci.yml | 33 ++++++++++ .github/workflows/push-image.yml | 39 ++++++++++++ Dockerfile | 60 +++++++++++++++++++ LICENSE | 21 +++++++ README.md | 22 +++++++ bin/run | 12 ++++ examples/passing/kata/kata.factor | 4 ++ .../passing/kata/preloaded/preloaded.factor | 1 + examples/passing/kata/tests/tests.factor | 19 ++++++ 9 files changed, 211 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/push-image.yml create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100755 bin/run create mode 100644 examples/passing/kata/kata.factor create mode 100644 examples/passing/kata/preloaded/preloaded.factor create mode 100644 examples/passing/kata/tests/tests.factor diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..aafa119 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: CI +on: + push: + branches: + - main + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + if: ${{ github.repository == 'codewars/factor' }} + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v2 + + - name: Build image + uses: docker/build-push-action@v3 + with: + context: . + push: false + # Make the image available in next step + load: true + tags: ghcr.io/codewars/factor:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Run Passing Example + run: bin/run passing + + - name: Report Image Size + run: | + echo "## Image Size" >> $GITHUB_STEP_SUMMARY + docker image inspect --format '{{.Size}}' ghcr.io/codewars/factor:latest | numfmt --to=si --suffix=B >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml new file mode 100644 index 0000000..d6d1982 --- /dev/null +++ b/.github/workflows/push-image.yml @@ -0,0 +1,39 @@ +# Build and push a Docker image to GitHub Container Registry when +# a new tag is pushed. +name: Push Image + +on: + push: + tags: + - "*" + +jobs: + build-and-push-image: + if: ${{ github.repository == 'codewars/factor' }} + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push image + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/factor:latest + ghcr.io/${{ github.repository_owner }}/factor:${{ github.ref_name }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5b94c5f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,60 @@ +FROM ubuntu:18.04 + +ENV FACTOR_VERSION=0.98 TESTEST_VERSION=2.0.1 +ENV LANG=C.UTF-8 + +RUN set -ex; \ + useradd --create-home codewarrior; \ + mkdir -p /workspace; \ + chown -R codewarrior:codewarrior /workspace; + +RUN set -ex; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + wget \ + ca-certificates \ + ; \ + rm -rf /var/lib/apt/lists/*; + +# Add the test framework +RUN set -ex; \ + mkdir -p /opt/factor/work; \ + mkdir -p /opt/factor/pre; \ + mkdir -p /tmp/testest; \ + wget -q -O - https://github.com/codewars/testest/archive/refs/tags/v${TESTEST_VERSION}.tar.gz | tar xz -C /tmp/testest --strip-components=1; \ + cd /tmp/testest; \ + mv tools /opt/factor/work; \ + mv codewars /opt/factor/work; \ + mv math /opt/factor/pre; \ + rm -rf /tmp/testest; + +# Install Factor +RUN set -ex; \ + cd /opt; \ + wget -q -O - https://downloads.factorcode.org/releases/${FACTOR_VERSION}/factor-linux-x86-64-${FACTOR_VERSION}.tar.gz | tar xzf -; \ +# To minimize the size, remove misc/ (editor support, icons), some of extra/ (extra libs and apps) + cd /opt/factor; \ + rm -rf \ + ./misc \ + ./extra/bunny \ + ./extra/images/testing \ + ./extra/usa-cities \ + ./extra/clutter \ + ./extra/gstreamer \ + ./extra/websites \ + ./extra/benchmark \ + ./extra/gpu \ + ./extra/snake-game \ + ./extra/project-euler \ + ./extra/rosetta-code \ + ./extra/audio/engine/test \ + ./extra/talks \ + ; \ +# reimage factor.image + ./factor -run=codewars.imager; + +ENV PATH=/opt/factor:$PATH \ + FACTOR_ROOTS=/workspace + +USER codewarrior +WORKDIR /workspace diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c8f264f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Codewars + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ac18fbd --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# Factor + +Container image for Factor used by CodeRunner. + +## Examples + +Use `bin/run` to test examples inside `examples/`. + +```bash +# Usage: ./bin/run $example_name +./bin/run passing +``` + +> NOTE: The CodeRunner supports arbitrary vocabulary name for the tests, +> but the examples must use `kata.tests` for simplicity. + + +## Building + +```bash +docker build -t ghcr.io/codewars/factor:latest . +``` diff --git a/bin/run b/bin/run new file mode 100755 index 0000000..2bdc0c9 --- /dev/null +++ b/bin/run @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -eu + +W=/workspace/ +# Create a container +C=$(docker container create --rm -w $W ghcr.io/codewars/factor:latest factor -run=kata.tests) + +# Copy files from the current directory +docker container cp examples/${1:-passing}/. $C:$W + +# Run tests +docker container start --attach $C diff --git a/examples/passing/kata/kata.factor b/examples/passing/kata/kata.factor new file mode 100644 index 0000000..986d5c4 --- /dev/null +++ b/examples/passing/kata/kata.factor @@ -0,0 +1,4 @@ +USE: math +IN: kata + +: solution ( a b -- a*b ) * ; diff --git a/examples/passing/kata/preloaded/preloaded.factor b/examples/passing/kata/preloaded/preloaded.factor new file mode 100644 index 0000000..d6cedcf --- /dev/null +++ b/examples/passing/kata/preloaded/preloaded.factor @@ -0,0 +1 @@ +IN: kata.preloaded diff --git a/examples/passing/kata/tests/tests.factor b/examples/passing/kata/tests/tests.factor new file mode 100644 index 0000000..badada2 --- /dev/null +++ b/examples/passing/kata/tests/tests.factor @@ -0,0 +1,19 @@ +USING: kata.preloaded prettyprint tools.testest ; +FROM: kata => solution ; +IN: kata.tests + +: run-tests ( -- ) + "Sample tests" describe#{ + "Succeeding tests" it#{ + <{ 0 1 solution -> 0 }> + <{ 1 0 solution -> 0 }> + <{ 1 1 solution -> 1 }> + <{ 3 5 solution -> 15 }> + }# + "Failing tests" it#{ + <{ 0 0 solution -> 1 }> + }# + }# +; + +MAIN: run-tests