Skip to content

Commit

Permalink
第二次重构 (#43)
Browse files Browse the repository at this point in the history
* refactor: switch to errgroup

Signed-off-by: Jian Zeng <[email protected]>

* chore: update deps

Signed-off-by: Jian Zeng <[email protected]>

* checkpoint

Signed-off-by: Jian Zeng <[email protected]>

* feat: update presubmit check workflow

Signed-off-by: Jian Zeng <[email protected]>

* test: fix test

Signed-off-by: Jian Zeng <[email protected]>

* chore: update deps

Signed-off-by: Jian Zeng <[email protected]>

* feat: impl repo meta endpoints

Signed-off-by: Jian Zeng <[email protected]>

* refactor: remove homebred validator

Signed-off-by: Jian Zeng <[email protected]>

* refactor: eliminate embedded context

Signed-off-by: Jian Zeng <[email protected]>

* refactor: switch to slog & drop quit channel

Signed-off-by: Jian Zeng <[email protected]>

* chore: update deps

Signed-off-by: Jian Zeng <[email protected]>

* test: add test cases for RepoMeta handlers

Signed-off-by: Jian Zeng <[email protected]>

* feat: impl repo endpoints

Signed-off-by: Jian Zeng <[email protected]>

* refactor: simplify config loading process

Signed-off-by: Jian Zeng <[email protected]>

* wip: impl sync repo handler

Signed-off-by: Jian Zeng <[email protected]>

* checkpoint

Signed-off-by: Jian Zeng <[email protected]>

* refactor: remove unused files

Signed-off-by: Jian Zeng <[email protected]>

* style: check error

Signed-off-by: Jian Zeng <[email protected]>

* chore: update deps

Signed-off-by: Jian Zeng <[email protected]>

* chore: update deps

Signed-off-by: Jian Zeng <[email protected]>

* refactor: override the path to config file

Signed-off-by: Jian Zeng <[email protected]>

* test: update fixtures

Signed-off-by: Jian Zeng <[email protected]>

* test: add fake docker client

Signed-off-by: Jian Zeng <[email protected]>

* refactor: cleanup

Signed-off-by: Jian Zeng <[email protected]>

* style: add linter & make linter happy

Signed-off-by: Jian Zeng <[email protected]>

* chore: update go.mod

Signed-off-by: Jian Zeng <[email protected]>

* refactor: cleanup

Signed-off-by: Jian Zeng <[email protected]>

* chore: integrate with goreleaser

Signed-off-by: Jian Zeng <[email protected]>

* chore: remove unused files

Signed-off-by: Jian Zeng <[email protected]>

* chore: update github workflow

Signed-off-by: Jian Zeng <[email protected]>

* doc: update README

Signed-off-by: Jian Zeng <[email protected]>

* test: add more test cases

Signed-off-by: Jian Zeng <[email protected]>

* test: add integration test

Signed-off-by: Jian Zeng <[email protected]>

* feat: configure dependabot

Signed-off-by: Jian Zeng <[email protected]>

* refactor: polish yukictl

Signed-off-by: Jian Zeng <[email protected]>

* refactor: remove unused cli & endpoint

Signed-off-by: Jian Zeng <[email protected]>

* fix: update yukictl

Signed-off-by: Jian Zeng <[email protected]>

* chore: update example server config

Signed-off-by: Jian Zeng <[email protected]>

* refactor: remove endpoint that returns repo logs

Signed-off-by: Jian Zeng <[email protected]>

* doc: update README

Signed-off-by: Jian Zeng <[email protected]>

* style: make linter happy

Signed-off-by: Jian Zeng <[email protected]>

* fix: mounts are different from binds

Signed-off-by: Jian Zeng <[email protected]>

* refactor: remove unused code

Signed-off-by: Jian Zeng <[email protected]>

* refactor: rename fields for better readability

Signed-off-by: Jian Zeng <[email protected]>

* refactor: cleanup

Signed-off-by: Jian Zeng <[email protected]>

* test: remove unnecessary test & connect to a temp db

Signed-off-by: Jian Zeng <[email protected]>

* feat: update envs

Signed-off-by: Jian Zeng <[email protected]>

* fix: update upstream when loading repo

Signed-off-by: Jian Zeng <[email protected]>

* chore: log request at DEBUG level

Signed-off-by: Jian Zeng <[email protected]>

* chore: more debug logs

Signed-off-by: Jian Zeng <[email protected]>

* chore: no need to copy env map

Signed-off-by: Jian Zeng <[email protected]>

* fix sync --debug

Signed-off-by: Jian Zeng <[email protected]>

* chore: update config files

Signed-off-by: Jian Zeng <[email protected]>

* feat: print version

Signed-off-by: Jian Zeng <[email protected]>

* fix: remove extra slashes

Signed-off-by: Jian Zeng <[email protected]>

* doc: update README

Signed-off-by: Jian Zeng <[email protected]>

* refactor: cleanup

Signed-off-by: Jian Zeng <[email protected]>

* fix: ensure map is not nil

Signed-off-by: Jian Zeng <[email protected]>

* chore: minor change

Signed-off-by: Jian Zeng <[email protected]>

* refactor: rename field `interval` to `cron`

Signed-off-by: Jian Zeng <[email protected]>

* refactor: change the type of images_upgrade_interval to duration

Signed-off-by: Jian Zeng <[email protected]>

* doc: update README

Signed-off-by: Jian Zeng <[email protected]>

* test: fix flaky test

Signed-off-by: Jian Zeng <[email protected]>

* refactor: cleanup

Signed-off-by: Jian Zeng <[email protected]>

* test: fix flaky test

Signed-off-by: Jian Zeng <[email protected]>

* feat: add release workflow

Signed-off-by: Jian Zeng <[email protected]>

* refactor: scan db periodically to run cronjobs

Signed-off-by: Jian Zeng <[email protected]>

* chore: update deps

Signed-off-by: Jian Zeng <[email protected]>

* doc: add migration guide to README

Signed-off-by: Jian Zeng <[email protected]>

* refactor: update docker client

Signed-off-by: Jian Zeng <[email protected]>

* chore: update deps

Signed-off-by: Jian Zeng <[email protected]>

* test: add more test cases

Signed-off-by: Jian Zeng <[email protected]>

* refactor: cleanup

Signed-off-by: Jian Zeng <[email protected]>

* feat: reduce scan interval

Signed-off-by: Jian Zeng <[email protected]>

* test: fix test

Signed-off-by: Jian Zeng <[email protected]>

* doc: fix quotes in README

Signed-off-by: Jian Zeng <[email protected]>

* fix: validate cron expression while parsing it

Signed-off-by: Jian Zeng <[email protected]>

* chore: update linter config

Signed-off-by: Jian Zeng <[email protected]>

* doc: update migration guide

Signed-off-by: Jian Zeng <[email protected]>

---------

Signed-off-by: Jian Zeng <[email protected]>
  • Loading branch information
knight42 authored Jan 7, 2024
1 parent a005963 commit 47ece57
Show file tree
Hide file tree
Showing 90 changed files with 2,762 additions and 4,898 deletions.
32 changes: 32 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
# Workflow files stored in the default location of `.github/workflows`. (You don't need to specify `/.github/workflows` for `directory`. You can use `directory: "/"`.)
directory: "/"
schedule:
interval: "weekly"
groups:
actions:
update-types:
- "major"
- "minor"
- "patch"
reviewers:
- "knight42"
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
groups:
gomod:
update-types:
- "minor"
- "patch"
reviewers:
- "knight42"
68 changes: 0 additions & 68 deletions .github/workflows/build.yml

This file was deleted.

64 changes: 64 additions & 0 deletions .github/workflows/pr-presubmit-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Presubmit Checks

on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- master
paths:
- '**.go'

concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: stable
check-latest: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.0
skip-build-cache: true
skip-pkg-cache: true

unit-test:
name: Unit Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: stable
check-latest: true
- name: Test
run: |
make unit-test
integration-test:
name: Integration Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: stable
check-latest: true
- name: Integration Test
run: |
set -euo pipefail
docker pull ustcmirror/test
make integration-test
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release

on:
push:
# run only against tags
tags:
- "v*"

concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}

