From 34feb5bb649be5ab478f4f3378b4a3fa72e59379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20K=C3=A1n=C4=9B?= Date: Tue, 20 Apr 2021 16:13:56 +0200 Subject: [PATCH] Enable builds on GitHub actions --- .github/workflows/main.yml | 34 ++++++++++++++++++++++++++++++++++ cmd/web/main.go | 14 +++++++------- 2 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..980b5b5 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,34 @@ +name: CI + +on: + push: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: nixbuild/nix-quick-install-action@v5 + with: + nix_version: 2.4pre20201205_a5d85d0 + nix_conf: experimental-features = nix-command flakes + - uses: actions/checkout@v2 + # TODO reuse cache even when key changes and then do GC + - uses: actions/cache@v2 + id: cache-nix + with: + path: ~/nix + key: ${{ hashFiles('flake.nix') }}-${{ hashFiles('flake.lock') }}-${{ hashFiles('deps.nix') }} + - name: Extract the cache + if: steps.cache-nix.outputs.cache-hit + run: sudo mkdir -p /nix && sudo rsync --recursive --archive ~/nix/ /nix + - name: Build + run: 'outpath="$(nix build --print-build-logs --no-link --json .# | jq -r .[0].outputs.out)" && echo "tinyquiz-build=$outpath" >> $GITHUB_ENV' + - uses: actions/upload-artifact@v2 + with: + path: ${{ env.tinyquiz-build }}/** + retention-days: 7 + if-no-files-found: error + - name: Prepare /nix/store for caching + if: '!steps.cache-nix.outputs.cache-hit' + run: sudo rsync --recursive --archive /nix/ ~/nix diff --git a/cmd/web/main.go b/cmd/web/main.go index bfc41d5..0c691cc 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "fmt" "html/template" "log" "net/http" @@ -10,6 +9,7 @@ import ( "time" "vkane.cz/tinyquiz/pkg/model" "vkane.cz/tinyquiz/pkg/model/ent" + "vkane.cz/tinyquiz/pkg/model/ent/migrate" rtcomm "vkane.cz/tinyquiz/pkg/rtcomm" "github.com/julienschmidt/httprouter" @@ -20,8 +20,8 @@ type application struct { errorLog *log.Logger infoLog *log.Logger templateCache map[string]*template.Template - model *model.Model - rtClients *rtcomm.Clients + model *model.Model + rtClients *rtcomm.Clients } type templateData struct { @@ -47,7 +47,7 @@ func main() { } if c, err := ent.Open("postgres", "host='127.0.0.1' sslmode=disable dbname=tinyquiz"); err == nil { - if err := c.Schema.Create(context.Background()); err != nil { + if err := c.Schema.Create(context.Background(), migrate.WithDropIndex(true), migrate.WithDropColumn(true)); err != nil { errorLog.Fatal(err) } app.model = model.NewModel(c) @@ -57,9 +57,9 @@ func main() { //TODO remove debug print go func() { - for range time.Tick(2*time.Second){ - sessions, clients := app.rtClients.Count() - fmt.Printf("There are %d sessions with total of %d clients\n", sessions, clients) + for range time.Tick(2 * time.Second) { + //sessions, clients := app.rtClients.Count() + //fmt.Printf("There are %d sessions with total of %d clients\n", sessions, clients) } }()