Compare commits

...
Sign in to create a new pull request.

55 commits

Author SHA1 Message Date
0bc6b81c8c .forgejo/workflows/openbao.yml hinzugefügt
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
openbao / build (push) Failing after 1s
Go / build (push) Successful in 30s
2025-10-20 11:28:07 +00:00
a50bc46701 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 2s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 19s
Create the timetracker DEB / Create Package (push) Failing after 2s
2025-09-05 05:34:19 +00:00
0f3e436464 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 16s
Create the timetracker DEB / Create Package (push) Successful in 18s
2025-09-03 12:44:58 +00:00
8ca87f58d3 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 13s
Create the timetracker DEB / Create Package (push) Successful in 17s
2025-09-03 12:42:08 +00:00
e943de0425 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 2s
Go / build (push) Successful in 15s
Create the timetracker DEB / Create Package (push) Successful in 26s
2025-09-03 12:38:49 +00:00
2b8bfa6c93 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 14s
Create the timetracker DEB / Create Package (push) Failing after 15s
2025-09-03 12:27:01 +00:00
75e1d5f03a .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 13s
Create the timetracker DEB / Create Package (push) Failing after 17s
2025-09-03 12:24:35 +00:00
1a2ef19c59 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 13s
2025-09-03 12:24:01 +00:00
53eb6001a5 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
CodeQL / Analyze (push) Failing after 1s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 3s
Go / build (push) Has been cancelled
2025-09-03 12:23:50 +00:00
09966039b6 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Has been cancelled
2025-09-03 12:23:39 +00:00
438f8bfcf0 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 14s
2025-09-03 12:23:09 +00:00
84c39e3519 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 12s
2025-09-03 12:21:02 +00:00
8ca4b1bc43 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 14s
2025-09-03 11:51:28 +00:00
9a904bd48f .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 13s
2025-09-03 11:51:07 +00:00
c7c194e5a5 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 13s
2025-09-03 11:49:53 +00:00
489be8de02 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 13s
Create the timetracker DEB / Create Package (push) Failing after 24s
2025-09-03 11:47:12 +00:00
4c6aca38f2 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 13s
Create the timetracker DEB / Create Package (push) Failing after 24s
2025-09-03 11:44:04 +00:00
074de69878 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
CodeQL / Analyze (push) Failing after 1s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
Create the timetracker DEB / Create Package (push) Failing after 27s
Go / build (push) Successful in 13s
2025-09-03 11:42:08 +00:00
47af533d9f .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 13s
Create the timetracker DEB / Create Package (push) Failing after 26s
2025-09-03 11:40:57 +00:00
a32b8b2a5c .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 13s
Create the timetracker DEB / Create Package (push) Failing after 26s
2025-09-03 11:39:33 +00:00
7e65e7012e .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 13s
Create the timetracker DEB / Create Package (push) Failing after 26s
2025-09-03 11:37:26 +00:00
bc4efc49b8 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 6s
Go / build (push) Successful in 24s
Create the timetracker DEB / Create Package (push) Successful in 41s
2025-09-03 11:32:09 +00:00
b72c4de2a6 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 22s
Create the timetracker DEB / Create Package (push) Failing after 32s
2025-09-03 09:21:52 +00:00
09227bd266 .forgejo/workflows/debian.yml aktualisiert
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 1s
Go / build (push) Successful in 1m0s
Create the timetracker DEB / Create Package (push) Successful in 29s
2025-09-03 09:19:58 +00:00
d218f8bbe8 test
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 14s
Go / build (push) Successful in 41s
Create the timetracker DEB / Create Package (push) Failing after 48s
2025-08-07 14:40:12 +02:00
3d817cf737 test
Some checks failed
CodeQL / Analyze (push) Failing after 1s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 8s
Go / build (push) Successful in 46s
Create the timetracker DEB / Create Package (push) Failing after 2m4s
2025-08-07 14:33:46 +02:00
692f41c5fb test
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 6s
Go / build (push) Successful in 45s
Create the timetracker DEB / Create Package (push) Failing after 25s
2025-08-07 10:12:58 +02:00
ccda5dcc01 test
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 3s
Go / build (push) Successful in 45s
Create the timetracker DEB / Create Package (push) Failing after 31s
2025-08-07 09:46:08 +02:00
eb80082733 test
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 3s
Go / build (push) Successful in 38s
Create the timetracker DEB / Create Package (push) Failing after 30s
2025-08-07 09:39:45 +02:00
d0339fee45 test
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 4s
CodeQL / Analyze (push) Failing after 7s
Go / build (push) Successful in 53s
Create the timetracker DEB / Create Package (push) Failing after 31s
2025-08-07 09:35:09 +02:00
2a0316008a test
Some checks failed
CodeQL / Analyze (push) Failing after 1s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 3s
Create the timetracker DEB / Create Package (push) Failing after 3s
Go / build (push) Successful in 40s
2025-08-06 11:15:29 +02:00
f3af9cb5a7 test
Some checks failed
CodeQL / Analyze (push) Failing after 1s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 4s
Go / build (push) Successful in 37s
Create the timetracker DEB / Create Package (push) Successful in 37s
2025-08-06 11:05:56 +02:00
6f7ff56a80 test
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 4s
Create the timetracker DEB / Create Package (push) Failing after 26s
Go / build (push) Successful in 43s
2025-08-06 11:03:27 +02:00
bc5aa1e45c test
Some checks failed
CodeQL / Analyze (push) Failing after 1s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 4s
Create the timetracker DEB / Create Package (push) Failing after 4s
Go / build (push) Successful in 43s
2025-08-06 10:54:59 +02:00
c9d9c0b0e7 test
Some checks failed
CodeQL / Analyze (push) Failing after 1s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 8s
Go / build (push) Successful in 24s
Create the timetracker DEB / Create Package (push) Failing after 4s
2025-08-06 09:08:54 +02:00
b7b725753f test
Some checks failed
CodeQL / Analyze (push) Failing after 4s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 4s
Go / build (push) Successful in 43s
Create the timetracker DEB / Create Package (push) Failing after 10s
2025-08-06 09:01:14 +02:00
9fa12746ca test
Some checks failed
CodeQL / Analyze (push) Failing after 1s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 6s
Go / build (push) Successful in 19s
Create the timetracker DEB / Create Package (push) Failing after 12s
2025-08-06 08:56:23 +02:00
390faa088b test
Some checks failed
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 1s
CodeQL / Analyze (push) Failing after 5s
Go / build (push) Successful in 38s
2025-08-06 08:55:14 +02:00
ea03051cdc test
Some checks failed
CodeQL / Analyze (push) Failing after 1s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 3s
Create the timetracker DEB / Create Package (push) Successful in 31s
Go / build (push) Successful in 1m31s
2025-08-06 08:52:14 +02:00
d540272153 test
Some checks failed
CodeQL / Analyze (push) Failing after 1s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 4s
Create the timetracker DEB / Create Package (push) Failing after 2s
Go / build (push) Successful in 42s
2025-08-06 08:45:31 +02:00
4386eef415 test
Some checks failed
CodeQL / Analyze (push) Failing after 0s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 3s
Create the timetracker DEB / Create Package (push) Failing after 7s
Go / build (push) Successful in 48s
2025-08-06 08:35:16 +02:00
08385977cc switch to v4
Some checks failed
CodeQL / Analyze (push) Failing after 1s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 6s
Create the timetracker DEB / Create Package (push) Failing after 3s
Go / build (push) Successful in 1m14s
2025-08-05 13:46:12 +02:00
8faa251b5e use softprops
Some checks failed
CodeQL / Analyze (push) Failing after 8s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 29s
Go / build (push) Successful in 32s
Create the timetracker DEB / Create Package (push) Failing after 3s
2025-08-05 11:41:25 +02:00
a216a792ff switch to v3
Some checks failed
CodeQL / Analyze (push) Failing after 3s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 34s
Create the timetracker DEB / Create Package (push) Failing after 3s
Go / build (push) Successful in 1m58s
2025-08-05 08:55:00 +02:00
24621d48fd move github actions to forgejo
Some checks failed
CodeQL / Analyze (push) Failing after 1s
Anchore Syft SBOM scan / Anchore-Build-Scan (push) Failing after 6s
Go / build (push) Successful in 42s
Create the timetracker DEB / Create Package (push) Failing after 1s
2025-07-24 12:59:00 +02:00
9347134276 Fix scripts
- use full path to binary to prevent loops
2025-06-05 08:25:42 +02:00
168cfafa93 Add missing scripts directory 2025-06-04 13:21:36 +02:00
907a7505a8 Provide update-alternatives to shwitch to archive mode 2025-06-04 13:15:39 +02:00
ronnyfriedland
432e5ab9f2 go mod tidy 2025-03-20 20:21:56 +01:00
ronnyfriedland
760d906be9 change version 2025-03-20 20:20:17 +01:00
ronnyfriedland
239fe92bff Use go 1.18 again 2025-03-20 20:07:06 +01:00
ronnyfriedland
edc5fb9641 Revert "switch to debian"
This reverts commit 80c4c07682.
2025-03-20 20:05:22 +01:00
ronnyfriedland
80c4c07682 switch to debian 2025-03-20 20:02:08 +01:00
ronnyfriedland
27711692bf raise go version to 1.19 2025-03-20 19:58:00 +01:00
ronnyfriedland
d2ff1bcc80 Add excel export 2025-03-19 20:56:23 +01:00
20 changed files with 299 additions and 51 deletions

