Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第二次重构 #43

Merged
merged 79 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
53794fe
refactor: switch to errgroup
knight42 Dec 16, 2023
227acdd
chore: update deps
knight42 Dec 16, 2023
5a70099
checkpoint
knight42 Dec 17, 2023
b5a8453
feat: update presubmit check workflow
knight42 Dec 17, 2023
ec78303
test: fix test
knight42 Dec 17, 2023
c7f776e
chore: update deps
knight42 Dec 17, 2023
71f14af
feat: impl repo meta endpoints
knight42 Dec 17, 2023
a3267ed
refactor: remove homebred validator
knight42 Dec 17, 2023
440fbd5
refactor: eliminate embedded context
knight42 Dec 17, 2023
ecdba88
refactor: switch to slog & drop quit channel
knight42 Dec 18, 2023
cbe485a
chore: update deps
knight42 Dec 20, 2023
fc97f3a
test: add test cases for RepoMeta handlers
knight42 Dec 20, 2023
5e13b52
feat: impl repo endpoints
knight42 Dec 20, 2023
7792377
refactor: simplify config loading process
knight42 Dec 20, 2023
e95928d
wip: impl sync repo handler
knight42 Dec 21, 2023
58ac257
checkpoint
knight42 Dec 27, 2023
ed85bc7
refactor: remove unused files
knight42 Dec 27, 2023
21a7df0
style: check error
knight42 Dec 27, 2023
7bf0568
chore: update deps
knight42 Dec 27, 2023
5c6183b
chore: update deps
knight42 Dec 28, 2023
bf9d722
refactor: override the path to config file
knight42 Dec 28, 2023
2d3fb6c
test: update fixtures
knight42 Dec 28, 2023
19f571e
test: add fake docker client
knight42 Dec 28, 2023
395de5e
refactor: cleanup
knight42 Dec 28, 2023
0015e6c
style: add linter & make linter happy
knight42 Dec 28, 2023
ff4fcd5
chore: update go.mod
knight42 Dec 28, 2023
750ffba
refactor: cleanup
knight42 Dec 28, 2023
d0f90ce
chore: integrate with goreleaser
knight42 Dec 28, 2023
b4ca376
chore: remove unused files
knight42 Dec 28, 2023
2a4f73b
chore: update github workflow
knight42 Dec 28, 2023
9ef2299
doc: update README
knight42 Dec 28, 2023
3ecb3cf
test: add more test cases
knight42 Dec 28, 2023
3c4184f
test: add integration test
knight42 Dec 28, 2023
57ced0a
feat: configure dependabot
knight42 Dec 28, 2023
92e82cc
refactor: polish yukictl
knight42 Dec 29, 2023
f6128c1
refactor: remove unused cli & endpoint
knight42 Dec 29, 2023
974743e
fix: update yukictl
knight42 Dec 29, 2023
ac956cf
chore: update example server config
knight42 Dec 29, 2023
67018f4
refactor: remove endpoint that returns repo logs
knight42 Dec 30, 2023
4db844a
doc: update README
knight42 Dec 30, 2023
4d1dd25
style: make linter happy
knight42 Dec 30, 2023
fe5c365
fix: mounts are different from binds
knight42 Dec 30, 2023
5b7c9ed
refactor: remove unused code
knight42 Dec 30, 2023
fdcd58d
refactor: rename fields for better readability
knight42 Dec 30, 2023
0013855
refactor: cleanup
knight42 Dec 31, 2023
8eebf66
test: remove unnecessary test & connect to a temp db
knight42 Jan 1, 2024
c436dd1
feat: update envs
knight42 Jan 1, 2024
7889e03
fix: update upstream when loading repo
knight42 Jan 1, 2024
2f104ad
chore: log request at DEBUG level
knight42 Jan 1, 2024
550d232
chore: more debug logs
knight42 Jan 1, 2024
a363263
chore: no need to copy env map
knight42 Jan 1, 2024
c579aad
fix sync --debug
knight42 Jan 1, 2024
563ca5c
chore: update config files
knight42 Jan 1, 2024
54da605
feat: print version
knight42 Jan 1, 2024
4dd407a
fix: remove extra slashes
knight42 Jan 1, 2024
31444ce
doc: update README
knight42 Jan 1, 2024
a5c6db6
refactor: cleanup
knight42 Jan 1, 2024
cb4e31b
fix: ensure map is not nil
knight42 Jan 1, 2024
b59cb5d
chore: minor change
knight42 Jan 1, 2024
e46e71b
refactor: rename field `interval` to `cron`
knight42 Jan 1, 2024
ab58572
refactor: change the type of images_upgrade_interval to duration
knight42 Jan 1, 2024
f84d6f5
doc: update README
knight42 Jan 1, 2024
7937caa
test: fix flaky test
knight42 Jan 1, 2024
50ab69f
refactor: cleanup
knight42 Jan 2, 2024
96c98bb
test: fix flaky test
knight42 Jan 2, 2024
ca6c378
feat: add release workflow
knight42 Jan 2, 2024
7da415e
refactor: scan db periodically to run cronjobs
knight42 Jan 2, 2024
c59a238
chore: update deps
knight42 Jan 2, 2024
da08801
doc: add migration guide to README
knight42 Jan 2, 2024
e829ab7
refactor: update docker client
knight42 Jan 3, 2024
51a4f9b
chore: update deps
knight42 Jan 3, 2024
e46cbb7
test: add more test cases
knight42 Jan 3, 2024
ecfbaba
refactor: cleanup
knight42 Jan 3, 2024
dee59a0
feat: reduce scan interval
knight42 Jan 3, 2024
731ec0c
test: fix test
knight42 Jan 3, 2024
f1807fb
doc: fix quotes in README
knight42 Jan 6, 2024
b76d4a7
fix: validate cron expression while parsing it
knight42 Jan 6, 2024
e4127f4
chore: update linter config
knight42 Jan 6, 2024
82a1867
doc: update migration guide
knight42 Jan 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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