Skip to content

Commit

Permalink
Merge pull request #1 from codewars/add-files
Browse files Browse the repository at this point in the history
Add the current version
  • Loading branch information
kazk authored Dec 1, 2023
2 parents 07f7dc3 + 01bc12b commit 4d07f18
Show file tree
Hide file tree
Showing 9 changed files with 211 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/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
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/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
60 changes: 60 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
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.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 .
```
12 changes: 12 additions & 0 deletions bin/run
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions examples/passing/kata/kata.factor
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
USE: math
IN: kata

: solution ( a b -- a*b ) * ;
1 change: 1 addition & 0 deletions examples/passing/kata/preloaded/preloaded.factor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IN: kata.preloaded
19 changes: 19 additions & 0 deletions examples/passing/kata/tests/tests.factor
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4d07f18

Please sign in to comment.