Skip to content

Commit 7aad3d2

Browse files
committed
first commit
1 parent 83a3637 commit 7aad3d2

File tree

10 files changed

+275
-2
lines changed

10 files changed

+275
-2
lines changed

.github/dependabot.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
time: "02:00"
8+
timezone: "Asia/Tokyo"
9+
ignore:
10+
- dependency-name: "*"
11+
update-types:
12+
- "version-update:semver-major"
13+
labels:
14+
- "dependency"
15+
commit-message:
16+
prefix: "dependabot"
17+
include: "scope"
18+
open-pull-requests-limit: 10

.github/labels.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
- name: bug
3+
description: Categorizes issue or PR as related to a bug.
4+
color: d73a4a
5+
- name: feature
6+
description: Categorizes issue or PR as related to a new feature.
7+
color: a2eeef
8+
- name: breaking
9+
description: Indicates a PR that contains breaking changes.
10+
color: f5e642
11+
- name: deprecation
12+
description: Categorizes issue or PR as related to a feature marked for deprecation.
13+
color: a50bd9
14+
- name: refactoring
15+
description: Categorizes issue or PR as related to a code refactoring.
16+
color: 0366d6
17+
- name: dependency
18+
description: Issues or PR related to dependency changes.
19+
color: 0366d6
20+
- name: ignore
21+
description: Indicates a PR that excludes from release notes.
22+
color: 8f8f8d

.github/release.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
changelog:
3+
exclude:
4+
labels:
5+
- "ignore"
6+
categories:
7+
- title: "💥 Breaking Changes"
8+
labels:
9+
- "breaking"
10+
- title: "✨ New Feature"
11+
labels:
12+
- "feature"
13+
- title: "🐛 Bug Fix"
14+
labels:
15+
- "bug"
16+
- title: "🗑️ Deprecation"
17+
labels:
18+
- "deprecation"
19+
- title: "♻️ Code Refactoring"
20+
labels:
21+
- "refactoring"
22+
- title: "⬆️ Dependency Updates"
23+
labels:
24+
- "dependency"

.github/semver.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
3+
from __future__ import annotations
4+
import re
5+
import os
6+
import sys
7+
8+
# reference: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
9+
SEMVER_REGEX = r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?: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<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
10+
11+
12+
def removeprefix(text: str, prefix: str) -> str:
13+
if text.startswith(prefix):
14+
return text[len(prefix) :]
15+
else:
16+
return text
17+
18+
19+
def get_semver(text: str, prefix: str) -> str | None:
20+
if prefix != "":
21+
text = removeprefix(text, prefix)
22+
23+
r = re.compile(SEMVER_REGEX)
24+
result = r.match(text)
25+
26+
if result is None:
27+
raise Exception(f"target is not semver string: '{text}'")
28+
29+
return (
30+
text,
31+
result["major"],
32+
result["minor"],
33+
result["patch"],
34+
result["prerelease"],
35+
result["buildmetadata"],
36+
)
37+
38+
39+
def main():
40+
semver_str: str = ""
41+
prefix: str = ""
42+
43+
try:
44+
semver_str = sys.argv[1]
45+
prefix = sys.argv[2]
46+
except IndexError:
47+
pass
48+
49+
output = os.getenv("GITHUB_OUTPUT")
50+
if output is None:
51+
raise Exception("GITHUB_OUTPUT environment variable is not define")
52+
53+
semver, major, minor, patch, prerelease, build_metadata = get_semver(
54+
semver_str, prefix
55+
)
56+
57+
if prerelease is None:
58+
prerelease = ""
59+
60+
if build_metadata is None:
61+
build_metadata = ""
62+
63+
with open(output, "a") as f:
64+
print(f"version={semver}", file=f)
65+
print(f"major={major}", file=f)
66+
print(f"minor={minor}", file=f)
67+
print(f"patch={patch}", file=f)
68+
print(f"prerelease={prerelease}", file=f)
69+
print(f"build-metadata={build_metadata}", file=f)
70+
71+
72+
if __name__ == "__main__":
73+
try:
74+
main()
75+
except Exception as err:
76+
print(f"::error::raised error: {err}")
77+
sys.exit(1)

.github/workflows/ci.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: ci
2+
3+
concurrency:
4+
group: ${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
push:
9+
tags:
10+
- "v*.*.*"
11+
12+
jobs:
13+
gh-release:
14+
runs-on: ubuntu-latest
15+
if: startsWith(github.ref, 'refs/tags/')
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
- uses: actions/setup-go@v4
21+
with:
22+
go-version: stable
23+
- uses: goreleaser/goreleaser-action@v5
24+
with:
25+
args: release --clean
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.github_token }}

.github/workflows/sync-label.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: sync labels
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- .github/labels.yml
9+
workflow_dispatch: {}
10+
11+
jobs:
12+
sync:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: EndBug/label-sync@v2
17+
with:
18+
config-file: .github/labels.yml
19+
delete-other-labels: true

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
*.out
1616

1717
# Dependency directories (remove the comment below to include it)
18-
# vendor/
18+
vendor/
1919

2020
# Go workspace file
2121
go.work
22+
23+
# editor
24+
.vscode/
25+
26+
# goreleaser
27+
dist/

.goreleaser.yaml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
2+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
3+
4+
project_name: ysr
5+
6+
before:
7+
hooks:
8+
- go mod tidy
9+
10+
builds:
11+
- main: ./cmd/ysr/main.go
12+
env:
13+
- CGO_ENABLED=0
14+
binary: "{{ .ProjectName }}"
15+
goos:
16+
- linux
17+
- windows
18+
- darwin
19+
goarch:
20+
- amd64
21+
- arm64
22+
ldflags:
23+
- -s -w -X github.com/s-dwinter/yashiro/internal/cmd.version={{ .Version }}
24+
25+
archives:
26+
- format: tar.gz
27+
name_template: >-
28+
{{ .ProjectName }}-
29+
{{- .Os }}-
30+
{{- .Arch }}
31+
{{- if .Arm }}v{{ .Arm }}{{ end }}
32+
# use zip for windows archives
33+
format_overrides:
34+
- goos: windows
35+
format: zip
36+
37+
checksum:
38+
name_template: "checksums.txt"
39+
40+
snapshot:
41+
name_template: "{{ incpatch .Version }}-next"
42+
43+
changelog:
44+
use: github-native
45+
sort: asc

Makefile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.PHONY: help
2+
help: ## Display this help.
3+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\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)
4+
5+
##@ Development
6+
7+
.PHONY: fmt
8+
fmt: ## Run go fmt against code.
9+
go fmt ./...
10+
11+
.PHONY: vet
12+
vet: ## Run go vet against code.
13+
go vet ./...
14+
15+
.PHONY: vendor
16+
vendor: ## Run go mod vendor.
17+
go mod vendor
18+
19+
.PHONY: tidy
20+
tidy: ## Run go mod tidy.
21+
go mod tidy
22+
23+
.PHONY: build
24+
build: fmt vet vendor ## Build cli binary.
25+
goreleaser build --single-target --snapshot --clean
26+
27+
args ?=
28+
.PHONY: run
29+
run: fmt vet tidy vendor ## Run a tool in your host.
30+
go run ./cmd/ysr/main.go ${args}
31+
32+
.PHONY: test
33+
test: ## Run tests.
34+
go test ./... -v -race -coverprofile cover.out

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# yashiro
1+
# Yashiro
2+
23
Yashiro is a templating engine with the external stores.

0 commit comments

Comments
 (0)