Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
madhuravius committed Jul 17, 2022
0 parents commit fde25a0
Show file tree
Hide file tree
Showing 32 changed files with 761 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .clingy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
label: clingy flow
steps:
- label: start
description: starting clingy flow
command: echo -e "\033[34mStarting\033[0m"
- label: build clingy
description: building clingy with Makefile target
command: make build
- label: clingy init
description: displaying printout of only calling clingy
command: build/clingy -d
- label: clingy help
description: display help text for clingy
command: build/clingy --help -d
- label: finish
description: finished clingy flow
command: echo -e "\033[92mComplete\033[0m"
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.github
.idea
*.iml
build
images
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@madhuravius
20 changes: 20 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
labels:
- dependencies
- actions
- Skip Changelog
schedule:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /
labels:
- dependencies
- go
- Skip Changelog
schedule:
interval: weekly
day: sunday
15 changes: 15 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Lint

on:
push:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '>=1.18.0'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
26 changes: 26 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Go Releaser
# Source: https://github.com/tchupp/actions-update-semver-tags

on:
release:
types:
- published

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v3
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
if: startsWith(github.ref, 'refs/tags/')
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/semver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Semantic Versioning of Tags
# Source: https://github.com/tchupp/actions-update-semver-tags

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
release:
types:
- published

jobs:
update-semver-tags:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Update Previous Tags
shell: bash
run: |
release_sha="${GITHUB_SHA}"
git_ref="${GITHUB_REF}"
git_ref_type=$(echo "${git_ref}" | cut -d '/' -f 2)
if [[ "${git_ref_type}" != "tags" ]]; then
echo "Action should only run for 'tags' refs, was: '${git_ref}'"
exit 0
fi
git_ref=$(echo "${git_ref}" | cut -d '/' -f 3-)
match="v[0-9]+.[0-9]+.[0-9]+"
if ! [[ "${git_ref}" =~ $match ]]; then
echo "Action should only run for tags that match the regex '$match', was: '${git_ref}'"
exit 0
fi
prefix=$(echo "${git_ref}" | sed -E 's/([^0-9]*)([0-9]*)\.([0-9]*)\.([0-9]*)/\1/')
major=$(echo "${git_ref}" | sed -E 's/([^0-9]*)([0-9]*)\.([0-9]*)\.([0-9]*)/\2/')
minor=$(echo "${git_ref}" | sed -E 's/([^0-9]*)([0-9]*)\.([0-9]*)\.([0-9]*)/\3/')
patch=$(echo "${git_ref}" | sed -E 's/([^0-9]*)([0-9]*)\.([0-9]*)\.([0-9]*)/\4/')
git tag -f "${prefix}${major}" "${release_sha}"
git tag -f "${prefix}${major}.${minor}" "${release_sha}"
git push --tags -f
14 changes: 14 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Test

on:
push:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '>=1.18.0'
- run: go test ./...
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

.idea
*.iml

output/*
!output/.gitkeep

build/*
!build/.gitkeep
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 1 - generate a new binary for use
FROM golang:1-bullseye as build
RUN apt-get update && \
apt-get install wget
RUN wget https://github.com/ImageMagick/ImageMagick/releases/download/7.1.0.43/ImageMagick--gcc-x86_64.AppImage && \
mv ImageMagick--gcc-x86_64.AppImage magick &&\
chmod +x magick && \
mv magick /usr/bin/
RUN mkdir /opt/app
WORKDIR /opt/app
COPY . .
RUN make build

# 2 - use the newly built image
FROM debian:bullseye
RUN apt-get update && \
apt-get install -qqy x11-apps && \
rm -rf /var/lib/apt/lists/*
ENV DISPLAY :0
COPY --from=build /usr/bin/magick /usr/bin
COPY --from=build /opt/app/build/clingy /usr/bin
RUN groupadd --gid 1001 clingy && \
useradd --uid 1001 --gid 1001 -m clingy && \
usermod -a -G users clingy && \
chown -R clingy /home/clingy
USER clingy
RUN mkdir /home/clingy/images
WORKDIR /home/clingy
ENTRYPOINT ["/usr/local/bin/clingy"]
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Copyright 2022 Madhusudan Ravi

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.

Taken from: https://opensource.org/licenses/MIT
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
init:
go mod download
.PHONY: init

build:
go build -o build/clingy
.PHONY: build

start:
go run main.go
.PHONY: start

clean:
rm build/clingy
.PHONY: clean

lint:
docker run \
--rm \
-v $(shell pwd):/app \
-w /app \
golangci/golangci-lint:v1.46 \
golangci-lint run
.PHONY: lint

test: lint
go test ./...
.PHONY: test

pretty:
go fmt ./...
.PHONY: pretty

release:
@echo "don't forget to create and push a git tag! e.g."
@echo " git tag -a v0.1.0 -m 'First release'"
@echo " git push origin v0.1.0"
@sleep 3
goreleaser release
.PHONY: release

build-docker:
docker build -t clingy .

run-docker: build-docker
# See readme on usage
xhost local:root
docker run \
-e DISPLAY=${DISPLAY} \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v ${PWD}/.clingy.yaml:/home/clingy/.clingy.yaml \
clingy
.PHONY: build-docker run-docker
Empty file added build/.gitkeep
Empty file.
35 changes: 35 additions & 0 deletions cmd/clean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cmd

import (
"io/ioutil"
"os"
"path"

"github.com/spf13/cobra"
)

// cleanCmd - clean temporary paths
var cleanCmd = &cobra.Command{
Use: "clean",
Short: "Clean clingy",
PreRun: initRunWithoutArtifactDirectoryCreate,
Run: func(cmd *cobra.Command, args []string) {
logger.Println("Cleaning clingy generated files")

subPaths, err := ioutil.ReadDir(getOutputPath())
if err != nil {
logger.Println("Unable to read build directory for cleaning", err)
os.Exit(1)
}
for _, subPath := range subPaths {
if subPath.Name() == ".gitkeep" {
continue
}
err := os.RemoveAll(path.Join([]string{getOutputPath(), subPath.Name()}...))
if err != nil {
logger.Println("Unable to clean up normal build path", err)
os.Exit(1)
}
}
},
}
18 changes: 18 additions & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/spf13/cobra"
)

// initCmd - inits a .clingy.yaml for use in the current path
var initCmd = &cobra.Command{
Use: "init",
Short: "instantiate a .clingy.yaml for use in the cwd",
PreRun: initRunWithoutArtifactDirectoryCreate,
Run: func(cmd *cobra.Command, args []string) {
// check current path to determine if needing to write file

// if it doesn't exist, go ahead and write the default template

},
}
Loading

0 comments on commit fde25a0

Please sign in to comment.