-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9548841
Showing
15 changed files
with
843 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Golang CI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
types: [opened, reopened, synchronize] | ||
schedule: | ||
- cron: '15 3 * * 0' | ||
|
||
jobs: | ||
build: | ||
name: Test and Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
|
||
- name: Fetch vendor | ||
run: go mod vendor | ||
|
||
- name: Test and build | ||
run: go run github.com/rebuy-de/rebuy-go-sdk/v5/cmd/buildutil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Release Docker image | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Release Binaries | ||
|
||
on: | ||
release: | ||
types: [created] | ||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
build: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '1.20' | ||
|
||
- name: Fetch vendor | ||
run: go mod vendor | ||
|
||
- name: Test and build | ||
run: | | ||
go run github.com/rebuy-de/rebuy-go-sdk/v5/cmd/buildutil \ | ||
--compress \ | ||
-x linux/amd64 \ | ||
-x linux/arm64 \ | ||
-x darwin/arm64 | ||
# The symlinks cause duplicate files on the GitHub releases page. Perhaps | ||
# we should fix this in buildutil. | ||
- name: Clean dist directory | ||
run: | | ||
cd dist && rm $(find . -type l) | ||
- name: Upload binaries to release | ||
uses: svenstaro/upload-release-action@v2 | ||
with: | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file: dist/devilctl-*.tar.gz | ||
tag: ${{ github.ref }} | ||
overwrite: true | ||
file_glob: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/vendor | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM golang:1.20-alpine as builder | ||
|
||
RUN apk add --no-cache git openssl | ||
|
||
COPY . /build | ||
RUN cd /build && ./buildutil | ||
|
||
FROM alpine:latest | ||
|
||
RUN apk add --no-cache ca-certificates tzdata && \ | ||
cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime && \ | ||
echo "Europe/Berlin" > /etc/timezone && \ | ||
apk del tzdata | ||
|
||
COPY --from=builder /build/dist/devilctl /usr/local/bin/ | ||
|
||
RUN adduser -D devilctl | ||
USER devilctl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Sven Walter | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# i3blocks-mqtt | ||
|
||
Command for templating message for MQTT to use in [i3blocks](https://github.com/vivien/i3blocks). | ||
|
||
> **Development Status:** Currently, I am only using this myself. | ||
> This project is open source, but not open for contribution, since helping contributors to ship a PR usually takes more time than doing it myself. Please drop an issue, if you want something changed. Also of course it is possible to fork the whole project. | ||
## Example | ||
|
||
``` | ||
[temperature-inside] | ||
label=In: | ||
interval=persist | ||
format=json | ||
command=i3block-mqtt subscribe | ||
BLOCKS_BROKER=mqtt://localhost:1883 | ||
BLOCKS_TOPIC=wadra/dashboard/temperature/wohnzimmer | ||
BLOCKS_JSON=true | ||
BLOCKS_TEMPLATE_FULL={{. | printf "%.1f"}}°C | ||
BLOCKS_TEMPLATE_COLOR={{if gt . 24.}}#cc0000{{end}}{{if lt . .20}}#73d216{{end}} | ||
``` | ||
|
||
Prints lines like this to stdout: | ||
|
||
``` | ||
{"full_text":"27.6°C","color":"#cc0000"} | ||
``` | ||
|
||
Which show `In:27.6°C` in a red color in the i3 bar. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env sh | ||
set -eu | ||
go mod vendor | ||
go generate ./... | ||
exec go run github.com/rebuy-de/rebuy-go-sdk/v5/cmd/buildutil "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
func AutoEnv(cmd *cobra.Command, args []string) { | ||
cmd.PersistentFlags().VisitAll(func(flag *pflag.Flag) { | ||
if !flag.Changed { | ||
var ( | ||
envName = "BLOCKS_" + ConvertToValidEnvVarName(flag.Name) | ||
envValue = os.Getenv(envName) | ||
) | ||
|
||
if envValue == "" { | ||
return | ||
} | ||
|
||
flag.Value.Set(envValue) | ||
} | ||
}) | ||
} | ||
|
||
func ConvertToValidEnvVarName(s string) string { | ||
// Remove non-alphanumeric characters and replace them with underscores | ||
re := regexp.MustCompile(`[^a-zA-Z0-9]+`) | ||
s = re.ReplaceAllString(s, "_") | ||
|
||
// Remove leading and trailing underscores | ||
s = strings.Trim(s, "_") | ||
|
||
// Convert to uppercase | ||
s = strings.ToUpper(s) | ||
|
||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/rebuy-de/rebuy-go-sdk/v5/pkg/cmdutil" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type RunnerFunc func(ctx context.Context) error | ||
|
||
func (r RunnerFunc) Bind(cmd *cobra.Command) error { | ||
return nil | ||
} | ||
|
||
func (r RunnerFunc) Run(ctx context.Context) error { | ||
return r(ctx) | ||
} | ||
|
||
func NewRootCommand() *cobra.Command { | ||
return cmdutil.New( | ||
"i3blocks-mqtt", "Tools for adding MQTT support to i3blocks", | ||
cmdutil.WithLogVerboseFlag(), | ||
cmdutil.WithVersionCommand(), | ||
|
||
cmdutil.WithSubCommand(cmdutil.New( | ||
"subscribe", "Subscribes to a single topic and output the data to stdout", | ||
cmdutil.WithRunner(new(SubscribeRunner)), | ||
)), | ||
) | ||
} |
Oops, something went wrong.