permissions:
contents: write
# packages: write
# issues: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v5
with:
go-version: stable
# More assembly might be required: Docker logins, GPG, etc.
# It all depends on your needs.
- uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Build output files
yukictl
yukid
/yukictl
/yukid

.idea/
dist/

*.swp
*.[oa]
Expand Down
81 changes: 81 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Options for analysis running.
run:
# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 5m

# Which dirs to skip: issues from them won't be reported.
# Can use regexp here: `generated.*`, regexp is applied on full path.
# Default value is empty list,
# but default dirs are skipped independently of this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work on Windows.
skip-dirs:

# Enables skipping of directories:
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
# Default: true
skip-dirs-use-default: true

# If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
# to go.mod are needed. This setting is most useful to check that go.mod does
# not need updates, such as in a continuous integration and testing system.
# If invoked with -mod=vendor, the go command assumes that the vendor
# directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
#
# Allowed values: readonly|vendor|mod
# By default, it isn't set.
modules-download-mode: readonly

# https://golangci-lint.run/usage/linters/
linters:
enable:
- exhaustive
- exportloopref
- gci
- gochecknoinits
- goconst
- gocritic
- gofmt
- goimports
- importas
- misspell
- nolintlint
- prealloc
- revive
- staticcheck
- testifylint
- unconvert
- unparam
- usestdlibvars
- whitespace

