Skip to content

Commit 4d07f18

Browse files
authored
Merge pull request #1 from codewars/add-files
Add the current version
2 parents 07f7dc3 + 01bc12b commit 4d07f18

File tree

9 files changed

+211
-0
lines changed

9 files changed

+211
-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/factor' }}
12+
steps:
13+
- uses: actions/checkout@v4
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/factor: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/factor: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/factor' }}
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
steps:
18+
- uses: actions/checkout@v4
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 }}/factor:latest
37+
ghcr.io/${{ github.repository_owner }}/factor:${{ github.ref_name }}
38+
cache-from: type=gha
39+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
FROM ubuntu:18.04
2+
3+
ENV FACTOR_VERSION=0.98 TESTEST_VERSION=2.0.1
4+
ENV LANG=C.UTF-8
5+
6+
RUN set -ex; \
7+
useradd --create-home codewarrior; \
8+
mkdir -p /workspace; \
9+
chown -R codewarrior:codewarrior /workspace;
10+
11+
RUN set -ex; \
12+
apt-get update; \
13+
apt-get install -y --no-install-recommends \
14+
wget \
15+
ca-certificates \
16+
; \
17+
rm -rf /var/lib/apt/lists/*;
18+
19+
# Add the test framework
20+
RUN set -ex; \
21+
mkdir -p /opt/factor/work; \
22+
mkdir -p /opt/factor/pre; \
23+
mkdir -p /tmp/testest; \
24+
wget -q -O - https://github.com/codewars/testest/archive/refs/tags/v${TESTEST_VERSION}.tar.gz | tar xz -C /tmp/testest --strip-components=1; \
25+
cd /tmp/testest; \
26+
mv tools /opt/factor/work; \
27+
mv codewars /opt/factor/work; \
28+
mv math /opt/factor/pre; \
29+
rm -rf /tmp/testest;
30+
31+
# Install Factor
32+
RUN set -ex; \
33+
cd /opt; \
34+
wget -q -O - https://downloads.factorcode.org/releases/${FACTOR_VERSION}/factor-linux-x86-64-${FACTOR_VERSION}.tar.gz | tar xzf -; \
35+
# To minimize the size, remove misc/ (editor support, icons), some of extra/ (extra libs and apps)
36+
cd /opt/factor; \
37+
rm -rf \
38+
./misc \
39+
./extra/bunny \
40+
./extra/images/testing \
41+
./extra/usa-cities \
42+
./extra/clutter \
43+
./extra/gstreamer \
44+
./extra/websites \
45+
./extra/benchmark \
46+
./extra/gpu \
47+
./extra/snake-game \
48+
./extra/project-euler \
49+
./extra/rosetta-code \
50+
./extra/audio/engine/test \
51+
./extra/talks \
52+
; \
53+
# reimage factor.image
54+
./factor -run=codewars.imager;
55+
56+
ENV PATH=/opt/factor:$PATH \
57+
FACTOR_ROOTS=/workspace
58+
59+
USER codewarrior
60+
WORKDIR /workspace

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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Factor
2+
3+
Container image for Factor used by CodeRunner.
4+
5+
## Examples
6+
7+
Use `bin/run` to test examples inside `examples/`.
8+
9+
```bash
10+
# Usage: ./bin/run $example_name
11+
./bin/run passing
12+
```
13+
14+
> NOTE: The CodeRunner supports arbitrary vocabulary name for the tests,
15+
> but the examples must use `kata.tests` for simplicity.
16+
17+
18+
## Building
19+
20+
```bash
21+
docker build -t ghcr.io/codewars/factor:latest .
22+
```

bin/run

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

examples/passing/kata/kata.factor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
USE: math
2+
IN: kata
3+
4+
: solution ( a b -- a*b ) * ;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
IN: kata.preloaded
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
USING: kata.preloaded prettyprint tools.testest ;
2+
FROM: kata => solution ;
3+
IN: kata.tests
4+
5+
: run-tests ( -- )
6+
"Sample tests" describe#{
7+
"Succeeding tests" it#{
8+
<{ 0 1 solution -> 0 }>
9+
<{ 1 0 solution -> 0 }>
10+
<{ 1 1 solution -> 1 }>
11+
<{ 3 5 solution -> 15 }>
12+
}#
13+
"Failing tests" it#{
14+
<{ 0 0 solution -> 1 }>
15+
}#
16+
}#
17+
;
18+
19+
MAIN: run-tests

0 commit comments

Comments
 (0)