From 75105c4716d44580bb0d9dd582fbdded0b039a94 Mon Sep 17 00:00:00 2001 From: Jonas Johan Solsvik Date: Mon, 23 Nov 2020 16:37:24 +0100 Subject: [PATCH 01/12] Add day00-example --- .editorconfig | 1 - .github/workflows/test.yaml | 6 ++++-- Dockerfile | 23 ++++++++++++++++++++--- Makefile | 6 ++++-- day00-example/README.md | 11 +++++++++++ day00-example/answers/main.deno.ts | 16 ++++++++++++++++ day00-example/answers/main.go | 27 +++++++++++++++++++++++++++ day00-example/answers/main.node.mjs | 19 +++++++++++++++++++ day00-example/answers/main.py | 18 ++++++++++++++++++ day00-example/input | 8 ++++++++ day00-example/output | 2 ++ day00-example/test.sh | 29 +++++++++++++++++++++++++++++ scripts/print-versions.sh | 6 ------ scripts/versions.sh | 20 ++++++++++++++++++++ 14 files changed, 178 insertions(+), 14 deletions(-) create mode 100644 day00-example/README.md create mode 100644 day00-example/answers/main.deno.ts create mode 100644 day00-example/answers/main.go create mode 100644 day00-example/answers/main.node.mjs create mode 100644 day00-example/answers/main.py create mode 100644 day00-example/input create mode 100644 day00-example/output create mode 100755 day00-example/test.sh delete mode 100755 scripts/print-versions.sh create mode 100755 scripts/versions.sh diff --git a/.editorconfig b/.editorconfig index fcd8ade1..935c9276 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,4 +11,3 @@ insert_final_newline = true [Makefile] indent_style = tab indent_size = 4 - diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 39c7be86..6ae4cdd8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -18,11 +18,13 @@ on: - README.md jobs: - test: + day00-example: runs-on: ubuntu-latest container: image: jonasjso/adventofcode2020 steps: - uses: actions/checkout@v2 - name: Print versions - run: ./scripts/print-versions.sh + run: ./scripts/versions.sh + - name: Test day 00 + run: ./day00-example/test.sh diff --git a/Dockerfile b/Dockerfile index f2055080..829a1fb1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,26 @@ FROM ubuntu:latest LABEL github=https://github.com/Arxcis/adventofcode2020 -# Apt install all the things +# Configure TZ, so we don't get interactive prompt +ENV TZ=Europe/Kiev +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +# Install all the things +RUN apt update && apt install -yqq\ + curl\ + unzip; + +# Tell ubuntu that we want to install node from nodesource +RUN curl -sL https://deb.nodesource.com/setup_15.x | bash - + +# Install all the things RUN apt update && apt install -yqq\ + # python3 v3.8.6 python3\ - python-is-python3\ - ; + # golang 1.14 + golang\ + # nodejs v15.x + nodejs + # deno v1.5.3 +RUN curl -fsSL https://deno.land/x/install/install.sh | sh && mv /root/.deno/bin/deno /bin/deno diff --git a/Makefile b/Makefile index 318a7e52..f1c5e711 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ test: - echo "hello test" + ./day00-example/test.sh dockerbuild: Dockerfile docker build . --tag jonasjso/adventofcode2020 @@ -7,6 +7,8 @@ dockerbuild: Dockerfile dockerpush: docker push jonasjso/adventofcode2020:latest +versions: + ./scripts/versions.sh -.PHONY: dockerbuild dockerpush test +.PHONY: dockerbuild dockerpush test versions diff --git a/day00-example/README.md b/day00-example/README.md new file mode 100644 index 00000000..11d197ff --- /dev/null +++ b/day00-example/README.md @@ -0,0 +1,11 @@ +# Day 0: Example day + +This example folder defines the framework of how the rest of the folders should be laid out. +## --- Part 1 --- + +Sum all numbers + +## --- Part 2 --- + +Sum all odd numbers + diff --git a/day00-example/answers/main.deno.ts b/day00-example/answers/main.deno.ts new file mode 100644 index 00000000..244eb37e --- /dev/null +++ b/day00-example/answers/main.deno.ts @@ -0,0 +1,16 @@ +import { readLines } from "https://deno.land/std@0.78.0/io/bufio.ts"; + +let sumAll = 0; +let sumOdd = 0; +for await (const line of readLines(Deno.stdin)) { + if (line === "") continue; + + const num = parseInt(line); + sumAll += num; + sumOdd += num % 2 === 0 ? 0 : num; +} + +// = Answer +console.log(`${sumAll}`); +console.log(`${sumOdd}`); +// ================ diff --git a/day00-example/answers/main.go b/day00-example/answers/main.go new file mode 100644 index 00000000..b5a23c06 --- /dev/null +++ b/day00-example/answers/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" +) + +func main() { + scanner := bufio.NewScanner(os.Stdin) + + var sumAll int64 = 0 + var sumOdd int64 = 0 + for scanner.Scan() { + line := scanner.Text() + num, _ := strconv.ParseInt(line, 10, 64) + sumAll += num + + if num%2 != 0 { + sumOdd += num + } + } + + fmt.Println(sumAll) + fmt.Println(sumOdd) +} diff --git a/day00-example/answers/main.node.mjs b/day00-example/answers/main.node.mjs new file mode 100644 index 00000000..c28e1295 --- /dev/null +++ b/day00-example/answers/main.node.mjs @@ -0,0 +1,19 @@ +import readline from "readline"; + +const lines = readline.createInterface({ + input: process.stdin, +}); + +let sumAll = 0; +let sumOdd = 0; +for await (const line of lines) { + const num = parseInt(line); + sumAll += num; + sumOdd += num % 2 === 0 ? 0 : num + +} + +// = Answer +console.log(`${sumAll}`) +console.log(`${sumOdd}`) +// ================ diff --git a/day00-example/answers/main.py b/day00-example/answers/main.py new file mode 100644 index 00000000..aea4ec6e --- /dev/null +++ b/day00-example/answers/main.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +#-*- coding:utf-8 -*- + +import fileinput + +sum_all = 0 +sum_odd = 0 + +for line in fileinput.input(): + num = int(line) + sum_all += num + if num % 2 != 0: + sum_odd += num + +# = Answer +print(str(sum_all)) +print(str(sum_odd)) +# ================ diff --git a/day00-example/input b/day00-example/input new file mode 100644 index 00000000..cbfe526f --- /dev/null +++ b/day00-example/input @@ -0,0 +1,8 @@ +1 +2 +3 +4 +8 +12 +3000 +28731 diff --git a/day00-example/output b/day00-example/output new file mode 100644 index 00000000..14a33409 --- /dev/null +++ b/day00-example/output @@ -0,0 +1,2 @@ +31761 +28735 diff --git a/day00-example/test.sh b/day00-example/test.sh new file mode 100755 index 00000000..bc753577 --- /dev/null +++ b/day00-example/test.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -e + +SCRIPT_PATH=`realpath $0` + +TASK_DIR=`dirname $SCRIPT_PATH` +ANSWERS_DIR="$TASK_DIR/answers" +INPUT=$(cat $TASK_DIR/input) +OUTPUT="$TASK_DIR/output" +SUCCESS="✅" + +TASK_NAME="${TASK_DIR%"${TASK_DIR##*[!/]}"}" +TASK_NAME="${TASK_NAME##*/}" + +# +# Run tests for day00 +# +echo "$INPUT" | deno run "$ANSWERS_DIR/main.deno.ts" | diff - $OUTPUT +echo "$TASK_NAME: deno $SUCCESS" + +echo "$INPUT" | go run "$ANSWERS_DIR/main.go" | diff - $OUTPUT +echo "$TASK_NAME: go $SUCCESS" + +echo "$INPUT" | node "$ANSWERS_DIR/main.node.mjs" | diff - $OUTPUT +echo "$TASK_NAME: node $SUCCESS" + +echo "$INPUT" | python3 "$ANSWERS_DIR/main.py" | diff - $OUTPUT +echo "$TASK_NAME: python $SUCCESS" diff --git a/scripts/print-versions.sh b/scripts/print-versions.sh deleted file mode 100755 index 13696dc7..00000000 --- a/scripts/print-versions.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -echo "" -uname -a - -echo "" -python --version diff --git a/scripts/versions.sh b/scripts/versions.sh new file mode 100755 index 00000000..006a8306 --- /dev/null +++ b/scripts/versions.sh @@ -0,0 +1,20 @@ +#!/bin/bash +echo "$ uname -a" +uname -a +echo "" + +echo "$ deno --version" +deno --version +echo "" + +echo "$ go version" +go version +echo "" + +echo "$ node --version" +node --version +echo "" + +echo "$ python3 --version" +python3 --version +echo "" From d1551ace20c5ce8d55d0d4c1b62e3812a5f6d574 Mon Sep 17 00:00:00 2001 From: Jonas Johan Solsvik Date: Mon, 23 Nov 2020 18:48:10 +0100 Subject: [PATCH 02/12] Rename answers/ -> cmd/ and add test-*.sh scripts --- .github/workflows/test.yaml | 6 ++-- Makefile | 5 ++-- README.md | 2 +- day-00-example/README.md | 12 ++++++++ .../cmd}/main.deno.ts | 0 .../answers => day-00-example/cmd}/main.go | 0 .../cmd}/main.node.mjs | 0 .../answers => day-00-example/cmd}/main.py | 0 {day00-example => day-00-example}/input | 0 {day00-example => day-00-example}/output | 0 day-00-example/test.sh | 11 +++++++ day00-example/README.md | 11 ------- day00-example/test.sh | 29 ------------------- scripts/{versions.sh => print-versions.sh} | 0 scripts/test-deno.sh | 11 +++++++ scripts/test-go.sh | 11 +++++++ scripts/test-node.sh | 11 +++++++ scripts/test-py.sh | 11 +++++++ 18 files changed, 73 insertions(+), 47 deletions(-) create mode 100644 day-00-example/README.md rename {day00-example/answers => day-00-example/cmd}/main.deno.ts (100%) rename {day00-example/answers => day-00-example/cmd}/main.go (100%) rename {day00-example/answers => day-00-example/cmd}/main.node.mjs (100%) rename {day00-example/answers => day-00-example/cmd}/main.py (100%) rename {day00-example => day-00-example}/input (100%) rename {day00-example => day-00-example}/output (100%) create mode 100755 day-00-example/test.sh delete mode 100644 day00-example/README.md delete mode 100755 day00-example/test.sh rename scripts/{versions.sh => print-versions.sh} (100%) create mode 100755 scripts/test-deno.sh create mode 100755 scripts/test-go.sh create mode 100755 scripts/test-node.sh create mode 100755 scripts/test-py.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6ae4cdd8..32031bca 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -18,13 +18,13 @@ on: - README.md jobs: - day00-example: + day-00-example: runs-on: ubuntu-latest container: image: jonasjso/adventofcode2020 steps: - uses: actions/checkout@v2 - name: Print versions - run: ./scripts/versions.sh + run: ./scripts/print-versions.sh - name: Test day 00 - run: ./day00-example/test.sh + run: ./day-00-example/test.sh diff --git a/Makefile b/Makefile index f1c5e711..995ac92e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ test: - ./day00-example/test.sh + ./day-00-example/test.sh dockerbuild: Dockerfile docker build . --tag jonasjso/adventofcode2020 @@ -8,7 +8,6 @@ dockerpush: docker push jonasjso/adventofcode2020:latest versions: - ./scripts/versions.sh + ./scripts/print-versions.sh .PHONY: dockerbuild dockerpush test versions - diff --git a/README.md b/README.md index 650af238..07b96a61 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # adventofcode2020 -Solving the 2020 edition of https://adventofcode.com/ in many languages, and test the solutions using Github CI +Solving the 2020 edition of https://adventofcode.com/ in many languages, and test the solutions using Github CI. ## References - Last attempt https://github.com/Arxcis/adventofcode2018/ diff --git a/day-00-example/README.md b/day-00-example/README.md new file mode 100644 index 00000000..ddc00f08 --- /dev/null +++ b/day-00-example/README.md @@ -0,0 +1,12 @@ +# day-00-example + +This example-folder sets the precedence, of how the rest of the folders should be laid out. + +## --- Part 1 --- + +Sum all numbers + +## --- Part 2 --- + +Sum all odd numbers + diff --git a/day00-example/answers/main.deno.ts b/day-00-example/cmd/main.deno.ts similarity index 100% rename from day00-example/answers/main.deno.ts rename to day-00-example/cmd/main.deno.ts diff --git a/day00-example/answers/main.go b/day-00-example/cmd/main.go similarity index 100% rename from day00-example/answers/main.go rename to day-00-example/cmd/main.go diff --git a/day00-example/answers/main.node.mjs b/day-00-example/cmd/main.node.mjs similarity index 100% rename from day00-example/answers/main.node.mjs rename to day-00-example/cmd/main.node.mjs diff --git a/day00-example/answers/main.py b/day-00-example/cmd/main.py similarity index 100% rename from day00-example/answers/main.py rename to day-00-example/cmd/main.py diff --git a/day00-example/input b/day-00-example/input similarity index 100% rename from day00-example/input rename to day-00-example/input diff --git a/day00-example/output b/day-00-example/output similarity index 100% rename from day00-example/output rename to day-00-example/output diff --git a/day-00-example/test.sh b/day-00-example/test.sh new file mode 100755 index 00000000..97954a34 --- /dev/null +++ b/day-00-example/test.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e +DIR=$(dirname $(realpath $0)) + +# +# Run tests for day-00-example +# +$DIR/../scripts/test-deno.sh "main.deno.ts" $DIR +$DIR/../scripts/test-go.sh "main.go" $DIR +$DIR/../scripts/test-node.sh "main.node.mjs" $DIR +$DIR/../scripts/test-py.sh "main.py" $DIR diff --git a/day00-example/README.md b/day00-example/README.md deleted file mode 100644 index 11d197ff..00000000 --- a/day00-example/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Day 0: Example day - -This example folder defines the framework of how the rest of the folders should be laid out. -## --- Part 1 --- - -Sum all numbers - -## --- Part 2 --- - -Sum all odd numbers - diff --git a/day00-example/test.sh b/day00-example/test.sh deleted file mode 100755 index bc753577..00000000 --- a/day00-example/test.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -set -e - -SCRIPT_PATH=`realpath $0` - -TASK_DIR=`dirname $SCRIPT_PATH` -ANSWERS_DIR="$TASK_DIR/answers" -INPUT=$(cat $TASK_DIR/input) -OUTPUT="$TASK_DIR/output" -SUCCESS="✅" - -TASK_NAME="${TASK_DIR%"${TASK_DIR##*[!/]}"}" -TASK_NAME="${TASK_NAME##*/}" - -# -# Run tests for day00 -# -echo "$INPUT" | deno run "$ANSWERS_DIR/main.deno.ts" | diff - $OUTPUT -echo "$TASK_NAME: deno $SUCCESS" - -echo "$INPUT" | go run "$ANSWERS_DIR/main.go" | diff - $OUTPUT -echo "$TASK_NAME: go $SUCCESS" - -echo "$INPUT" | node "$ANSWERS_DIR/main.node.mjs" | diff - $OUTPUT -echo "$TASK_NAME: node $SUCCESS" - -echo "$INPUT" | python3 "$ANSWERS_DIR/main.py" | diff - $OUTPUT -echo "$TASK_NAME: python $SUCCESS" diff --git a/scripts/versions.sh b/scripts/print-versions.sh similarity index 100% rename from scripts/versions.sh rename to scripts/print-versions.sh diff --git a/scripts/test-deno.sh b/scripts/test-deno.sh new file mode 100755 index 00000000..54be4277 --- /dev/null +++ b/scripts/test-deno.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +# Usage: ../test-deno.sh FILENAME DIR +# Example: ../test-deno.sh main.deno.ts /home/jonas/adventofcode2020/day-00-example + +FILENAME=$1 +DIR=$2 + +echo "$(cat $DIR/input)" | deno run "$DIR/cmd/$FILENAME" | diff - "$DIR/output" +echo "$DIR / deno run $FILENAME ✅" diff --git a/scripts/test-go.sh b/scripts/test-go.sh new file mode 100755 index 00000000..b38a7b50 --- /dev/null +++ b/scripts/test-go.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +# Usage: ../test-go.sh FILENAME DIR +# Example: ../test-go.sh main.go /home/jonas/adventofcode2020/day-00-example + +FILENAME=$1 +DIR=$2 + +echo "$(cat $DIR/input)" | go run "$DIR/cmd/$FILENAME" | diff - "$DIR/output" +echo "$DIR / go run $FILENAME ✅" diff --git a/scripts/test-node.sh b/scripts/test-node.sh new file mode 100755 index 00000000..f8e5e915 --- /dev/null +++ b/scripts/test-node.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +# Usage: ../test-node.sh FILENAME DIR +# Example: ../test-node.sh main.node.ts /home/jonas/adventofcode2020/day-00-example + +FILENAME=$1 +DIR=$2 + +echo "$(cat $DIR/input)" | node "$DIR/cmd/$FILENAME" | diff - "$DIR/output" +echo "$DIR / node $FILENAME ✅" diff --git a/scripts/test-py.sh b/scripts/test-py.sh new file mode 100755 index 00000000..d4f8c625 --- /dev/null +++ b/scripts/test-py.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +# Usage: ../test-py.sh FILENAME DIR +# Example: ../test-py.sh main.py /home/jonas/adventofcode2020/day-00-example + +FILENAME=$1 +DIR=$2 + +echo "$(cat $DIR/input)" | python3 "$DIR/cmd/$FILENAME" | diff - "$DIR/output" +echo "$DIR / python3 $FILENAME ✅" From d4ee99466de839c0fadb48e773b1ca9f0cf78512 Mon Sep 17 00:00:00 2001 From: Jonas Johan Solsvik Date: Mon, 23 Nov 2020 19:09:13 +0100 Subject: [PATCH 03/12] Run day-00-example workflow only when folder is updated --- .../{test.yaml => day-00-example.yaml} | 21 ++++--------------- day-00-example/README.md | 2 +- 2 files changed, 5 insertions(+), 18 deletions(-) rename .github/workflows/{test.yaml => day-00-example.yaml} (51%) diff --git a/.github/workflows/test.yaml b/.github/workflows/day-00-example.yaml similarity index 51% rename from .github/workflows/test.yaml rename to .github/workflows/day-00-example.yaml index 32031bca..09d170b9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/day-00-example.yaml @@ -1,24 +1,11 @@ -name: test +name: day-00-example on: push: - branches: - - main - paths-ignore: - - README.md - - pull_request: - branches: - - main - types: - - opened - - synchronize - - reopened - - ready_for_review - paths-ignore: - - README.md + paths: + - 'day-00-example/**' jobs: - day-00-example: + test: runs-on: ubuntu-latest container: image: jonasjso/adventofcode2020 diff --git a/day-00-example/README.md b/day-00-example/README.md index ddc00f08..3dd13480 100644 --- a/day-00-example/README.md +++ b/day-00-example/README.md @@ -1,6 +1,6 @@ # day-00-example -This example-folder sets the precedence, of how the rest of the folders should be laid out. +This example-folder sets the precedence, for how the rest of the folders should be laid out. ## --- Part 1 --- From 6f57063426e04cf5eae4b951bffac942fe23178c Mon Sep 17 00:00:00 2001 From: Jonas Johan Solsvik Date: Mon, 23 Nov 2020 19:13:50 +0100 Subject: [PATCH 04/12] README.md / Add status badge --- .github/workflows/day-00-example.yaml | 2 +- README.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/day-00-example.yaml b/.github/workflows/day-00-example.yaml index 09d170b9..cb0c3582 100644 --- a/.github/workflows/day-00-example.yaml +++ b/.github/workflows/day-00-example.yaml @@ -13,5 +13,5 @@ jobs: - uses: actions/checkout@v2 - name: Print versions run: ./scripts/print-versions.sh - - name: Test day 00 + - name: Run test run: ./day-00-example/test.sh diff --git a/README.md b/README.md index 07b96a61..37bc98a3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # adventofcode2020 Solving the 2020 edition of https://adventofcode.com/ in many languages, and test the solutions using Github CI. +## Status +![day-00-example](https://github.com/Arxcis/adventofcode2020/workflows/day-00-example/badge.svg) + ## References - Last attempt https://github.com/Arxcis/adventofcode2018/ From 0122859d548671fc781962794b460adce26387bf Mon Sep 17 00:00:00 2001 From: Jonas Johan Solsvik Date: Mon, 23 Nov 2020 19:50:06 +0100 Subject: [PATCH 05/12] Update README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 37bc98a3..ec87ff71 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,18 @@ # adventofcode2020 Solving the 2020 edition of https://adventofcode.com/ in many languages, and test the solutions using Github CI. +## Contributing +1. Make a branch. Example: `git checkout -b jonas/day-03` +2. Add a file with your code, in a language of your choice. Example: `touch ./day-03/cmd/super-optimized.py` +3. Add a test. To add a test, add a line of code to `./day-03/test.sh`. Example: +```sh +$DIR/../scripts/test-py.sh "super-optimized.py" $DIR +``` +4. Make a Pull Request to the `main` branch. +5. Get merged! + +NOTE: If we don't support the language you want, please make an issue and suggest a change to the `Dockerfile`. + ## Status ![day-00-example](https://github.com/Arxcis/adventofcode2020/workflows/day-00-example/badge.svg) From 60b2f5a1dab0bf827d610a8d78a0474446799e51 Mon Sep 17 00:00:00 2001 From: Jonas Johan Solsvik Date: Mon, 23 Nov 2020 20:00:35 +0100 Subject: [PATCH 06/12] Add make-workflows.sh and make-scaffold.sh commands - Not running them yet --- Makefile | 8 +++++++- day-00-example/test.sh | 2 -- scripts/make-scaffold.sh | 34 ++++++++++++++++++++++++++++++++++ scripts/make-workflows.sh | 24 ++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100755 scripts/make-scaffold.sh create mode 100755 scripts/make-workflows.sh diff --git a/Makefile b/Makefile index 995ac92e..c4945031 100644 --- a/Makefile +++ b/Makefile @@ -10,4 +10,10 @@ dockerpush: versions: ./scripts/print-versions.sh -.PHONY: dockerbuild dockerpush test versions +workflows: + ./scripts/make-workflows.sh + +scaffold: + ./scripts/make-scaffold.sh + +.PHONY: dockerbuild dockerpush test versions workflows scaffold diff --git a/day-00-example/test.sh b/day-00-example/test.sh index 97954a34..86ab6442 100755 --- a/day-00-example/test.sh +++ b/day-00-example/test.sh @@ -2,9 +2,7 @@ set -e DIR=$(dirname $(realpath $0)) -# # Run tests for day-00-example -# $DIR/../scripts/test-deno.sh "main.deno.ts" $DIR $DIR/../scripts/test-go.sh "main.go" $DIR $DIR/../scripts/test-node.sh "main.node.mjs" $DIR diff --git a/scripts/make-scaffold.sh b/scripts/make-scaffold.sh new file mode 100755 index 00000000..f540072c --- /dev/null +++ b/scripts/make-scaffold.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +for i in {01,02} +do + mkdir -p "./day-$i/cmd" + cat > "./day-$i/cmd/.keep" << KEEP +KEEP + + cat > "./day-$i/README.md" << README +# day-$i +## --- Part 1 --- +## --- Part 2 --- +README + + cat > "./day-$i/input" << INPUT + +INPUT + + cat > "./day-$i/output" << OUTPUT + +OUTPUT + + cat > "./day-$i/test.sh" << 'TEST' +#!/bin/bash +set -e +DIR=$(dirname $(realpath $0)) + +# Run tests +# Example: $DIR/../scripts/test-deno.sh "main.deno.ts" $DIR +TEST + + chmod +x ./day-$i/test.sh +done + diff --git a/scripts/make-workflows.sh b/scripts/make-workflows.sh new file mode 100755 index 00000000..000234fc --- /dev/null +++ b/scripts/make-workflows.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +for i in {01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24} +do + cat > "./.github/workflows/day-$i.yaml" << WORKFLOW +name: day-${i} +on: +push: + paths: + - 'day-${i}/**' + +jobs: +test: + runs-on: ubuntu-latest + container: + image: jonasjso/adventofcode2020 + steps: + - uses: actions/checkout@v2 + - name: Print versions + run: ./scripts/print-versions.sh + - name: Run test + run: ./day-${i}/test.sh +WORKFLOW +done From e7b043b7c158f6f2a22508a616d8e83e26a21007 Mon Sep 17 00:00:00 2001 From: Jonas Johan Solsvik Date: Mon, 23 Nov 2020 21:25:02 +0100 Subject: [PATCH 07/12] Change test-**.sh API-s to take full cmd path --- day-00-example/test.sh | 8 ++++---- scripts/test-deno.sh | 12 ++++++------ scripts/test-go.sh | 12 ++++++------ scripts/test-node.sh | 12 ++++++------ scripts/test-py.sh | 12 ++++++------ 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/day-00-example/test.sh b/day-00-example/test.sh index 86ab6442..66e8a7a5 100755 --- a/day-00-example/test.sh +++ b/day-00-example/test.sh @@ -3,7 +3,7 @@ set -e DIR=$(dirname $(realpath $0)) # Run tests for day-00-example -$DIR/../scripts/test-deno.sh "main.deno.ts" $DIR -$DIR/../scripts/test-go.sh "main.go" $DIR -$DIR/../scripts/test-node.sh "main.node.mjs" $DIR -$DIR/../scripts/test-py.sh "main.py" $DIR +$DIR/../scripts/test-deno.sh $DIR "./cmd/main.deno.ts" +$DIR/../scripts/test-go.sh $DIR "./cmd/main.go" +$DIR/../scripts/test-node.sh $DIR "./cmd/main.node.mjs" +$DIR/../scripts/test-py.sh $DIR "./cmd/main.py" diff --git a/scripts/test-deno.sh b/scripts/test-deno.sh index 54be4277..42711bd5 100755 --- a/scripts/test-deno.sh +++ b/scripts/test-deno.sh @@ -1,11 +1,11 @@ #!/bin/bash set -e -# Usage: ../test-deno.sh FILENAME DIR -# Example: ../test-deno.sh main.deno.ts /home/jonas/adventofcode2020/day-00-example +# Usage: ../test-deno.sh DIR CMD +# Example: ../test-deno.sh /adventofcode2020/day-03 cmd/main.deno.ts -FILENAME=$1 -DIR=$2 +DIR=$1 +CMD=$2 -echo "$(cat $DIR/input)" | deno run "$DIR/cmd/$FILENAME" | diff - "$DIR/output" -echo "$DIR / deno run $FILENAME ✅" +echo "$(cat $DIR/input)" | deno run "$DIR/$CMD" | diff - "$DIR/output" +echo "$DIR / deno run $CMD ✅" diff --git a/scripts/test-go.sh b/scripts/test-go.sh index b38a7b50..256d7b68 100755 --- a/scripts/test-go.sh +++ b/scripts/test-go.sh @@ -1,11 +1,11 @@ #!/bin/bash set -e -# Usage: ../test-go.sh FILENAME DIR -# Example: ../test-go.sh main.go /home/jonas/adventofcode2020/day-00-example +# Usage: ../test-go.sh DIR CMD +# Example: ../test-go.sh /adventofcode2020/day-03 cmd/main.go -FILENAME=$1 -DIR=$2 +DIR=$1 +CMD=$2 -echo "$(cat $DIR/input)" | go run "$DIR/cmd/$FILENAME" | diff - "$DIR/output" -echo "$DIR / go run $FILENAME ✅" +echo "$(cat $DIR/input)" | go run "$DIR/$CMD" | diff - "$DIR/output" +echo "$DIR / go run $CMD ✅" diff --git a/scripts/test-node.sh b/scripts/test-node.sh index f8e5e915..fe7417c0 100755 --- a/scripts/test-node.sh +++ b/scripts/test-node.sh @@ -1,11 +1,11 @@ #!/bin/bash set -e -# Usage: ../test-node.sh FILENAME DIR -# Example: ../test-node.sh main.node.ts /home/jonas/adventofcode2020/day-00-example +# Usage: ../test-node.sh DIR CMD +# Example: ../test-node.sh /adventofcode2020/day-03 cmd/main.node.mjs -FILENAME=$1 -DIR=$2 +DIR=$1 +CMD=$2 -echo "$(cat $DIR/input)" | node "$DIR/cmd/$FILENAME" | diff - "$DIR/output" -echo "$DIR / node $FILENAME ✅" +echo "$(cat $DIR/input)" | node "$DIR/$CMD" | diff - "$DIR/output" +echo "$DIR / node $CMD ✅" diff --git a/scripts/test-py.sh b/scripts/test-py.sh index d4f8c625..312b43e8 100755 --- a/scripts/test-py.sh +++ b/scripts/test-py.sh @@ -1,11 +1,11 @@ #!/bin/bash set -e -# Usage: ../test-py.sh FILENAME DIR -# Example: ../test-py.sh main.py /home/jonas/adventofcode2020/day-00-example +# Usage: ../test-py.sh DIR CMD +# Example: ../test-py.sh /adventofcode2020/day-03 cmd/main.py -FILENAME=$1 -DIR=$2 +DIR=$1 +CMD=$2 -echo "$(cat $DIR/input)" | python3 "$DIR/cmd/$FILENAME" | diff - "$DIR/output" -echo "$DIR / python3 $FILENAME ✅" +echo "$(cat $DIR/input)" | python3 "$DIR/$CMD" | diff - "$DIR/output" +echo "$DIR / python3 $CMD ✅" From 07c114c4feaa06f57c08ca2dc3b46710a2751a7b Mon Sep 17 00:00:00 2001 From: Jonas Johan Solsvik Date: Mon, 23 Nov 2020 21:48:26 +0100 Subject: [PATCH 08/12] Dockerfile add comment about rust-support --- Dockerfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 829a1fb1..b6ebe443 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,6 @@ LABEL github=https://github.com/Arxcis/adventofcode2020 ENV TZ=Europe/Kiev RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -# Install all the things RUN apt update && apt install -yqq\ curl\ unzip; @@ -23,4 +22,9 @@ RUN apt update && apt install -yqq\ nodejs # deno v1.5.3 -RUN curl -fsSL https://deno.land/x/install/install.sh | sh && mv /root/.deno/bin/deno /bin/deno +RUN curl -fsSL https://deno.land/x/install/install.sh | sh\ + && mv -v /root/.deno/bin/* /bin/ + +# @TODO Enable rust support rust v1.48 +#RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y\ + # && mv -v /root/.cargo/bin/* /bin/ From d888e251f5822f21ff7acfb1f779529a883bcdda Mon Sep 17 00:00:00 2001 From: Jonas Johan Solsvik Date: Mon, 23 Nov 2020 21:49:25 +0100 Subject: [PATCH 09/12] Update example in make-scaffold.sh --- scripts/make-scaffold.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/make-scaffold.sh b/scripts/make-scaffold.sh index f540072c..d6ef34c2 100755 --- a/scripts/make-scaffold.sh +++ b/scripts/make-scaffold.sh @@ -26,7 +26,7 @@ set -e DIR=$(dirname $(realpath $0)) # Run tests -# Example: $DIR/../scripts/test-deno.sh "main.deno.ts" $DIR +# Example: $DIR/../scripts/test-deno.sh $DIR ./cmd/main.deno.ts TEST chmod +x ./day-$i/test.sh From b1bfb69531c760b00672dbb9fab084cca226424c Mon Sep 17 00:00:00 2001 From: Jonas Johan Solsvik Date: Mon, 23 Nov 2020 22:21:49 +0100 Subject: [PATCH 10/12] Improve README.md --- README.md | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ec87ff71..2a1f7117 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,34 @@ Solving the 2020 edition of https://adventofcode.com/ in many languages, and tes ## Contributing 1. Make a branch. Example: `git checkout -b jonas/day-03` -2. Add a file with your code, in a language of your choice. Example: `touch ./day-03/cmd/super-optimized.py` -3. Add a test. To add a test, add a line of code to `./day-03/test.sh`. Example: +2. Write a program, in the language of your choice. Example: `vim ./day-03/cmd/super-optimized.py` +3. Test your program. + +```sh +cat ./input | python3 ./cmd/super-optimized.py | diff - ./output +``` + +4. Make sure your program is automatically tested by the Github CI, by adding a line of code to `./day-03/test.sh`. +*Example line:* ```sh -$DIR/../scripts/test-py.sh "super-optimized.py" $DIR +$DIR/../scripts/test-py.sh $DIR "./cmd/super-optimized.py" ``` -4. Make a Pull Request to the `main` branch. -5. Get merged! -NOTE: If we don't support the language you want, please make an issue and suggest a change to the `Dockerfile`. +5. Make a Pull Request to the `main` branch. +6. Get merged! + +**How are programs tested?** + +Every program gets the `input`-challenge delivered to `stdin`, and every program is expected to respond by writing the `output` - the answer to the `input`-challenge - to `stdout`. + +```sh +#!/bin/bash +cat ./input | | diff - ./output +``` + +**The CI does not support my favourite language. What do I do?** + +If we don't support the language you want to write in, don't worry. Make an issue on `Github`, and we will add it. ## Status ![day-00-example](https://github.com/Arxcis/adventofcode2020/workflows/day-00-example/badge.svg) From a6f5e57ffe4c5e8283f76ab58562f9124fd0a247 Mon Sep 17 00:00:00 2001 From: Jonas Johan Solsvik Date: Mon, 23 Nov 2020 23:38:56 +0100 Subject: [PATCH 11/12] Use cat directly instead of wrapping it in echo --- day-00-example/test.sh | 11 +++++------ scripts/test-deno.sh | 2 +- scripts/test-go.sh | 2 +- scripts/test-node.sh | 2 +- scripts/test-py.sh | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/day-00-example/test.sh b/day-00-example/test.sh index 66e8a7a5..b80c7d46 100755 --- a/day-00-example/test.sh +++ b/day-00-example/test.sh @@ -1,9 +1,8 @@ #!/bin/bash -set -e DIR=$(dirname $(realpath $0)) -# Run tests for day-00-example -$DIR/../scripts/test-deno.sh $DIR "./cmd/main.deno.ts" -$DIR/../scripts/test-go.sh $DIR "./cmd/main.go" -$DIR/../scripts/test-node.sh $DIR "./cmd/main.node.mjs" -$DIR/../scripts/test-py.sh $DIR "./cmd/main.py" +# Run tests +$DIR/../scripts/test-deno.sh $DIR "cmd/main.deno.ts" +$DIR/../scripts/test-go.sh $DIR "cmd/main.go" +$DIR/../scripts/test-node.sh $DIR "cmd/main.node.mjs" +$DIR/../scripts/test-py.sh $DIR "cmd/main.py" \ No newline at end of file diff --git a/scripts/test-deno.sh b/scripts/test-deno.sh index 42711bd5..f988060d 100755 --- a/scripts/test-deno.sh +++ b/scripts/test-deno.sh @@ -7,5 +7,5 @@ set -e DIR=$1 CMD=$2 -echo "$(cat $DIR/input)" | deno run "$DIR/$CMD" | diff - "$DIR/output" +cat "$DIR/input" | deno run "$DIR/$CMD" | diff - "$DIR/output" echo "$DIR / deno run $CMD ✅" diff --git a/scripts/test-go.sh b/scripts/test-go.sh index 256d7b68..f7f4be1c 100755 --- a/scripts/test-go.sh +++ b/scripts/test-go.sh @@ -7,5 +7,5 @@ set -e DIR=$1 CMD=$2 -echo "$(cat $DIR/input)" | go run "$DIR/$CMD" | diff - "$DIR/output" +cat "$DIR/input" | go run "$DIR/$CMD" | diff - "$DIR/output" echo "$DIR / go run $CMD ✅" diff --git a/scripts/test-node.sh b/scripts/test-node.sh index fe7417c0..f894d230 100755 --- a/scripts/test-node.sh +++ b/scripts/test-node.sh @@ -7,5 +7,5 @@ set -e DIR=$1 CMD=$2 -echo "$(cat $DIR/input)" | node "$DIR/$CMD" | diff - "$DIR/output" +cat "$DIR/input" | node "$DIR/$CMD" | diff - "$DIR/output" echo "$DIR / node $CMD ✅" diff --git a/scripts/test-py.sh b/scripts/test-py.sh index 312b43e8..64000a57 100755 --- a/scripts/test-py.sh +++ b/scripts/test-py.sh @@ -7,5 +7,5 @@ set -e DIR=$1 CMD=$2 -echo "$(cat $DIR/input)" | python3 "$DIR/$CMD" | diff - "$DIR/output" +cat "$DIR/input" | python3 "$DIR/$CMD" | diff - "$DIR/output" echo "$DIR / python3 $CMD ✅" From e75a2e938989c3205b1f32fc806f82f1362254b0 Mon Sep 17 00:00:00 2001 From: Jonas Johan Solsvik Date: Mon, 23 Nov 2020 23:46:13 +0100 Subject: [PATCH 12/12] Update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2a1f7117..8e1d50df 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,17 @@ Solving the 2020 edition of https://adventofcode.com/ in many languages, and tes ## Contributing 1. Make a branch. Example: `git checkout -b jonas/day-03` -2. Write a program, in the language of your choice. Example: `vim ./day-03/cmd/super-optimized.py` +2. Write a program, in the language of your choice. Example: `vim day-03/cmd/super-optimized.py` 3. Test your program. ```sh -cat ./input | python3 ./cmd/super-optimized.py | diff - ./output +cat day-03/input | python3 day-03/cmd/super-optimized.py | diff - day-03/output ``` -4. Make sure your program is automatically tested by the Github CI, by adding a line of code to `./day-03/test.sh`. +4. Make sure your program is automatically tested by the Github CI, by adding a line of code to `day-03/test.sh`. *Example line:* ```sh -$DIR/../scripts/test-py.sh $DIR "./cmd/super-optimized.py" +$DIR/../scripts/test-py.sh $DIR "cmd/super-optimized.py" ``` 5. Make a Pull Request to the `main` branch. @@ -21,11 +21,11 @@ $DIR/../scripts/test-py.sh $DIR "./cmd/super-optimized.py" **How are programs tested?** -Every program gets the `input`-challenge delivered to `stdin`, and every program is expected to respond by writing the `output` - the answer to the `input`-challenge - to `stdout`. +Every program gets the `input`-challenge delivered to `stdin`, and every program is expected to answer, by writing the `output`-answer to `stdout`. ```sh #!/bin/bash -cat ./input | | diff - ./output +cat input | | diff - output ``` **The CI does not support my favourite language. What do I do?**