linters-settings:
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/ustclug/Yuki)
exhaustive:
# Only run exhaustive check on switches with "//exhaustive:enforce" comment.
explicit-exhaustive-switch: true
# https://golangci-lint.run/usage/linters/#revive
revive:
confidence: 0.6
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#blank-imports
- name: blank-imports
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#dot-imports
- name: dot-imports
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-strings
- name: error-strings
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#errorf
- name: errorf

issues:
exclude-rules:
- path: _test.go
linters:
- errcheck
47 changes: 47 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
before:
hooks:
- go mod tidy
# TODO: publish docker images
# https://goreleaser.com/customization/docker/#how-it-works
builds:
-
id: yukictl
binary: yukictl
env:
- CGO_ENABLED=0
main: ./cmd/yukictl
goos:
- linux
goarch:
- amd64
flags:
- -trimpath
ldflags:
- -s -w -X github.com/ustclug/Yuki/pkg/info.Version={{.Version}} -X github.com/ustclug/Yuki/pkg/info.BuildDate={{.Date}}
-
id: yukid
binary: yukid
main: ./cmd/yukid
env:
# required by sqlite
- CGO_ENABLED=1
goos:
- linux
goarch:
- amd64
flags:
- -trimpath
ldflags:
- -s -w -X github.com/ustclug/Yuki/pkg/info.Version={{.Version}} -X github.com/ustclug/Yuki/pkg/info.BuildDate={{.Date}}
archives:
- format: binary
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
use: github-native

# modelines, feel free to remove those if you don't want/use them:
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.PHONY: lint
lint:
golangci-lint run --fix ./...

.PHONY: unit-test
unit-test:
go test -race -v ./pkg/...

.PHONY: integration-test
integration-test:
go test -v ./test/integration/...

.PHONY: yukid
yukid:
go build -trimpath ./cmd/yukid

.PHONY: yukictl
yukictl:
go build -trimpath ./cmd/yukictl

BUILD_IMAGE ?= golang:1.21-bookworm

.PHONY: yukid-linux
yukid-linux:
@docker run \
--rm \
--mount source=go-cache,destination=/root/.cache/go-build \
--mount source=go-mod,destination=/go/pkg/mod \
-v $(PWD):/app \
$(BUILD_IMAGE) \
bash -c 'cd /app && make yukid'
Loading

0 comments on commit 47ece57

Please sign in to comment.