View file

@ -0,0 +1,78 @@
name: Create the timetracker DEB
permissions:
contents: write
on:
push:
tags:
- 'v*'
jobs:
Create_Packages:
name: Create Package
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: https://code.forgejo.org/actions/setup-go@v5
with:
go-version: '1.18'
- name: Tidy dependencies
run: go mod tidy
- name: Build
run: go build -o timetracker cmd/main.go
- name: Copy necessary files
run: |
mkdir -p PKG_SOURCE/usr/local/bin
mkdir -p PKG_SOURCE/var/lib/timetracker
mkdir -p PKG_SOURCE/lib/systemd/system
cp -Rf ./DEBIAN PKG_SOURCE/
cp -Rf ./timetracker PKG_SOURCE/var/lib/timetracker/
cp -Rf ./scripts/* PKG_SOURCE/var/lib/timetracker/
cp -Rf ./systemd/* PKG_SOURCE/lib/systemd/system/
- name: Create Deb package
run: |
dpkg-deb --build PKG_SOURCE timetracker_${{github.ref_name}}.deb
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.test }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.test }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: timetracker_${{github.ref_name}}.deb
asset_name: timetracker_${{github.ref_name}}.deb
asset_content_type: application/zip
- name: Upload Artifact (für CI-Artefakt)
uses: actions/upload-artifact@v3
with:
name: timetracker_${{github.ref_name}}.deb
path: timetracker_${{github.ref_name}}.deb
retention-days: 5
token: ${{ secrets.test }}
- name: Upload Package
run: |
FILE="timetracker_${{github.ref_name}}.deb"
ORG="Ronny.Friedland"
REPO="timetracker"
VERSION=${{github.ref_name}}
curl -v --header "Authorization: Bearer ${{ secrets.TEST }}" \
--upload-file $FILE \
"https://edp.buildth.ing/api/packages/${ORG}/generic/${REPO}/${VERSION}/${FILE}"

View file

@ -0,0 +1,23 @@
name: openbao
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Read Openbao secrets
id: read-openbao-secrets
uses: hashicorp/vault-action@v2
with:
url: https://vault-test.mms-at-work.de:8200
token: ${{ secrets.VAULT_TEST_TOKEN }}
secrets: |
testproject/test/testproject foo | FOO
- name: Echo secret value from Openbao
run: echo "$FOO"

View file

@ -1,38 +0,0 @@
name: Create the timetracker DEB
permissions:
contents: write
on:
push:
tags:
- 'v*'
jobs:
Create_Packages:
name: Create Package
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build
run: go build -o timetracker cmd/main.go
- name: Copy necessary files
run: |
mkdir -p PKG_SOURCE/usr/local/bin
mkdir -p PKG_SOURCE/var/lib/timetracker
mkdir -p PKG_SOURCE/lib/systemd/system
cp -Rf ./DEBIAN PKG_SOURCE/
cp -Rf ./timetracker PKG_SOURCE/usr/local/bin/
cp -Rf ./systemd/* PKG_SOURCE/lib/systemd/system/
- name: Create Deb package
run: |
dpkg-deb --build PKG_SOURCE timetracker_${{github.ref_name}}.deb
- name: Release the Deb package
uses: softprops/action-gh-release@v1
with:
files: timetracker_${{github.ref_name}}.deb

View file

@ -1,5 +1,5 @@
Package: timetracker
Version: 1.0.2
Version: 1.2.0
Section: misc
Priority: optional
Architecture: all

View file

@ -5,6 +5,11 @@ set -e
case "$1" in
configure)
chown -R timetracker:timetracker /var/lib/timetracker
chmod u+x /var/lib/timetracker/timetracker*.sh
update-alternatives --install /usr/local/bin/timetracker timetracker /var/lib/timetracker/timetracker-archive.sh 100
update-alternatives --install /usr/local/bin/timetracker timetracker /var/lib/timetracker/timetracker.sh 1000
;;
abort-upgrade|abort-remove|abort-deconfigure)

View file

@ -10,6 +10,8 @@ case "$1" in
if getent group timetracker >/dev/null; then
delgroup --system timetracker
fi
update-alternatives --remove-all timetracker
;;
upgrade)

View file

@ -11,12 +11,21 @@ The timetracker application provides the following arguments which can be passed
| Property | Description |
|---------------|----------------------------------------------------------------------------|
| archivedata | Enables archiving timetracker status to excel archive file, default: false |
| configpath | Defines the location of the necessary files, default: /var/lib/timetracker |
## Execution
The application is triggered by a systemd timer which triggers the application via systemd unit.
*Note:* Running timetracker with systemd unit uses the default property values. To change it you have use the appropriate alternative.
### Switch alternative
```shell
update-alternatives --config timetracker
```
To enable the timer you have to (requires root privileges):
### enable the timer

View file

@ -7,27 +7,28 @@ import (
)
func main() {
mode, configPath := parseArguments()
mode, configPath, archiveData := parseArguments()
if mode == "" {
os.Exit(0)
} else if mode == "cli" {
cli.Run(&configPath)
cli.Run(&configPath, &archiveData)
os.Exit(0)
} else {
os.Exit(1)
}
}
func parseArguments() (string, string) {
func parseArguments() (string, string, bool) {
mode := flag.String("mode", "cli", "the application mode, available: cli")
configPath := flag.String("configpath", "/var/lib/timetracker", "the config path")
archiveData := flag.Bool("archivedata", false, "flag to enable data archiving")
help := flag.Bool("help", false, "print this help message")
flag.Parse()
if *help {
flag.PrintDefaults()
return "", ""
return "", "", false
} else {
return *mode, *configPath
return *mode, *configPath, *archiveData
}
}

View file

@ -11,18 +11,21 @@ func TestParameter(t *testing.T) {
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
params := []string{"-configpath", "/foo", "-mode", "testmode"}
params := []string{"-mode", "testmode", "-configpath", "/foo", "-archivedata", "true"}
flag.CommandLine = flag.NewFlagSet("test", flag.ContinueOnError)
os.Args = append([]string{"params"}, params...)
mode, configPath := parseArguments()
mode, configPath, archiveData := parseArguments()
if mode != "testmode" {
log.Fatalf("Got unexpected mode result, got %s, expected %s", "testmode", mode)
}
if configPath != "/foo" {
log.Fatalf("Got unexpected config path result, got %s, expected %s", "/foo", configPath)
}
if !archiveData {
log.Fatalf("Got unexpected archive data flag result, got %t, expected %t", true, archiveData)
}
}
func TestParameterDefaults(t *testing.T) {
@ -34,13 +37,16 @@ func TestParameterDefaults(t *testing.T) {
flag.CommandLine = flag.NewFlagSet("test", flag.ContinueOnError)
os.Args = append([]string{"defaults"}, params...)
mode, configPath := parseArguments()
mode, configPath, archiveData := parseArguments()
if mode != "cli" {
log.Fatalf("Got unexpected mode result, got %s, expected %s", "cli", mode)
}
if configPath != "/var/lib/timetracker" {
log.Fatalf("Got unexpected config path result, got %s, expected %s", "/var/lib/timetracker", configPath)
}
if archiveData {
log.Fatalf("Got unexpected archive data flag result, got %t, expected %t", false, archiveData)
}
}
func TestParameterHelp(t *testing.T) {
@ -52,11 +58,14 @@ func TestParameterHelp(t *testing.T) {
flag.CommandLine = flag.NewFlagSet("test", flag.ContinueOnError)
os.Args = append([]string{"help"}, params...)
mode, configPath := parseArguments()
mode, configPath, archiveData := parseArguments()
if mode != "" {
log.Fatalf("Got unexpected mode result, got %s, expected %s", "", mode)
}
if configPath != "" {
log.Fatalf("Got unexpected config path result, got %s, expected %s", "", configPath)
}
if archiveData {
log.Fatalf("Got unexpected archive data flag result, got %t, expected %t", false, archiveData)
}
}

13
go.mod
View file

@ -1,3 +1,16 @@
module ronnyfriedland/timetracker/v2
go 1.18
require github.com/xuri/excelize/v2 v2.9.0
require (
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.4 // indirect
github.com/xuri/efp v0.0.0-20250227110027-3491fafc2b79 // indirect
github.com/xuri/nfp v0.0.0-20250226145837-86d5fc24b2ba // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/net v0.37.0 // indirect
golang.org/x/text v0.23.0 // indirect
)

24
go.sum
View file

@ -0,0 +1,24 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/richardlehane/msoleps v1.0.4 h1:WuESlvhX3gH2IHcd8UqyCuFY5yiq/GR/yqaSM/9/g00=
github.com/richardlehane/msoleps v1.0.4/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/xuri/efp v0.0.0-20250227110027-3491fafc2b79 h1:78nKszZqigiBRBVcoe/AuPzyLTWW5B+ltBaUX1rlIXA=
github.com/xuri/efp v0.0.0-20250227110027-3491fafc2b79/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.9.0 h1:1tgOaEq92IOEumR1/JfYS/eR0KHOCsRv/rYXXh6YJQE=
github.com/xuri/excelize/v2 v2.9.0/go.mod h1:uqey4QBZ9gdMeWApPLdhm9x+9o2lq4iVmjiLfBS5hdE=
github.com/xuri/nfp v0.0.0-20250226145837-86d5fc24b2ba h1:DhIu6n3qU0joqG9f4IO6a/Gkerd+flXrmlJ+0yX2W8U=
github.com/xuri/nfp v0.0.0-20250226145837-86d5fc24b2ba/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ=
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

View file

@ -2,14 +2,17 @@ package cli
import (
"log"
"ronnyfriedland/timetracker/v2/internal/excel"
"ronnyfriedland/timetracker/v2/internal/logic"
)
const dateLayout = "02.01.2006"
const timeLayout = "15:04:05"
func Run(configPath *string) {
func Run(configPath *string, archiveData *bool) {
duration := logic.Execute(configPath)
if duration.Complete {
log.Printf("[%s] - Work duration: %2.2fh",
duration.Date.Format(dateLayout),
@ -20,5 +23,8 @@ func Run(configPath *string) {
duration.StartTime.Format(timeLayout),
duration.EndTime.Format(timeLayout))
if *archiveData {
excel.Export(configPath, duration)
}
}
}

View file

@ -16,8 +16,9 @@ func TestRunNotComplete(t *testing.T) {
log.SetOutput(&logContent)
directory, _ := createStatusFile()
archiveData := false
Run(&directory)
Run(&directory, &archiveData)
if logContent.String() != "" {
log.Fatalf("Expected empty logmessage")
@ -31,10 +32,11 @@ func TestRunComplete(t *testing.T) {
log.SetOutput(&logContent)
directory, fileName := createStatusFile()
archiveData := false
setModificationDate(fileName, "28.02.2022")
Run(&directory)
Run(&directory, &archiveData)
if logContent.String() == "" {
log.Fatalf("Expected logmessage")

61
internal/excel/excel.go Normal file
View file

@ -0,0 +1,61 @@
package excel
import (
"fmt"
"log"
"time"
"github.com/xuri/excelize/v2"
"ronnyfriedland/timetracker/v2/internal/logic"
)
var SheetName = time.Now().Format("2006")
var Headers = []string{"Date", "From", "To", "Duration"}
const dateLayout = "02.01.2006"
const timeLayout = "15:04:05"
func Export(configPath *string, duration logic.Duration) string {
archiveDataFile := *configPath + "/timetracker.xlsx"
file, err := excelize.OpenFile(archiveDataFile)
if err != nil {
file = excelize.NewFile()
}
defer func() {
err := file.Close()
if err != nil {
log.Fatal(err)
}
}()
_, err = file.NewSheet(SheetName)
if err != nil {
log.Fatalf("Failed to ensure sheet created: %v", err)
}
file.DeleteSheet("Sheet1")
for i, header := range Headers {
file.SetCellValue(SheetName, fmt.Sprintf("%s%d", string(rune(65+i)), 1), header)
}
rows, err := file.GetRows(SheetName)
if err != nil {
log.Fatalf("Failed to get rows from sheet: %v", err)
}
next := len(rows) + 1
file.SetCellValue(SheetName, fmt.Sprintf("A%d", next), duration.Date.Format(dateLayout))
file.SetCellValue(SheetName, fmt.Sprintf("B%d", next), duration.StartTime.Format(timeLayout))
file.SetCellValue(SheetName, fmt.Sprintf("C%d", next), duration.EndTime.Format(timeLayout))
file.SetCellValue(SheetName, fmt.Sprintf("D%d", next), fmt.Sprintf("%2.2f", duration.Duration.Hours()))
if err := file.SaveAs(archiveDataFile);
err != nil {
log.Fatal(err)
}
return archiveDataFile
}

View file

@ -0,0 +1,47 @@
package excel
import (
"log"
"os"
"ronnyfriedland/timetracker/v2/internal/logic"
"testing"
"time"
"github.com/xuri/excelize/v2"
)
func TestExport(t *testing.T) {
testData := logic.Duration{
Date: time.Now(),
StartTime: time.Now(),
EndTime: time.Now(),
Duration: time.Duration(1000),
}
excelDirectory := os.TempDir()
excelFile := Export(&excelDirectory, testData)
file, err := excelize.OpenFile(excelFile)
if err != nil {
log.Fatalf("Expected excel file")
}
rows, err := file.GetRows(SheetName)
if err != nil {
log.Fatalf("Expected no error getting rows")
}
if len(rows) != 2 {
log.Fatalf("Unexpected line count - expected 2, got %d", len(rows))
}
headers := rows[0]
for i := 0; i < len(headers); i++ {
if headers[i] != Headers[i] {
log.Fatalf("Unexpected header value - expected %s, got %s", Headers[i], headers[i])
}
}
defer os.Remove(excelFile)
}

View file

@ -0,0 +1,3 @@
#!/usr/bin/env sh
/var/lib/timetracker/timetracker -archivedata=true

3
scripts/timetracker.sh Normal file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env sh
/var/lib/timetracker/timetracker