Skip to content

Commit a487547

Browse files
committed
Add files
1 parent d77ff4c commit a487547

File tree

9 files changed

+175
-0
lines changed

9 files changed

+175
-0
lines changed

.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/lean' }}
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@v1
22+
23+
- name: Login to GitHub Container Registry
24+
uses: docker/login-action@v1
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@v2
32+
with:
33+
context: .
34+
push: true
35+
tags: |
36+
ghcr.io/${{ github.repository_owner }}/lean:latest
37+
ghcr.io/${{ github.repository_owner }}/lean:${{ github.ref_name }}
38+
cache-from: type=gha
39+
cache-to: type=gha,mode=max

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.olean
2+
/_target
3+
/leanpkg.path

Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM ubuntu:18.04
2+
3+
RUN set -ex; \
4+
useradd --create-home -u 9999 codewarrior; \
5+
mkdir -p /workspace; \
6+
chown -R codewarrior:codewarrior /workspace;
7+
8+
ENV LC_ALL=C.UTF-8 LANG=C.UTF-8
9+
RUN set -ex; \
10+
apt-get update; \
11+
apt-get install -y --no-install-recommends \
12+
wget \
13+
ca-certificates \
14+
git \
15+
python3-pip \
16+
python3-setuptools \
17+
; \
18+
# Install `leanproject`
19+
pip3 install mathlibtools; \
20+
rm -rf /tmp/* /var/lib/apt/lists/*;
21+
22+
USER codewarrior
23+
# Install Elan to manage Lean versions
24+
RUN set -ex; \
25+
cd /tmp; \
26+
wget -q https://github.com/Kha/elan/releases/download/v0.10.2/elan-x86_64-unknown-linux-gnu.tar.gz; \
27+
tar xf elan-x86_64-unknown-linux-gnu.tar.gz; \
28+
rm elan-x86_64-unknown-linux-gnu.tar.gz; \
29+
./elan-init -y --no-modify-path; \
30+
rm elan-init;
31+
ENV PATH=/home/codewarrior/.elan/bin:$PATH
32+
33+
WORKDIR /workspace
34+
COPY --chown=codewarrior:codewarrior leanpkg.toml /workspace/leanpkg.toml
35+
RUN set -ex; \
36+
cd /workspace; \
37+
# `leanproject` command requires git repository
38+
git init -q; \
39+
mkdir src; \
40+
mkdir test; \
41+
# Get mathlib olean files
42+
leanproject get-mathlib-cache; \
43+
# Check timestamps are correct
44+
leanproject check;

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) 2022 Qualified
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Lean
2+
3+
Container image for Lean used by CodeRunner.
4+
5+
## Usage
6+
7+
```bash
8+
W=/workspace/
9+
# Create container
10+
C=$(docker container create --rm -w $W ghcr.io/codewars/lean:latest lean test/SolutionTest.lean)
11+
12+
# Copy files from the current directory
13+
# src/Solution.lean
14+
# src/Preloaded.lean
15+
# test/SolutionTest.lean
16+
docker container cp ./. $C:$W
17+
18+
# Run tests
19+
docker container start --attach $C
20+
```
21+
22+
## Building
23+
24+
```bash
25+
$ docker build -t ghcr.io/codewars/lean:latest .
26+
```

leanpkg.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "lean-challenge"
3+
version = "1.0"
4+
lean_version = "leanprover-community/lean:3.20.0"
5+
path = "src"
6+
7+
[dependencies]
8+
mathlib = {git = "https://github.com/leanprover-community/mathlib", rev = "da66bb81bf0466335bae82077f0c335dfe53aeb3"}

src/Preloaded.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Task 1: no axioms required
2+
def TASK_1 := ∀ n m : ℕ, n + m = n + m
3+
notation `TASK_1` := TASK_1
4+
5+
-- Task 2: using `simp` introduces `propext`
6+
def TASK_2 := ∀ n m : ℕ, n + m = m + n
7+
notation `TASK_2` := TASK_2
8+
9+
-- Task 3: requires all 3 core axioms
10+
def TASK_3 := ∀ p : Prop, p ∨ ¬p
11+
notation `TASK_3` := TASK_3

src/Solution.lean

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Preloaded tactic
2+
open classical
3+
4+
-- Task 1: Prove that n + m = n + m
5+
theorem immediate : ∀ n m : ℕ, n + m = n + m :=
6+
by intros; refl
7+
8+
-- Task 2: Prove that n + m = m + n
9+
theorem plus_comm : ∀ n m : ℕ, n + m = m + n :=
10+
by intros; apply add_comm
11+
12+
-- Task 3: Prove excluded middle
13+
theorem excluded_middle : ∀ p : Prop, p ∨ ¬p := em

test/SolutionTest.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Preloaded Solution
2+
3+
theorem task_1 : TASK_1 := immediate
4+
#print axioms task_1
5+
6+
theorem task_2 : TASK_2 := plus_comm
7+
#print axioms task_2
8+
9+
theorem task_3 : TASK_3 := excluded_middle
10+
#print axioms task_3

0 commit comments

Comments
 (0)