Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
mfontani committed Jan 7, 2021
0 parents commit afcc27b
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dev/build-static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

go build -tags timetzdata --ldflags "-X 'main.Version=$(git describe --tags)' -linkmode external -extldflags \"-static\" -s -w" -o tstdin .
89 changes: 89 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
kind: pipeline
name: build_linux_amd64

platform:
os: linux
arch: amd64

volumes:
- name: deps
temp: {}

steps:
# Ensure we also fetch tags, to later allow "git describe --tags" to work
# https://docs.drone.io/pipeline/docker/syntax/cloning/#the---tags-flag
- name: fetch
image: mfontani/gobuzz
pull: "always" # ensure image is up to date at start of pipeline
commands:
- git fetch --tags
- name: deps
image: mfontani/gobuzz
pull: "never" # pulled on previous step
depends_on:
- fetch
volumes:
- name: deps
path: /go
commands:
- go mod download
- name: vetting
image: mfontani/gobuzz
pull: "never" # pulled on previous step
depends_on:
- fetch
- deps
volumes:
- name: deps
path: /go
commands:
- go vet
- name: test
image: mfontani/gobuzz
pull: "never" # pulled on previous step
depends_on:
- fetch
- deps
commands:
# The env var TEST=... and TZ are used in tests
- TZ=UTC go test -bench=.
- name: binary
image: mfontani/gobuzz
pull: "never" # pulled on previous step
depends_on:
- deps
- vetting
- test
volumes:
- name: deps
path: /go
commands:
# Build it...
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 .dev/build-static.sh
# This ends up being about 2-3 MiB
- ls -la tstdin
# Ensure it works...
- ./tstdin -version
- sh -c '(echo foo ; sleep 1; echo bar ; sleep 1 ; echo baz) | ./tstdin'
- name: gitea_release
image: plugins/gitea-release
pull: "always" # ensure image is up to date!
depends_on:
- binary
settings:
api_key:
from_secret: gitea_token
base_url: https://git.marcofontani.it
title: ${DRONE_TAG}
checksum:
- sha1
- sha256
- sha512
files:
- ./tstdin
when:
event:
- tag

...
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Build
"on":
push:
branches:
- '*'
tags:
- '!**'

jobs:

test:
runs-on: ubuntu-20.04
container: mfontani/gobuzz
steps:
- uses: actions/checkout@v2
- run: go mod download
- run: go vet
- run: go test ./...
env:
TZ: UTC

build:
needs: [test]
runs-on: ubuntu-20.04
container: mfontani/gobuzz
steps:
- uses: actions/checkout@v2
- run: go mod download
- run: ./.dev/build-static.sh
# Ensure it runs...
- run: ./tstdin -help
- run: sh -c '(echo foo ; sleep 1; echo bar ; sleep 1 ; echo baz) | ./tstdin'
59 changes: 59 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
name: Release
"on":
push:
tags:
- '*'

jobs:

build:
runs-on: ubuntu-20.04
container: mfontani/gobuzz
steps:
- uses: actions/checkout@v2
- run: go mod download
- run: ./.dev/build-static.sh
# Ensure it runs...
- run: ./tstdin -help
- run: sh -c '(echo foo ; sleep 1; echo bar ; sleep 1 ; echo baz) | ./tstdin'
# Compress and upload...
- run: xz --compress --stdout tstdin > tstdin.xz
- uses: actions/upload-artifact@master
with:
name: tstdin.xz
path: tstdin.xz

release:
needs: [build]
runs-on: ubuntu-20.04
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url}}
steps:
- id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}

upload:
needs: [release]
strategy:
matrix:
file: ['tstdin.xz']
runs-on: ubuntu-20.04
steps:
- uses: actions/download-artifact@master
with:
name: ${{ matrix.file }}
path: .
- uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ./${{ matrix.file }}
asset_name: ${{ matrix.file }}
asset_content_type: application/x-xz
27 changes: 27 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2021 Marco Fontani <MFONTANI@cpan.org>

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# tstdin

Timestamp your pipeline.

$ (echo foo ; sleep 1; echo bar ; sleep 1 ; echo baz) | tstdin
2031-04-07 14:20:03.952221 00:00:00.000003 00:00:00.000003 foo
2031-04-07 14:20:04.952120 00:00:00.999902 00:00:00.999898 bar
2031-04-07 14:20:05.953362 00:00:02.001144 00:00:01.001241 baz

For each line received on STDIN, it outputs:

- (1) the current date/time including microseconds
- (2) hours, minutes, seconds and microseconds since the start
- (3) hours, minutes, seconds and microseconds since the last line was received
- (4) the line that was received

… all separated by spaces.


If the time between the previous line and the current one took too long, the
(3) token will be output with color: red if it took more than a minute, or
yellow if it took more than a second.

Colors are automatically disabled if STDOUT is not a terminal, if `TERM=dumb`
or if either `NO_COLOR` or `TSTDIN_NO_COLOR` are set in the environment, but
see the `-color` and `-no-color` options.

## LICENSE

Copyright 2021 Marco Fontani <MFONTANI@cpan.org>

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module git.marcofontani.it/mfontani/tstdin

go 1.15
Loading

0 comments on commit afcc27b

Please sign in to comment.