Skip to content

Commit

Permalink
Add github workflow and badges
Browse files Browse the repository at this point in the history
  • Loading branch information
timchurchard committed Jan 3, 2024
1 parent 17dc881 commit cd5e034
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
14 changes: 14 additions & 0 deletions .github/lint-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# Lint version should match what is in .github/workflows/build-and-test.yml
LINT_VERSION=v1.54.2

# If command not found then install required version
golangci-lint >/dev/null || go install github.com/golangci/golangci-lint/cmd/golangci-lint@$LINT_VERSION

# Show the full version line
golangci-lint version

# Check version
found_version=$(golangci-lint version | head -n 1 | awk '{print $4}')
[ $found_version == $LINT_VERSION ] || echo -e "\033[33mWarning!\033[0m golangci-lint version $found_version does not match version $LINT_VERSION used in github actions"
14 changes: 14 additions & 0 deletions .github/mockgen-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# Lint version should match what is in .github/workflows/build-and-test.yml
MOCKGEN_VERSION=v1.6.0

# If command not found then install required version
mockgen >/dev/null 2>&1 || go install github.com/golang/mock/mockgen@$MOCKGEN_VERSION

# Show the full version line
mockgen -version

# Check version
found_version=$(mockgen -version | head -n 1 | awk '{print $1}')
[ $found_version == $MOCKGEN_VERSION ] || echo -e "\033[33mWarning!\033[0m mockgen version $found_version does not match version $MOCKGEN_VERSION used in github actions"
61 changes: 61 additions & 0 deletions .github/workflows/coverage_badge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
name: Generate code coverage badge

on:
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
name: Update coverage badge
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.

- name: Setup go
uses: actions/setup-go@v4
with:
go-version: '1.21.5'

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run Test
run: |
go test -v ./... -covermode=count -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage.out
- name: Go Coverage Badge # Pass the `coverage.out` output to this action
uses: tj-actions/coverage-badge-go@v2
with:
filename: coverage.out

- name: Verify Changed files
uses: tj-actions/verify-changed-files@v12
id: verify-changed-files
with:
files: README.md

- name: Commit changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "chore: Updated coverage badge."
- name: Push changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ github.token }}
branch: ${{ github.head_ref }}
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
on: release
name: Build Release
jobs:
release-linux-amd64:
name: release linux/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: compile and release
uses: ngs/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: amd64
GOOS: linux
EXTRA_FILES: "LICENSE"
release-linux-arm:
name: release linux/386
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: compile and release
uses: ngs/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: "arm"
GOOS: linux
EXTRA_FILES: "LICENSE"
release-linux-arm64:
name: release linux/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: compile and release
uses: ngs/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: arm64
GOOS: linux
EXTRA_FILES: "LICENSE"
release-darwin-amd64:
name: release darwin/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: compile and release
uses: ngs/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: amd64
GOOS: darwin
EXTRA_FILES: "LICENSE"
release-windows-amd64:
name: release windows/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: compile and release
uses: ngs/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: amd64
GOOS: windows
EXTRA_FILES: "LICENSE"
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
on: [push, pull_request]
name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.21.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Test
run: go test ./...
16 changes: 16 additions & 0 deletions .github/workflows/test_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: Pull Request Action
on:
pull_request:
branches:
- 'main'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: GoGitOps Step
id: gogitops
uses: beaujr/[email protected]
with:
github-actions-token: ${{secrets.GITHUB_TOKEN}}
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY:

generate:
./.github/mockgen-version.sh
go generate -v ./...

lint: generate
./.github/lint-version.sh
golangci-lint run -v ./...

test: generate
go test -cover ./...

10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# readstat

Attempt to collect and show reading statistics from ereaders like Kobo.
![Build Status](https://github.com/timchurchard/readstat/workflows/Test/badge.svg)
![Coverage](https://img.shields.io/badge/Coverage-67.3%25-yellow)
[![License](https://img.shields.io/github/license/timchurchard/readstat)](/LICENSE)
[![Release](https://img.shields.io/github/release/timchurchard/readstat.svg)](https://github.com/timchurchard/readstat/releases/latest)
[![GitHub Releases Stats of readstat](https://img.shields.io/github/downloads/timchurchard/readstat/total.svg?logo=github)](https://somsubhra.github.io/github-release-stats/?username=timchurchard&repository=readstat)

Proof of concept! I've been able to read the Kobo database and produce stats! I'll start to tidy-up now.
Attempt to collect and show reading statistics from e-reader devicess, like [Kobo](https://uk.kobobooks.com/collections/ereaders). This is a proof of concept using my two devices (Kobo Clara 2E and Libra 2 with database version 174).

## Usage

Use the `sync` command to read the Kobo database. Syncing updates a local json file. And use the `stats` command to show stats.
Use the `sync` command to read the Kobo database. Syncing updates a local json file. And use the `stats` command to make stats.

```shell
./readstat sync -d ./testfiles/20231219/libra2/KoboReader.sqlite -s tc_readstat.json
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/timchurchard/readstat

go 1.21.5
go 1.20

require github.com/ncruces/go-sqlite3 v0.11.2

Expand Down

0 comments on commit cd5e034

Please sign in to comment.