Skip to content

Commit

Permalink
modernized phase 1
Browse files Browse the repository at this point in the history
* Moved to go 1.12
* Moved to goreleaser
* Moved to github actions
* Formatted code
* Vetted code with golangci
* Moved to taskfile
* Removed io/ioutil
  • Loading branch information
retr0h committed Nov 9, 2023
1 parent f73826b commit d07b1c0
Show file tree
Hide file tree
Showing 29 changed files with 375 additions and 167 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Cleanup

on:
pull_request:
types: [closed]

jobs:
delete-branch:
runs-on: ubuntu-latest
steps:
- name: delete branch
uses: SvanBoxel/delete-merged-branch@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Go

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Install Task
uses: arduino/setup-task@v1
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Test
run: task test
21 changes: 21 additions & 0 deletions .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Greetings

on: [pull_request, issues]

jobs:
greeting:
runs-on: ubuntu-latest
steps:
- uses: actions/first-interaction@v1
if: env.month != 'Oct'
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: 'Thank you for your first issue! 😊🕹️'
pr-message: 'Thank you for contributing to this project! 😊🕹️'
- uses: actions/first-interaction@v1
if: env.month == 'Oct'
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: 'Thank you for your first issue! Happy Hacktoberfest!!! 🎃👕🕹️'
pr-message: 'Thank you for contributing to this project. Happy Hacktoberfest!!! 🎃👕🕹️'
18 changes: 18 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Mark stale issues and pull requests

on:
schedule:
- cron: "30 1 * * *"

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Stale issue message'
stale-pr-message: 'Stale pull request message'
stale-issue-label: 'no-issue-activity'
stale-pr-label: 'no-pr-activity'
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.build/
coverage*
test/integration/tmp/
cobertura.xml
cover.out
result.xml
30 changes: 30 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Refer to golangci-lint's example config file for more options and information:
# https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml

run:
timeout: 5m
modules-download-mode: readonly
skip-dirs:
- .asdf

linters:
enable:
- errcheck
- errname
- goimports
- govet
- prealloc
- predeclared
- revive
- staticcheck

linters-settings:
revive:
rules:
- name: package-comments
disabled: true

issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
26 changes: 26 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
ldflags:
- -s -w -X {{ .ModulePath }}/cmd.date={{ .CommitDate }}
- -X {{ .ModulePath }}/cmd.commit={{ .Commit }}
- -X {{ .ModulePath }}/cmd.version={{ .Version }}
archives:
- format: binary
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

68 changes: 0 additions & 68 deletions Makefile

This file was deleted.

31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Coveralls github](https://img.shields.io/coveralls/github/retr0h/go-gilt.svg?style=flat-square)](https://coveralls.io/github/retr0h/go-gilt)
[![Go Report Card](https://goreportcard.com/badge/github.com/retr0h/go-gilt?style=flat-square)](https://goreportcard.com/report/github.com/retr0h/go-gilt)

# go-gilt
# Gilt

Gilt is a tool which aims to make repo management, manageable. Gilt
clones repositories at a particular version, then overlays the repository to
Expand All @@ -11,18 +11,15 @@ the provided destination. An alternate approach to "vendoring".
What makes Gilt interesting, is the ability to overlay particular files and/or
directories from the specified repository to given destinations. This is quite
helpful for those using Ansible, since libraries, plugins, and playbooks are
often shared, but Ansible's [Galaxy][1] has no mechanism to handle this.

[1]: https://docs.ansible.com/ansible/latest/reference_appendices/galaxy.html
often shared, but Ansible's [Galaxy][] has no mechanism to handle this.

## Port

This project is a port of [Gilt](http:https://gilt.readthedocs.io/en/latest/), it is
This project is a port of [Gilt][], it is
not 100% compatible with the python version, and aims to correct some poor decisions
made in the python version of Gilt.

This version of Gilt does not provide built in locking, unlike our python friend. If one
wishes to use locking, [flock(1)](https://linux.die.net/man/1/flock) should be used.
This version of Gilt does not provide built in locking, unlike our python friend.

## Installation

Expand Down Expand Up @@ -100,10 +97,22 @@ $ tree .build/

## Testing

```bash
$ make test
```
To execute tests:

$ task test

Auto format code:

$ task fmt

List helpful targets:

$ task

## License

MIT
The [MIT][] License.

[Galaxy]: https://docs.ansible.com/ansible/latest/reference_appendices/galaxy.html
[Gilt]: http:https://gilt.readthedocs.io/en/latest/
[MIT]: LICENSE
92 changes: 92 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
version: "3"

vars:
GIT_ROOT:
sh: git rev-parse --show-toplevel
MAIN_PACKAGE: main.go

tasks:
deps:
desc: Install dependencies
cmds:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2
- go install github.com/princjef/gomarkdoc/cmd/[email protected]
- go install golang.org/x/vuln/cmd/[email protected]
- go install github.com/jstemmer/[email protected]
- go install github.com/segmentio/[email protected]
- go install github.com/golang/mock/[email protected]
- go install github.com/boumenot/[email protected]
- go install mvdan.cc/gofumpt@fd93f1d8818fc86a956b9706ad8b81734c81cc1e
- go install github.com/goreleaser/goreleaser@latest

mod:
desc: Module maintenance
cmds:
- go mod download
- go mod tidy

vet:
desc: Report likely mistakes in packages
cmds:
- $(go env GOPATH)/bin/golangci-lint run --config {{ .GIT_ROOT }}/.golangci.yml

vuln:
desc: Run Go's vulnerability scanner
cmds:
- govulncheck ./...

run:
desc: Compile and run Go program
cmds:
- go run {{ .MAIN_PACKAGE }} {{.CLI_ARGS}}

unit:
desc: Test packages
cmds:
- go test -parallel 5 -race -v ./...

unit:int:
desc: Integration test packages
cmds:
- go test -tags=integration -parallel 5 -race -v ./...

test:
desc: Test all
cmds:
- task: deps
- task: mod
- task: fmt:check
- task: vet
- task: cov
- task: unit:int

cov:
desc: Generate coverage
cmds:
- go test -race -coverprofile cover.out -v 2>&1 ./... | go-junit-report --set-exit-code > result.xml || (cat result.xml && echo "fail" && exit 1)
- $(go env GOPATH)/bin/gocover-cobertura < cover.out > cobertura.xml

covmap:
desc: Generate coverage and show heatmap
cmds:
- task: cov
- go tool cover -html=cover.out

fmt:
desc: Reformat files whose formatting differs from `go_fmt_command`
cmds:
- gofumpt -l -w .
- golines --base-formatter=gofumpt -w .

fmt:check:
desc: Check files whose formatting differs from `go_fmt_command`
cmds:
# https://github.com/mvdan/gofumpt/issues/114
- test -z "$(gofumpt -d -e . | tee /dev/stderr)"
- test -z "$(golines -l --dry-run --base-formatter=gofumpt -w .)"

build:
desc: Build ARCH compatible binary.
cmds:
- goreleaser release --snapshot --clean
Loading

0 comments on commit d07b1c0

Please sign in to comment.