Enable builds on GitHub actions

This commit is contained in:
Vojtěch Káně
2021-04-20 16:13:56 +02:00
parent de7b9072ef
commit 34feb5bb64
2 changed files with 41 additions and 7 deletions

34
.github/workflows/main.yml vendored Normal file
View File

@@ -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

View File

@@ -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"
@@ -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)
}
}()