From cc5da3a574c00a0f05a045e1d70c5007f1d22535 Mon Sep 17 00:00:00 2001 From: Nicolas Karolak Date: Sun, 18 Aug 2024 16:14:58 +0200 Subject: [PATCH] chore: replace makefile by taskfile --- .devcontainer.json | 10 ---- .editorconfig | 17 ++++--- .githooks/commit-msg | 10 ++++ .githooks/pre-commit | 15 ++++++ .github/FUNDING.yml | 4 -- .github/dependabot.yml | 10 ++++ .github/renovate.json | 13 ------ .github/workflows/cd.yml | 57 ++++++++++++----------- .github/workflows/ci.yml | 93 +++++++++++++++++++++----------------- .gitignore | 1 + .goreleaser.yml | 1 - .pre-commit-config.yaml | 67 --------------------------- .yamlfmt.yml | 7 +++ .yamllint.yml | 4 +- Makefile | 88 ------------------------------------ Taskfile.yml | 85 ++++++++++++++++++++++++++++++++++ contrib/postinstall-deb.sh | 27 ++++++----- 17 files changed, 235 insertions(+), 274 deletions(-) delete mode 100644 .devcontainer.json create mode 100755 .githooks/commit-msg create mode 100755 .githooks/pre-commit delete mode 100644 .github/FUNDING.yml create mode 100644 .github/dependabot.yml delete mode 100644 .github/renovate.json delete mode 100644 .pre-commit-config.yaml create mode 100644 .yamlfmt.yml delete mode 100644 Makefile create mode 100644 Taskfile.yml diff --git a/.devcontainer.json b/.devcontainer.json deleted file mode 100644 index 810564f..0000000 --- a/.devcontainer.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "wirelogd", - "image": "ghcr.io/nikaro/debian-devcontainer:latest", - "features": { - "ghcr.io/nikaro/features/base": {}, - "ghcr.io/nikaro/features/actionlint": {}, - "ghcr.io/nikaro/features/go-devtools": {}, - "ghcr.io/nikaro/features/pre-commit": {} - } -} diff --git a/.editorconfig b/.editorconfig index 43ec4d5..3263332 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,15 +1,18 @@ +# EditorConfig is awesome: https://editorconfig.org + +# top-most EditorConfig file root = true +# Unix-style newlines with a newline ending every file [*] charset = utf-8 end_of_line = lf -indent_style = tab -indent_size = 4 +indent_style = space +indent_size = 2 insert_final_newline = true -[Dockerfile] -indent_style = space +[*.py] +indent_size = 4 -[*.{json,yml,yaml}] -indent_style = space -indent_size = 2 +[Makefile] +indent_style = tab diff --git a/.githooks/commit-msg b/.githooks/commit-msg new file mode 100755 index 0000000..234e855 --- /dev/null +++ b/.githooks/commit-msg @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +echo Running commit-msg hook + +if ! command -v cz >/dev/null 2>&1; then + echo "commitizen could not be found - please install it commiting" + exit 1 +fi + +cz check --allow-abort --commit-msg-file "$1" diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..63cf53b --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +echo Running pre-commit hook + +# Run pre-commit, this checks if we changed any files and runs the checks. +FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') +if [ -n "$FILES" ]; then + if ! task lint --yes >/dev/null 2>&1; then + echo "Error running make lint - please fix before committing" + echo "if this is a mistake you can skip the checks with 'git commit --no-verify'" + exit 1 + fi +fi + +exit 0 diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 633f656..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,4 +0,0 @@ -# These are supported funding model platforms - -github: [nikaro] -liberapay: nka diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..632e8eb --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + - package-ecosystem: gomod + directory: / + schedule: + interval: weekly diff --git a/.github/renovate.json b/.github/renovate.json deleted file mode 100644 index 5bba828..0000000 --- a/.github/renovate.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": ["github>nikaro/actions//.github/renovate_preset"], - "customManagers": [ - { - "customType": "regex", - "fileMatch": ["^.pre-commit-config\\.yaml$"], - "matchStrings": [ - "# renovate: datasource=(?[a-z-.]+?) depName=(?[^\\s]+?)(?: (?:lookupName|packageName)=(?[^\\s]+?))?(?: versioning=(?[a-z-0-9]+?))?\\s+.*:(?v?\\d+(?:\\.\\d+)*).*" - ] - } - ] -} diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 865581c..65ba6f0 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,4 +1,3 @@ ---- name: CD on: @@ -6,6 +5,9 @@ on: - cron: "0 0 * * 3" workflow_dispatch: +env: + TASK_X_REMOTE_TASKFILES: 1 + jobs: ci: name: CI @@ -15,41 +17,44 @@ jobs: release: name: Release needs: [ci] - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest permissions: contents: write steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - with: - fetch-depth: 0 + env: + BRANCH: ${{ github.head_ref || github.ref_name }} + GH_TOKEN: ${{ github.token }} + run: |- + gh repo clone ${{ github.repository }} ${{ github.workspace }} -- --branch "$BRANCH" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" - - name: Dry run - uses: commitizen-tools/commitizen-action@1f11eb222996406681d2bfa1eb3d997eca46557c # 0.21.0 - with: - github_token: ${{ github.token }} - changelog_increment_filename: _changelog.md - dry_run: true + - name: Install tools + run: | + echo "/home/linuxbrew/.linuxbrew/bin" >> "$GITHUB_PATH" + /home/linuxbrew/.linuxbrew/bin/brew install \ + commitizen \ + go \ + go-task \ + goreleaser \ - name: Bump - if: env.PREVIOUS_REVISION != env.REVISION - uses: commitizen-tools/commitizen-action@1f11eb222996406681d2bfa1eb3d997eca46557c # 0.21.0 - with: - github_token: ${{ github.token }} - changelog_increment_filename: _changelog.md + run: |- + echo "PREVIOUS_REVISION=$(cz version --project)" >>"$GITHUB_ENV" + task go:bump --yes + echo "REVISION=$(cz version --project)" >>"$GITHUB_ENV" - - name: Setup Go + - name: Push tags if: env.PREVIOUS_REVISION != env.REVISION - uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 - with: - cache: true - check-latest: true - go-version-file: go.mod + env: + BRANCH: ${{ github.head_ref || github.ref_name }} + REMOTE_REPO: https://${{ github.actor }}:${{ github.token }}@github.com/${{ github.repository }}.git + run: git push "$REMOTE_REPO" "HEAD:${BRANCH}" --tags - - name: Run GoReleaser + - name: Release if: env.PREVIOUS_REVISION != env.REVISION - uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0 - with: - args: release --clean --release-notes _changelog.md env: + AUR_KEY: ${{ secrets.AUR_KEY }} GITHUB_TOKEN: ${{ github.token }} + run: task go:release --yes diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58e6d4b..623622b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,77 +1,88 @@ ---- name: CI on: + push: + branches: [main] pull_request: branches: [main] workflow_call: + workflow_dispatch: permissions: contents: read +env: + TASK_X_REMOTE_TASKFILES: 1 + jobs: lint: name: Lint runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - - - name: Setup Go - uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 - with: - cache: true - check-latest: true - go-version-file: go.mod - - - name: Run staticcheck - uses: dominikh/staticcheck-action@fe1dd0c3658873b46f8c9bb3291096a617310ca6 # v1.3.1 - with: - install-go: false - - - name: Run govulncheck - uses: golang/govulncheck-action@dd0578b371c987f96d1185abb54344b44352bd58 # v1.0.3 - with: - go-version-file: go.mod + env: + BRANCH: ${{ github.head_ref || github.ref_name }} + GH_TOKEN: ${{ github.token }} + run: gh repo clone ${{ github.repository }} ${{ github.workspace }} -- --depth=1 --branch "$BRANCH" - - name: Run golangci-lint - uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0 + - name: Install tools + run: | + echo "/home/linuxbrew/.linuxbrew/bin" >> "$GITHUB_PATH" + /home/linuxbrew/.linuxbrew/bin/brew install \ + actionlint \ + check-jsonschema \ + fd \ + go \ + go-task \ + golangci-lint \ + govulncheck \ + jq \ + prettier \ + shellcheck \ + staticcheck \ + shfmt \ + yamlfmt \ + yamllint \ - - name: Run pre-commit - uses: nikaro/actions/pre-commit@cecb5d4e1f07cde50d8c5738e4a1c60c4938fc9f # 1.6.10 - with: - python-version: 3.x + - name: Lint + run: task lint --yes build: name: Build runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + env: + BRANCH: ${{ github.head_ref || github.ref_name }} + GH_TOKEN: ${{ github.token }} + run: gh repo clone ${{ github.repository }} ${{ github.workspace }} -- --depth=1 --branch "$BRANCH" - - name: Setup Go - uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 - with: - cache: true - check-latest: true - go-version-file: go.mod + - name: Install tools + run: | + echo "/home/linuxbrew/.linuxbrew/bin" >> "$GITHUB_PATH" + /home/linuxbrew/.linuxbrew/bin/brew install \ + go \ + go-task \ - name: Build - run: go build -v . + run: task go:build --yes test: name: Test runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + env: + BRANCH: ${{ github.head_ref || github.ref_name }} + GH_TOKEN: ${{ github.token }} + run: gh repo clone ${{ github.repository }} ${{ github.workspace }} -- --depth=1 --branch "$BRANCH" - - name: Setup Go - uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 - with: - cache: true - check-latest: true - go-version-file: go.mod + - name: Install tools + run: | + echo "/home/linuxbrew/.linuxbrew/bin" >> "$GITHUB_PATH" + /home/linuxbrew/.linuxbrew/bin/brew install \ + go \ + go-task \ - name: Test - run: go test -v ./... + run: task go:test --yes diff --git a/.gitignore b/.gitignore index 3997b6a..c19c826 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ config.toml # Artifacts _changelog.md +.task/ diff --git a/.goreleaser.yml b/.goreleaser.yml index 6882cce..dc98f51 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,5 +1,4 @@ # yaml-language-server: $schema=https://goreleaser.com/static/schema.json ---- version: 2 builds: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 1368181..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,67 +0,0 @@ ---- -default_install_hook_types: [pre-commit, commit-msg] - -repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 - hooks: - - id: check-added-large-files - - id: check-case-conflict - - id: check-json - - id: check-merge-conflict - - id: check-symlinks - - id: check-toml - - id: check-vcs-permalinks - - id: check-xml - - id: check-yaml - - id: destroyed-symlinks - - id: detect-private-key - - id: end-of-file-fixer - - id: forbid-new-submodules - - id: forbid-submodules - - id: mixed-line-ending - - id: trailing-whitespace - - - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.29.1 - hooks: - - id: check-github-actions - - id: check-github-workflows - - id: check-renovate - - - repo: https://github.com/adrienverge/yamllint - rev: v1.35.1 - hooks: - - id: yamllint - - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.1.0 - hooks: - - id: prettier - types_or: - - json - - yaml - - - repo: local - hooks: - - id: make-format - name: make format - language: system - types: [go] - entry: make format - - id: make-lint - name: make lint - language: system - types: [go] - entry: make lint - - - repo: https://github.com/golangci/golangci-lint - rev: v1.59.1 - hooks: - - id: golangci-lint-config-verify - - id: golangci-lint-full - - - repo: https://github.com/commitizen-tools/commitizen - rev: v3.29.0 - hooks: - - id: commitizen diff --git a/.yamlfmt.yml b/.yamlfmt.yml new file mode 100644 index 0000000..322784d --- /dev/null +++ b/.yamlfmt.yml @@ -0,0 +1,7 @@ +gitignore_excludes: true +formatter: + eof_newline: true + pad_line_comments: 2 + retain_line_breaks_single: true + scan_folded_as_literal: true + trim_trailing_whitespace: true diff --git a/.yamllint.yml b/.yamllint.yml index 526bf7a..40ef49e 100644 --- a/.yamllint.yml +++ b/.yamllint.yml @@ -1,9 +1,7 @@ ---- extends: default rules: - comments: - min-spaces-from-content: 1 + document-start: disable line-length: disable truthy: check-keys: false diff --git a/Makefile b/Makefile deleted file mode 100644 index f806e6d..0000000 --- a/Makefile +++ /dev/null @@ -1,88 +0,0 @@ -APP=wirelogd -PREFIX?=/usr/local -_INSTDIR=${DESTDIR}${PREFIX} -BINDIR?=${_INSTDIR}/bin -SHAREDIR?=${_INSTDIR}/share/${APP} -MANDIR?=${_INSTDIR}/share/man - -GOOS?=$(shell go env GOOS) -GOARCH?=$(shell go env GOARCH) -VERSION = $(shell git describe --always --dirty) - -.PHONY: all -all: build - -.PHONY: setup -## setup: Setup go modules -setup: - go get -u all - go mod tidy - -.PHONY: build -## build: Build for the current target -build: - @echo "Building..." - env CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -ldflags="-s -w -X 'main.version=${VERSION}'" -o build/${APP}-${GOOS}-${GOARCH} . - -.PHONY: install -## install: Install the application -install: - @echo "Installing..." - install -Dm755 build/${APP}-${GOOS}-${GOARCH} ${BINDIR}/${APP} - install -Dm644 man/${APP}.1 ${MANDIR}/man1/${APP}.1 - install -Dm644 contrib/config.json ${SHAREDIR}/config.json - install -Dm644 contrib/${APP}.service ${SHAREDIR}/${APP}.service - sed -i'' -e 's,/usr,${PREFIX},g' ${SHAREDIR}/${APP}.service - -.PHONY: uninstall -## uninstall: Uninstall the application -uninstall: - @echo "Uninstalling..." - rm -f ${BINDIR}/${APP} - rm -f ${MANDIR}/man1/${APP}.1 - rm -f ${SHAREDIR}/* - rmdir --ignore-fail-on-non-empty ${BINDIR} - rmdir --ignore-fail-on-non-empty ${SHAREDIR} - rmdir --ignore-fail-on-non-empty ${MANDIR}/man1 - rmdir --ignore-fail-on-non-empty ${MANDIR} - -.PHONY: lint -## lint: Run linters -lint: - @echo "Linting..." - go vet ./... - go fix ./... - staticcheck ./... - govulncheck ./... - golangci-lint run - - -.PHONY: format -## format: Runs goimports on the project -format: - @echo "Formatting..." - go fmt ./... - -.PHONY: test -## test: Runs go test -test: - @echo "Testing..." - go test ./... - -.PHONY: run -## run: Runs go run -run: - go run -race ${APP}.go - -.PHONY: clean -## clean: Cleans the binary -clean: - @echo "Cleaning..." - rm -rf build/ - rm -rf dist/ - -.PHONY: help -## help: Print this help message -help: - @echo -e "Usage: \n" - @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..5961a73 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,85 @@ +version: '3' + +set: [errexit, nounset, pipefail] +shopt: [globstar] + +includes: + lint: + taskfile: https://github.com/nikaro/meta/raw/main/taskfiles/lint.yml + internal: true + format: + taskfile: https://github.com/nikaro/meta/raw/main/taskfiles/format.yml + internal: true + go: + taskfile: https://github.com/nikaro/meta/raw/go-tasks/taskfiles/go.yml + vars: + BUILD_TARGETS: + - linux/amd64 + - linux/arm64 + - darwin/amd64 + - darwin/arm64 + +env: + APP: wirelogd + PREFIX: + sh: echo ${PREFIX:-/usr/local} + BINDIR: + sh: echo ${BINDIR:-${PREFIX:-/usr/local}/bin} + MANDIR: + sh: echo ${MANDIR:-${PREFIX:-/usr/local}/share/man} + SHAREDIR: + sh: echo ${SHAREDIR:-${PREFIX:-/usr/local}/share/${APP:-wirelogd}} + +tasks: + init: + desc: Initialize repositry + cmds: + - git config core.hooksPath .githooks + - git config commit.template .gitmessage + + lint: + desc: Run linters + cmds: + - task: lint:default + - task: go:lint + + format: + desc: Run formatters + cmds: + - task: format:default + - task: go:format + + bump: + desc: Bump version + preconditions: + - cz --no-raise 21 bump --dry-run --changelog --changelog-to-stdout > ./_changelog.md + cmd: cz --no-raise 21 bump --changelog --changelog-to-stdout > ./_changelog.md + + release: + desc: Publish release + preconditions: + - test -n "$GITHUB_TOKEN" + cmds: + - goreleaser release --clean --release-notes ./_changelog.md + - defer: rm -rf _changelog.md + + install: + desc: Install the application + deps: ['go:build'] + cmds: + - install -Dm755 ./build/${APP}-${GOOS}-${GOARCH} ${BINDIR}/${APP} + - install -Dm644 ./man/${APP}.1 ${MANDIR}/man1/${APP}.1 + - install -Dm644 ./contrib/config.json ${SHAREDIR}/config.json + - install -Dm644 ./contrib/${APP}.service ${SHAREDIR}/${APP}.service + - sed -i'' -e 's|/usr|${PREFIX}|g' ${SHAREDIR}/${APP}.service + + uninstall: + desc: Uninstall the application + cmds: + - rm -rf ${BINDIR}/${APP} + - rm -f ${MANDIR}/man1/${APP}.1 + - rm -f ${SHAREDIR}/* + - rmdir --ignore-fail-on-non-empty ${BINDIR} + - rmdir --ignore-fail-on-non-empty ${SHAREDIR} + - rmdir --ignore-fail-on-non-empty ${MANDIR}/man1 + - rmdir --ignore-fail-on-non-empty ${MANDIR} diff --git a/contrib/postinstall-deb.sh b/contrib/postinstall-deb.sh index 9f7e8cf..6569155 100644 --- a/contrib/postinstall-deb.sh +++ b/contrib/postinstall-deb.sh @@ -2,18 +2,17 @@ set -e case "$1" in - configure) - systemctl daemon-reload - if [ -z "$2" ]; then - if ! getent passwd wirelogd >>/dev/null 2>&1 ; then - useradd --home-dir /var/run/wirelogd --shell /usr/sbin/nologin --system --user-group wirelogd - if command -v setfacl >>/dev/null 2>&1 ; then - setfacl -m u:wirelogd:rX,g:wirelogd:rX /etc/wireguard - fi - fi - systemctl enable --now wirelogd.service - fi - ;; - *) - ;; +configure) + systemctl daemon-reload + if [ -z "$2" ]; then + if ! getent passwd wirelogd >>/dev/null 2>&1; then + useradd --home-dir /var/run/wirelogd --shell /usr/sbin/nologin --system --user-group wirelogd + if command -v setfacl >>/dev/null 2>&1; then + setfacl -m u:wirelogd:rX,g:wirelogd:rX /etc/wireguard + fi + fi + systemctl enable --now wirelogd.service + fi + ;; +*) ;; esac