Skip to content

Commit

Permalink
Multiple changes:
Browse files Browse the repository at this point in the history
- Rewrite CI from Travis to GHA
- Bump Go version
- Add linting
- Minor refactoring
- Upgrade deps
  • Loading branch information
pomo-mondreganto committed Nov 7, 2023
1 parent d941c16 commit c178fe9
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 36 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: release
on:
push:
tags:
- '*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

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

- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- id: repo_name
uses: ASzc/change-string-case-action@v5
with:
string: ${{ github.repository_owner }}

- name: Build and push image
uses: docker/build-push-action@v4
with:
context: .
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: 'linux/amd64,linux/arm64'
tags: |
ghcr.io/${{ steps.repo_name.outputs.lowercase }}/dedcleaner:latest
ghcr.io/${{ steps.repo_name.outputs.lowercase }}/dedcleaner:${{ steps.get_version.outputs.VERSION }}
21 changes: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: tests
on:
- push
- pull_request
jobs:
code:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

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

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --config .golangci.yml
55 changes: 55 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
run:
timeout: 5m
tests: true

linters:
enable:
- asciicheck
- bodyclose
- dogsled
- durationcheck
- errname
- errorlint
- exhaustive
- exportloopref
- gocritic
- gofmt
- goimports
- gomoddirectives
- gosimple
- govet
- ineffassign
- importas
- misspell
- noctx
- prealloc
- predeclared
- revive
- staticcheck
- thelper
- tparallel
- unconvert
- unparam
- unused
- whitespace
- wrapcheck

linters-settings:
unparam:
check-exported: false
wrapcheck:
ignoreSigs:
- (context.Context).Err()
- fmt.Errorf(
- errors.New(

issues:
exclude-use-default: false
max-same-issues: 0
exclude-rules:
- linters:
- revive
text: "package-comments:"
- linters:
- revive
text: "exported:"
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

16 changes: 10 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
FROM golang:alpine AS builder
FROM golang:1.21-alpine AS builder

RUN apk update && apk add --no-cache git upx
RUN apk update && \
apk add --no-cache upx

WORKDIR /app
COPY ./go.mod /app/go.mod
COPY ./go.sum /app/go.sum
RUN go mod download
COPY . /app
RUN go build -o /app/dedcleaner

RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
go build \
-ldflags="-s -w" \
-o /app/dedcleaner
RUN upx --best --ultra-brute /app/dedcleaner

FROM scratch

COPY --from=builder /app/dedcleaner /dedcleaner

CMD ["/dedcleaner"]
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: lint
lint:
golangci-lint run -v --config .golangci.yml
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ For example, if you have a directory structure like:
```
/tmp
├── keks
│   └── asd
└── asd
└── uploads
└── kekus
└── kek
```

and `DIRS=/tmp/uploads/**/*,/tmp/keks` then dedcleaner will delete all files in `/tmp/uploads/kekus/kek` and `/tmp/keks/asd` directories, resulting in the following structure:
and `DIRS=/tmp/uploads/**/*,/tmp/keks` then dedcleaner will delete all files in `/tmp/uploads/kekus/kek`
and `/tmp/keks/asd` directories, resulting in the following structure:
```
/tmp
├── keks
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module github.com/C4T-BuT-S4D/dedcleaner

go 1.15
go 1.21

require (
github.com/mattn/go-zglob v0.0.4
github.com/sirupsen/logrus v1.7.0
github.com/sirupsen/logrus v1.9.3
)

require golang.org/x/sys v0.14.0 // indirect
18 changes: 12 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/mattn/go-zglob v0.0.4 h1:LQi2iOm0/fGgu80AioIJ/1j9w9Oh+9DZ39J4VAGzHQM=
github.com/mattn/go-zglob v0.0.4/go.mod h1:MxxjyoXXnMxfIpxTK2GAkw1w8glPsQILx3N5wrKakiY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
21 changes: 13 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"log"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -62,7 +61,7 @@ func clean(dir string) error {
if err := os.Remove(entry); err != nil {
dirLog.Errorf("Failed to delete file %s", entry)
} else {
cntDeleted += 1
cntDeleted++
}
}
}
Expand Down Expand Up @@ -93,21 +92,27 @@ func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)

loop:
for {
run := func() {
for _, d := range directories {
d := strings.TrimSpace(d)
if err := clean(d); err != nil {
log.Fatalf("Failed to clean directory '%s': %v", d, err)
logrus.Fatalf("Failed to clean directory '%s': %v", d, err)
}
}
ticker := time.NewTicker(sleep)
}

ticker := time.NewTicker(sleep)
defer ticker.Stop()

run()
loop:
for {
select {
case <-ticker.C:
run()
case <-c:
logrus.Infof("Shutting down")
break loop
case <-ticker.C:
ticker.Stop()
}
}
}

0 comments on commit c178fe9

Please sign in to comment.