-
-
Notifications
You must be signed in to change notification settings - Fork 3
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 34494f0
Showing
27 changed files
with
1,683 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 @@ | ||
github: l3uddz |
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 @@ | ||
name: prune_artifacts | ||
on: | ||
schedule: | ||
# Every 4 hours | ||
- cron: '0 */4 * * *' | ||
|
||
jobs: | ||
remove-old-artifacts: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
|
||
steps: | ||
- name: Remove old artifacts | ||
uses: c-hive/gha-remove-artifacts@v1 | ||
with: | ||
age: '1 hour' | ||
skip-tags: true | ||
skip-recent: 1 |
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,80 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- '*' | ||
tags: | ||
- 'v*' | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- edited | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# checkout | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
# setup go | ||
- name: go | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.14 | ||
- run: go version | ||
- run: go env | ||
|
||
# cache | ||
- name: cache | ||
uses: actions/cache@v1 | ||
with: | ||
path: vendor | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
# vendor | ||
- name: vendor | ||
run: | | ||
make vendor | ||
# build | ||
- name: build | ||
if: startsWith(github.ref, 'refs/tags/') == false | ||
run: | | ||
make snapshot | ||
# get tag name | ||
- name: tag_name | ||
if: startsWith(github.ref, 'refs/tags/') | ||
uses: olegtarasov/get-tag@v2 | ||
with: | ||
tagRegex: "v?(.+)" | ||
|
||
# publish | ||
- name: publish | ||
if: startsWith(github.ref, 'refs/tags/') | ||
env: | ||
TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITHUB_REF: ${{ github.ref }} | ||
run: | | ||
make publish | ||
# artifacts | ||
- name: artifact_linux | ||
uses: actions/upload-artifact@v2-preview | ||
with: | ||
name: build_linux | ||
path: dist/*linux* | ||
|
||
- name: artifact_darwin | ||
uses: actions/upload-artifact@v2-preview | ||
with: | ||
name: build_darwin | ||
path: dist/*darwin* |
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,14 @@ | ||
name: golangci-lint | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v1 | ||
with: | ||
version: v1.27 |
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,7 @@ | ||
.DS_Store | ||
.idea/ | ||
vendor/ | ||
dist/ | ||
|
||
*.db | ||
*.log |
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,22 @@ | ||
run: | ||
timeout: 10m | ||
|
||
linters: | ||
enable: | ||
- bodyclose | ||
# - goimports | ||
- unconvert | ||
# - unparam | ||
- scopelint | ||
- dupl | ||
- interfacer | ||
- stylecheck | ||
|
||
issues: | ||
exclude-rules: | ||
- linters: | ||
- stylecheck | ||
text: "ST1003:" | ||
- linters: | ||
- scopelint | ||
text: 'Using the variable on range scope `tc` in function literal' |
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,65 @@ | ||
# https://goreleaser.com | ||
project_name: plexarr | ||
env: | ||
- GO111MODULE=on | ||
- CGO_ENABLED=1 | ||
|
||
# Build | ||
builds: | ||
- id: build_darwin | ||
env: | ||
- CC=o64-clang | ||
- CXX=o64-clang++ | ||
main: ./cmd/plexarr | ||
goos: | ||
- darwin | ||
goarch: | ||
- amd64 | ||
ldflags: | ||
- -s -w | ||
- -X "main.Version={{ .Version }}" | ||
- -X "main.GitCommit={{ .ShortCommit }}" | ||
- -X "main.Timestamp={{ .Timestamp }}" | ||
flags: | ||
- -trimpath | ||
|
||
- id: build_linux | ||
main: ./cmd/plexarr | ||
goos: | ||
- linux | ||
goarch: | ||
- amd64 | ||
ldflags: | ||
- -linkmode external | ||
- -extldflags -static | ||
- -s -w | ||
- -X "main.Version={{ .Version }}" | ||
- -X "main.GitCommit={{ .ShortCommit }}" | ||
- -X "main.Timestamp={{ .Timestamp }}" | ||
flags: | ||
- -trimpath | ||
- -tags=netgo | ||
- -v | ||
|
||
# Archive | ||
archives: | ||
- | ||
name_template: "{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}" | ||
format: "binary" | ||
|
||
# Checksum | ||
checksum: | ||
name_template: "checksums.txt" | ||
algorithm: sha512 | ||
|
||
# Snapshot | ||
snapshot: | ||
name_template: "{{ .Major }}.{{ .Minor }}.{{ .Patch }}-dev+{{ .ShortCommit }}" | ||
|
||
# Changelog | ||
changelog: | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" | ||
- "^Merge branch" |
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,67 @@ | ||
.DEFAULT_GOAL := build | ||
CMD := plexarr | ||
TARGET := $(shell go env GOOS)_$(shell go env GOARCH) | ||
DIST_PATH := dist | ||
BUILD_PATH := ${DIST_PATH}/${CMD}_${TARGET} | ||
GO_FILES := $(shell find . -path ./vendor -prune -or -type f -name '*.go' -print) | ||
GIT_COMMIT := $(shell git rev-parse --short HEAD) | ||
TIMESTAMP := $(shell date +%s) | ||
VERSION ?= 0.0.0-dev | ||
CGO := 1 | ||
|
||
# Deps | ||
.PHONY: check_golangci | ||
check_golangci: | ||
@command -v golangci-lint >/dev/null || (echo "golangci-lint is required."; exit 1) | ||
|
||
.PHONY: lint | ||
lint: check_golangci ## Run linting | ||
@echo "*** golangci-lint ***" | ||
golangci-lint run | ||
|
||
.PHONY: vendor | ||
vendor: ## Vendor files and tidy go.mod | ||
go mod vendor | ||
go mod tidy | ||
|
||
.PHONY: vendor_update | ||
vendor_update: ## Update vendor dependencies | ||
go get -u ./... | ||
${MAKE} vendor | ||
|
||
.PHONY: build | ||
build: vendor ${BUILD_PATH}/${CMD} ## Build application | ||
|
||
# Binary | ||
${BUILD_PATH}/${CMD}: ${GO_FILES} go.sum | ||
@echo "Building for ${TARGET}..." && \ | ||
mkdir -p ${BUILD_PATH} && \ | ||
CGO_ENABLED=${CGO} go build \ | ||
-mod vendor \ | ||
-trimpath \ | ||
-ldflags "-s -w -X main.Version=${VERSION} -X main.GitCommit=${GIT_COMMIT} -X main.Timestamp=${TIMESTAMP}" \ | ||
-o ${BUILD_PATH}/${CMD} \ | ||
./cmd/plexarr | ||
|
||
.PHONY: publish | ||
publish: ## Generate a release, and publish | ||
docker run --rm --privileged \ | ||
-e GITHUB_TOKEN="${TOKEN}" \ | ||
-e VERSION="${GIT_TAG_NAME}" \ | ||
-e GIT_COMMIT="${GIT_COMMIT}" \ | ||
-e TIMESTAMP="${TIMESTAMP}" \ | ||
-v `pwd`:/go/src/github.com/l3uddz/plexarr \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
-w /go/src/github.com/l3uddz/plexarr \ | ||
neilotoole/xcgo:latest goreleaser --rm-dist | ||
|
||
.PHONY: snapshot | ||
snapshot: ## Generate a snapshot release | ||
docker run --rm --privileged \ | ||
-e VERSION="${VERSION}" \ | ||
-e GIT_COMMIT="${GIT_COMMIT}" \ | ||
-e TIMESTAMP="${TIMESTAMP}" \ | ||
-v `pwd`:/go/src/github.com/l3uddz/plexarr \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
-w /go/src/github.com/l3uddz/plexarr \ | ||
neilotoole/xcgo:latest goreleaser --snapshot --skip-validate --skip-publish --rm-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 @@ | ||
# plexarr |
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,44 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/kirsle/configdir" | ||
"golang.org/x/sys/unix" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func defaultConfigPath() string { | ||
// get binary path | ||
bp := getBinaryPath() | ||
if dirIsWriteable(bp) == nil { | ||
return bp | ||
} | ||
|
||
// binary path is not write-able, use alternative path | ||
cp := configdir.LocalConfig("plexarr") | ||
if _, err := os.Stat(cp); os.IsNotExist(err) { | ||
if e := os.MkdirAll(cp, os.ModePerm); e != nil { | ||
panic("failed to create plexarr config directory") | ||
} | ||
} | ||
|
||
return cp | ||
} | ||
|
||
func getBinaryPath() string { | ||
// get current binary path | ||
dir, err := filepath.Abs(filepath.Dir(os.Args[0])) | ||
if err != nil { | ||
// get current working dir | ||
if dir, err = os.Getwd(); err != nil { | ||
panic("failed to determine current binary location") | ||
} | ||
} | ||
|
||
return dir | ||
} | ||
|
||
func dirIsWriteable(dir string) error { | ||
// credits: https://stackoverflow.com/questions/20026320/how-to-tell-if-folder-exists-and-is-writable | ||
return unix.Access(dir, unix.W_OK) | ||
} |
Oops, something went wrong.