Skip to content

Commit

Permalink
Add files
Browse files Browse the repository at this point in the history
  • Loading branch information
kazk committed Oct 26, 2023
1 parent 2c04389 commit 69d6e99
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions .github/workflows/push-image.yml
Original file line number Diff line number Diff line change
@@ -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
Empty file added .gitignore
Empty file.
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 .
```
13 changes: 13 additions & 0 deletions bin/run
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions examples/passing/preloaded.4th
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\ preloaded.4th is loaded before solution.4th
1 change: 1 addition & 0 deletions examples/passing/solution.4th
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
: solution ( u1|n1 u2|n2 -- u3|n3 ) + ; \ Addition
5 changes: 5 additions & 0 deletions examples/passing/tests.4th
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
s" solution" describe#{
s" returns sum" it#{
<{ 1 1 solution -> 2 }>
}#
}#

0 comments on commit 69d6e99

Please sign in to comment.