From 69d6e99feaa1d88083ee17858fab7c50e093676b Mon Sep 17 00:00:00 2001 From: kazk Date: Thu, 26 Oct 2023 13:01:41 -0700 Subject: [PATCH] Add files --- .github/workflows/ci.yml | 33 +++++++++++++++++++++++++++ .github/workflows/push-image.yml | 39 ++++++++++++++++++++++++++++++++ .gitignore | 0 Dockerfile | 26 +++++++++++++++++++++ LICENSE | 21 +++++++++++++++++ README.md | 21 +++++++++++++++++ bin/run | 13 +++++++++++ examples/passing/preloaded.4th | 1 + examples/passing/solution.4th | 1 + examples/passing/tests.4th | 5 ++++ 10 files changed, 160 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/push-image.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100755 bin/run create mode 100644 examples/passing/preloaded.4th create mode 100644 examples/passing/solution.4th create mode 100644 examples/passing/tests.4th diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..07f22ef --- /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/forth' }} + steps: + - uses: actions/checkout@v2 + - 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/forth: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/forth: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..07d00c1 --- /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/forth' }} + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v2 + + - 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 }}/forth:latest + ghcr.io/${{ github.repository_owner }}/forth:${{ github.ref_name }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4116011 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM ubuntu:18.04 + +ENV LANG=C.UTF-8 +RUN set -ex; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ +# Install GNU Forth Language Environment 0.7.3 +# https://packages.ubuntu.com/bionic/gforth + gforth \ + wget \ + ca-certificates \ + ; \ + rm -rf /var/lib/apt/lists/*; + +RUN set -ex; \ + useradd --create-home codewarrior; \ + mkdir /workspace; \ + chown codewarrior:codewarrior /workspace; + +USER codewarrior +ENV USER=codewarrior \ + HOME=/home/codewarrior +WORKDIR /workspace + +# `ttester-codewars.4th` contains words to make test output in Codewars format. +RUN wget -q https://raw.githubusercontent.com/codewars/ttester-codewars/v0.0.4/ttester-codewars.4th 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..2a9a9ac --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Forth + +Container image for Forth used by CodeRunner. + +## Usage + +Use the `bin/run` to test examples in `examples/`. + +```bash +./bin/run passing +``` + +## Examples + +- `passing`: a passing example + +## Building + +```bash +docker build -t ghcr.io/codewars/forth:latest . +``` diff --git a/bin/run b/bin/run new file mode 100755 index 0000000..c01d8d0 --- /dev/null +++ b/bin/run @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -eu + +W=/workspace +FILES="preloaded.4th solution.4th ttester-codewars.4th tests.4th" +# Create container +C=$(docker container create --rm -w $W ghcr.io/codewars/forth:latest sh -c "gforth $FILES -e bye") + +# 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/preloaded.4th b/examples/passing/preloaded.4th new file mode 100644 index 0000000..c9c1dd7 --- /dev/null +++ b/examples/passing/preloaded.4th @@ -0,0 +1 @@ +\ preloaded.4th is loaded before solution.4th diff --git a/examples/passing/solution.4th b/examples/passing/solution.4th new file mode 100644 index 0000000..2cd5593 --- /dev/null +++ b/examples/passing/solution.4th @@ -0,0 +1 @@ +: solution ( u1|n1 u2|n2 -- u3|n3 ) + ; \ Addition diff --git a/examples/passing/tests.4th b/examples/passing/tests.4th new file mode 100644 index 0000000..99261c7 --- /dev/null +++ b/examples/passing/tests.4th @@ -0,0 +1,5 @@ +s" solution" describe#{ + s" returns sum" it#{ + <{ 1 1 solution -> 2 }> + }# +}#