Skip to content

Commit

Permalink
Merge pull request #13 from hzeller/superq/build
Browse files Browse the repository at this point in the history
Add CircleCI build
  • Loading branch information
SuperQ authored Feb 7, 2019
2 parents f30879d + 8ec16d6 commit d729dc5
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 15 deletions.
39 changes: 37 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ jobs:
build:
docker:
- image: circleci/golang:1.11

steps:
- checkout
- run: sudo apt-get -y install file
- run: go mod download
- run: mkdir -v build
- run: go get github.com/mattn/go-sqlite3
- run: make -C stuff style
- run: make -C stuff stuff
- run: make -C stuff test
- run: mv stuff/stuff build/stuff
- run: mv -v stuff/stuff build/stuff-amd64
- run: GOARCH=arm GOARM=5 make -C stuff stuff
- run: mv -v stuff/stuff build/stuff-armv5
- run: file build/*
- persist_to_workspace:
root: .
Expand All @@ -21,6 +25,29 @@ jobs:
- store_artifacts:
path: build

release:
docker:
- image: circleci/golang:1.11

steps:
- run: sudo apt-get update
- run: sudo apt-get -y install fakeroot
- run: mkdir -v -p ${HOME}/bin
- run: curl -L 'https://github.com/aktau/github-release/releases/download/v0.7.2/linux-amd64-github-release.tar.bz2' | tar xvjf - --strip-components 3 -C ${HOME}/bin
- attach_workspace:
at: .
- run: cd build && fakeroot tar -czvf ../stuff-${CIRCLE_TAG}.amd64.tar.gz stuff-amd64
- run: cd build && fakeroot tar -czvf ../stuff-${CIRCLE_TAG}.armv5.tar.gz stuff-armv5
- run: >
for tarfile in stuff-*.tar.gz ; do
${HOME}/bin/github-release upload \
--user "${CIRCLE_PROJECT_USERNAME}" \
--repo "${CIRCLE_PROJECT_REPONAME}" \
--tag "${CIRCLE_TAG}" \
--name "${tarfile}" \
--file "${tarfile}"
done
workflows:
version: 2
stuff:
Expand All @@ -29,3 +56,11 @@ workflows:
filters:
tags:
only: /.*/
- release:
requires:
- build
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stuff/stuff
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/hzeller/stuff-org

require github.com/mattn/go-sqlite3 v1.10.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
12 changes: 12 additions & 0 deletions stuff/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# features of 'make'
##

GO ?= go
GOFMT ?= $(GO)fmt

all : stuff test

stuff: *.go
Expand All @@ -12,3 +15,12 @@ test:

clean:
rm -f stuff

style:
@echo ">> checking code style"
@fmtRes=$$($(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print)); \
if [ -n "$${fmtRes}" ]; then \
echo "gofmt checking failed!"; echo "$${fmtRes}"; echo; \
echo "Please ensure you are using $$($(GO) version) for formatting code."; \
exit 1; \
fi
7 changes: 4 additions & 3 deletions stuff/form-handler.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"encoding/json"
"compress/gzip"
"encoding/json"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -94,6 +94,7 @@ type FormPage struct {
FormEditable bool
ShowEditToggle bool
}

// We need another type to indicate availability of an item
// but it uses aggregation with an existing type
type JsonInfoComponent struct {
Expand Down Expand Up @@ -584,9 +585,9 @@ func (h *FormHandler) apiInfo(out http.ResponseWriter, r *http.Request) {
currentItem := h.store.FindById(id)
if currentItem != nil {
jsonResult.Available = true
jsonResult.Item = JsonComponent {
jsonResult.Item = JsonComponent{
Component: *currentItem,
Image: fmt.Sprintf("/img/%d", currentItem.Id),
Image: fmt.Sprintf("/img/%d", currentItem.Id),
}
}

Expand Down
20 changes: 10 additions & 10 deletions stuff/status-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
)

const (
kStatusPage = "/status"
kApiStatus = "/api/status"
kStatusPage = "/status"
kApiStatus = "/api/status"
kApiStatusDefaultOffset = 0
kApiStatusDefaultLimit = 100
kApiStatusDefaultLimit = 100
)

type StatusHandler struct {
Expand Down Expand Up @@ -47,10 +47,10 @@ type JsonStatus struct {
StatusItem
}
type JsonApiStatusResult struct {
Directlink string `json:"link"`
Offset int `json:"offset"`
Limit int `json:"limit"`
Items []JsonStatus `json:"status"`
Directlink string `json:"link"`
Offset int `json:"offset"`
Limit int `json:"limit"`
Items []JsonStatus `json:"status"`
}

func fillStatusItem(store StuffStore, imageDir string, id int, item *StatusItem) {
Expand Down Expand Up @@ -158,7 +158,7 @@ func (h *StatusHandler) apiStatus(out http.ResponseWriter, r *http.Request) {
limit = parsed_limit
}
}
if offset + limit > maxStatus {
if offset+limit > maxStatus {
offset, limit = 0, maxStatus
}

Expand All @@ -169,8 +169,8 @@ func (h *StatusHandler) apiStatus(out http.ResponseWriter, r *http.Request) {
Items: make([]StatusItem, limit),
}

for i := offset; i < offset + limit; i++ {
fillStatusItem(h.store, h.imgPath, i, &page.Items[i - offset])
for i := offset; i < offset+limit; i++ {
fillStatusItem(h.store, h.imgPath, i, &page.Items[i-offset])
}

jsonResult := &JsonApiStatusResult{
Expand Down

0 comments on commit d729dc5

Please sign in to comment.