Skip to content

Commit 69d6e99

Browse files
committed
Add files
1 parent 2c04389 commit 69d6e99

File tree

10 files changed

+160
-0
lines changed

10 files changed

+160
-0
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
if: ${{ github.repository == 'codewars/forth' }}
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: docker/setup-buildx-action@v2
15+
16+
- name: Build image
17+
uses: docker/build-push-action@v3
18+
with:
19+
context: .
20+
push: false
21+
# Make the image available in next step
22+
load: true
23+
tags: ghcr.io/codewars/forth:latest
24+
cache-from: type=gha
25+
cache-to: type=gha,mode=max
26+
27+
- name: Run Passing Example
28+
run: bin/run passing
29+
30+
- name: Report Image Size
31+
run: |
32+
echo "## Image Size" >> $GITHUB_STEP_SUMMARY
33+
docker image inspect --format '{{.Size}}' ghcr.io/codewars/forth:latest | numfmt --to=si --suffix=B >> $GITHUB_STEP_SUMMARY

.github/workflows/push-image.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Build and push a Docker image to GitHub Container Registry when
2+
# a new tag is pushed.
3+
name: Push Image
4+
5+
on:
6+
push:
7+
tags:
8+
- "*"
9+
10+
jobs:
11+
build-and-push-image:
12+
if: ${{ github.repository == 'codewars/forth' }}
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v2
22+
23+
- name: Login to GitHub Container Registry
24+
uses: docker/login-action@v2
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.repository_owner }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Build and push image
31+
uses: docker/build-push-action@v3
32+
with:
33+
context: .
34+
push: true
35+
tags: |
36+
ghcr.io/${{ github.repository_owner }}/forth:latest
37+
ghcr.io/${{ github.repository_owner }}/forth:${{ github.ref_name }}
38+
cache-from: type=gha
39+
cache-to: type=gha,mode=max

.gitignore

Whitespace-only changes.

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM ubuntu:18.04
2+
3+
ENV LANG=C.UTF-8
4+
RUN set -ex; \
5+
apt-get update; \
6+
apt-get install -y --no-install-recommends \
7+
# Install GNU Forth Language Environment 0.7.3
8+
# https://packages.ubuntu.com/bionic/gforth
9+
gforth \
10+
wget \
11+
ca-certificates \
12+
; \
13+
rm -rf /var/lib/apt/lists/*;
14+
15+
RUN set -ex; \
16+
useradd --create-home codewarrior; \
17+
mkdir /workspace; \
18+
chown codewarrior:codewarrior /workspace;
19+
20+
USER codewarrior
21+
ENV USER=codewarrior \
22+
HOME=/home/codewarrior
23+
WORKDIR /workspace
24+
25+
# `ttester-codewars.4th` contains words to make test output in Codewars format.
26+
RUN wget -q https://github.com/codewars/ttester-codewars/v0.0.4/ttester-codewars.4th

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Codewars
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Forth
2+
3+
Container image for Forth used by CodeRunner.
4+
5+
## Usage
6+
7+
Use the `bin/run` to test examples in `examples/`.
8+
9+
```bash
10+
./bin/run passing
11+
```
12+
13+
## Examples
14+
15+
- `passing`: a passing example
16+
17+
## Building
18+
19+
```bash
20+
docker build -t ghcr.io/codewars/forth:latest .
21+
```

bin/run

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
W=/workspace
5+
FILES="preloaded.4th solution.4th ttester-codewars.4th tests.4th"
6+
# Create container
7+
C=$(docker container create --rm -w $W ghcr.io/codewars/forth:latest sh -c "gforth $FILES -e bye")
8+
9+
# Copy files from the current directory
10+
docker container cp examples/${1:-passing}/. $C:$W
11+
12+
# Run tests
13+
docker container start --attach $C

examples/passing/preloaded.4th

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\ preloaded.4th is loaded before solution.4th

examples/passing/solution.4th

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
: solution ( u1|n1 u2|n2 -- u3|n3 ) + ; \ Addition

examples/passing/tests.4th

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
s" solution" describe#{
2+
s" returns sum" it#{
3+
<{ 1 1 solution -> 2 }>
4+
}#
5+
}#

0 commit comments

Comments
 (0)