diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 0000000..4b73fda --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,18 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" + time: "02:00" + timezone: "Asia/Tokyo" + ignore: + - dependency-name: "*" + update-types: + - "version-update:semver-major" + labels: + - "dependency" + commit-message: + prefix: "dependabot" + include: "scope" + open-pull-requests-limit: 10 diff --git a/.github/labels.yml b/.github/labels.yml new file mode 100644 index 0000000..49dd925 --- /dev/null +++ b/.github/labels.yml @@ -0,0 +1,22 @@ +--- +- name: bug + description: Categorizes issue or PR as related to a bug. + color: d73a4a +- name: feature + description: Categorizes issue or PR as related to a new feature. + color: a2eeef +- name: breaking + description: Indicates a PR that contains breaking changes. + color: f5e642 +- name: deprecation + description: Categorizes issue or PR as related to a feature marked for deprecation. + color: a50bd9 +- name: refactoring + description: Categorizes issue or PR as related to a code refactoring. + color: 0366d6 +- name: dependency + description: Issues or PR related to dependency changes. + color: 0366d6 +- name: ignore + description: Indicates a PR that excludes from release notes. + color: 8f8f8d diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..7de13e8 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,24 @@ +--- +changelog: + exclude: + labels: + - "ignore" + categories: + - title: "💥 Breaking Changes" + labels: + - "breaking" + - title: "✨ New Feature" + labels: + - "feature" + - title: "🐛 Bug Fix" + labels: + - "bug" + - title: "🗑️ Deprecation" + labels: + - "deprecation" + - title: "♻️ Code Refactoring" + labels: + - "refactoring" + - title: "⬆️ Dependency Updates" + labels: + - "dependency" diff --git a/.github/semver.py b/.github/semver.py new file mode 100755 index 0000000..5475abd --- /dev/null +++ b/.github/semver.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 + +from __future__ import annotations +import re +import os +import sys + +# reference: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string +SEMVER_REGEX = r"^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$" + + +def removeprefix(text: str, prefix: str) -> str: + if text.startswith(prefix): + return text[len(prefix) :] + else: + return text + + +def get_semver(text: str, prefix: str) -> str | None: + if prefix != "": + text = removeprefix(text, prefix) + + r = re.compile(SEMVER_REGEX) + result = r.match(text) + + if result is None: + raise Exception(f"target is not semver string: '{text}'") + + return ( + text, + result["major"], + result["minor"], + result["patch"], + result["prerelease"], + result["buildmetadata"], + ) + + +def main(): + semver_str: str = "" + prefix: str = "" + + try: + semver_str = sys.argv[1] + prefix = sys.argv[2] + except IndexError: + pass + + output = os.getenv("GITHUB_OUTPUT") + if output is None: + raise Exception("GITHUB_OUTPUT environment variable is not define") + + semver, major, minor, patch, prerelease, build_metadata = get_semver( + semver_str, prefix + ) + + if prerelease is None: + prerelease = "" + + if build_metadata is None: + build_metadata = "" + + with open(output, "a") as f: + print(f"version={semver}", file=f) + print(f"major={major}", file=f) + print(f"minor={minor}", file=f) + print(f"patch={patch}", file=f) + print(f"prerelease={prerelease}", file=f) + print(f"build-metadata={build_metadata}", file=f) + + +if __name__ == "__main__": + try: + main() + except Exception as err: + print(f"::error::raised error: {err}") + sys.exit(1) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..799fa30 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +name: ci + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +on: + push: + tags: + - "v*.*.*" + +jobs: + gh-release: + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-go@v4 + with: + go-version: stable + - uses: goreleaser/goreleaser-action@v5 + with: + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.github_token }} diff --git a/.github/workflows/sync-label.yml b/.github/workflows/sync-label.yml new file mode 100644 index 0000000..ba56d2e --- /dev/null +++ b/.github/workflows/sync-label.yml @@ -0,0 +1,19 @@ +name: sync labels + +on: + push: + branches: + - main + paths: + - .github/labels.yml + workflow_dispatch: {} + +jobs: + sync: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: EndBug/label-sync@v2 + with: + config-file: .github/labels.yml + delete-other-labels: true diff --git a/.gitignore b/.gitignore index 3b735ec..9dd3b40 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,13 @@ *.out # Dependency directories (remove the comment below to include it) -# vendor/ +vendor/ # Go workspace file go.work + +# editor +.vscode/ + +# goreleaser +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..dcccae9 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,45 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +project_name: ysr + +before: + hooks: + - go mod tidy + +builds: + - main: ./cmd/ysr/main.go + env: + - CGO_ENABLED=0 + binary: "{{ .ProjectName }}" + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -s -w -X github.com/s-dwinter/yashiro/internal/cmd.version={{ .Version }} + +archives: + - format: tar.gz + name_template: >- + {{ .ProjectName }}- + {{- .Os }}- + {{- .Arch }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +checksum: + name_template: "checksums.txt" + +snapshot: + name_template: "{{ incpatch .Version }}-next" + +changelog: + use: github-native + sort: asc diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0682d9a --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +.PHONY: help +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + +##@ Development + +.PHONY: fmt +fmt: ## Run go fmt against code. + go fmt ./... + +.PHONY: vet +vet: ## Run go vet against code. + go vet ./... + +.PHONY: vendor +vendor: ## Run go mod vendor. + go mod vendor + +.PHONY: tidy +tidy: ## Run go mod tidy. + go mod tidy + +.PHONY: build +build: fmt vet vendor ## Build cli binary. + goreleaser build --single-target --snapshot --clean + +args ?= +.PHONY: run +run: fmt vet tidy vendor ## Run a tool in your host. + go run ./cmd/ysr/main.go ${args} + +.PHONY: test +test: ## Run tests. + go test ./... -v -race -coverprofile cover.out diff --git a/README.md b/README.md index 14a1aef..d44cd54 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -# yashiro +# Yashiro + Yashiro is a templating engine with the external stores.