Skip to content

Commit

Permalink
feat: GitHub Actions と各種バッジの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
KEINOS committed Jul 3, 2021
1 parent 66beb6e commit cf8204d
Show file tree
Hide file tree
Showing 28 changed files with 168 additions and 177 deletions.
6 changes: 2 additions & 4 deletions .devcontainer/installToolsForDev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ GoVersionRequireMin=16

NameRepo="QiiTrans"

echo "Current Go version is: ${GoVersion} (Minosr ver is: ${GoVersionMinor})"
echo "Current Go version is: ${GoVersion} (Minor ver is: ${GoVersionMinor})"
echo "Go path: $(which go)"

if [ "$GoVersionMinor" -lt "$GoVersionRequireMin" ]; then
echo >&2 "Minimum Go version does not satisfy. Required minimum Go version: 1.${GoVersionRequireMin}"
Expand Down Expand Up @@ -87,13 +88,10 @@ go install "github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest"
go install "github.com/nicksnyder/go-i18n/v2/goi18n@latest"
go install "mvdan.cc/gofumpt@latest"
go install "golang.org/x/tools/gopls@latest"
go install "github.com/spf13/cobra/cobra@latest"
go install "github.com/golang/mock/mockgen@latest"
go install "github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest"
go install "github.com/ramya-rao-a/go-outline@latest"
go install "github.com/go-delve/delve/cmd/dlv@latest"
go install "honnef.co/go/tools/cmd/staticcheck@latest"
go install "github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest"

echo
echo '* Installing shellcheck'
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Workflow/Actions to Automate

- [coverage-tests.yaml](coverage-tests.yaml): Runs unit test and static analysis of Go.
- [merte-tests.yaml](merge-tests.yaml): Runs tests for requirements to merge including shell scripts.
- [update-on-release.yaml](update-on-release.yaml): Updates the package in [pkg.go.dev](https://pkg.go.dev/github.com/KEINOS/Hello-Cobra) when new version was released.
- [merte-tests.yaml](merge-tests.yaml): マージ前に必要なテストを実行します。

## Fork 時の注意

Fork 先のリポジトリの設定で、翻訳 API のアクセストークン(認証キー)を設定・登録する必要があります。

### Repository secrets の設定

Fork 先のリポジトリの [Settings] -> [Secrets] -> "Actions secrets" の "New repository secrets" ボタンから以下の設定でトークンを設定します.

- DeepL PRO API ([認証キー確認先](https://www.deepl.com/pro-account/plan)
- Name: `DEEPL_API_KEY`
- Value: DEEPL で発行した認証キー
48 changes: 0 additions & 48 deletions .github/workflows/coverage-tests.yaml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/golangci-lint.yaml

This file was deleted.

64 changes: 37 additions & 27 deletions .github/workflows/merge-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,66 @@
name: Tests before merge
name: All Tests

on:
workflow_dispatch:
pull_request:

jobs:
merge_tests:
coverage:
name: Unit test and coverage
environment: TOKENS_BY_KEINOS

runs-on: ubuntu-latest

steps:
- name: Checkout the code
- name: Checkout repo
uses: actions/checkout@v2

- uses: actions/setup-go@v2
- name: Install Golang
uses: actions/setup-go@v2
with:
go-version: 1.15.x

- name: Use Cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
go-version: 1.16

- name: Download Modules
if: steps.cache.outputs.cache-hit != 'true'
run: go mod download

- name: Run shellcheck (pre-installed)
- name: Install ShellCheck
run: |
find . -name '*.sh' -type f -print0 | xargs -0 shellcheck
url_download="https://github.com/koalaman/shellcheck/releases/download/latest/shellcheck-latest.linux.$(uname -m).tar.xz"
timestamp="$(date +%Y%m%d%H%M%S)"
path_tmp_dir=$(mktemp "/tmp/${NameRepo}-${timestamp}.tmp.XXXXXX")
echo "TEMP PATH: ${path_tmp_dir}"
wget -P "${path_tmp_dir}/" "$url_download"
tar xvf "${path_tmp_dir}"/shellcheck* -C "${path_tmp_dir}/"
sudo cp "${path_tmp_dir}/shellcheck-latest/shellcheck" "$(dirname $(which tar))/shellcheck"
shellcheck --version
- name: Install and run shfmt
- name: Install shfmt
run: |
GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt
find . -name '*.sh' -type f -print0 | xargs -0 shfmt -d
- name: Install go-carpet
run: |
GO111MODULE=on go get github.com/msoap/go-carpet
- name: Install gomarkdoc
run: |
GO111MODULE=on go get github.com/princjef/gomarkdoc/cmd/gomarkdoc
- name: Run gofmt
uses: Jerome1337/gofmt-action@v1.0.4
with:
gofmt-path: '.'
gofmt-flags: '-d -e' # display diffs and report all errors

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: latest
args: --config ./.github/golangci.yml
skip-go-installation: true # use pre-installed Go
- name: Install golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(go env GOPATH)/bin"
golangci-lint --version
- name: Run requirement check
- name: Run coverage (Linux)
env:
DEEPL_API_KEY: ${{ secrets.DEEPL_API_KEY }}
if: runner.os != 'Windows'
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
./.github/check-requirements.sh
go mod tidy
./.github/run-tests-merge.sh
25 changes: 0 additions & 25 deletions .github/workflows/update-on-release.yaml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ man
.vagrant

coverage.out
go.sum
go-carpet-*

.DS_Store
3 changes: 2 additions & 1 deletion .markdownlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"MD024": false,
"MD029": false,
"MD033": false,
"MD040": false
"MD040": false,
"MD041": false
}
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[![All Tests](https://github.com/Qithub-BOT/QiiTrans/actions/workflows/merge-tests.yaml/badge.svg)](https://github.com/Qithub-BOT/QiiTrans/actions/workflows/merge-tests.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/Qithub-BOT/QiiTrans)](https://goreportcard.com/report/github.com/Qithub-BOT/QiiTrans)
[![Go Reference](https://pkg.go.dev/badge/github.com/Qithub-BOT/QiiTrans.svg)](https://pkg.go.dev/github.com/Qithub-BOT/QiiTrans)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Qithub-BOT/QiiTrans/blob/main/LICENSE)

# `QiiTrans`

`qiitrans`コマンドは、文書作成支援ツールです。
Expand Down Expand Up @@ -96,15 +101,15 @@ Options:

1. コマンド・オプションの `--apikey` で指定されたトークン。
2. 環境変数に、使用している翻訳エンジン専用の変数がセットされている場合は、その値。
- `DEEPL_APIKEY` ... `--engine=deepl` (デフォルトの翻訳エンジン)
3. `QIITRANS_APIKEY` がセットされている場合は、その値。
- `DEEPL_API_KEY` ... `--engine=deepl` (デフォルトの翻訳エンジン)
3. `QIITRANS_API_KEY` がセットされている場合は、その値。

## その他の環境変数

`QiiTrans` は、以下の環境変数がセットされていた場合は、デフォルト値として利用します。

- `QIITRANS_ENGINE`: 翻訳に使うエンジンです。現在は "`deepl`" のみが指定可能です。
- `QIITRANS_APIKEY`: 翻訳に使うエンジンの APIキー(アクセストークン)です。
- `QIITRANS_API_KEY`: 翻訳に使うエンジンの APIキー(アクセストークン)です。

## コントリビュート

Expand Down
File renamed without changes.
24 changes: 18 additions & 6 deletions src/cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ ClearAll() ... キャッシュ・ディレクトリを削除します。

## Constants

NameDirCacheDefault はキャッシュ時のデフォルトのディレクトリ名もしくはプレフィックス(接頭辞)です\.

テンポラリ・ディレクトリの、この名前の付いたディレクトリは削除可能です\.

```go
const (
NameDirCacheDefault = "QiiTrans"
)
const NameDirCacheDefault = "QiiTrans"
```

## type [TCache](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.go#L9-L13>)
## type [TCache](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.go#L11-L15>)

TCache はキャッシュ DB の構造体です\. \[badger\]\(https://github.com/dgraph-io/badger\) のラッパーです\.

```go
type TCache struct {
Expand Down Expand Up @@ -111,12 +115,16 @@ func (c *TCache) ClearAll()

ClearAll はキャッシュ・データを削除します\.

### func \(\*TCache\) [CloseDB](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.CloseDB.go#L7>)
### func \(\*TCache\) [CloseDB](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.CloseDB.go#L11>)

```go
func (c *TCache) CloseDB()
```

CloseDB はキャッシュの DB をクローズします\. DB がオープンされていない場合は何もしません\. クローズに失敗した場合はパニックを起こします\.

このメソッドは、Get\(\) Set\(\) でも呼び出されるため、利用時に OpenDB\(\) CloseDB\(\) を行う必要はありません\.

### func \(\*TCache\) [Get](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.Get.go#L5>)

```go
Expand All @@ -141,12 +149,16 @@ func (c *TCache) GetValueInByte(keyHashed []byte) ([]byte, error)

GetValueInByte はバイトデータにハッシュ化された keyHashed キーを使ってキャッシュを探索しバイトデータで返します\.

### func \(\*TCache\) [OpenDB](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.OpenDB.go#L8>)
### func \(\*TCache\) [OpenDB](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.OpenDB.go#L11>)

```go
func (c *TCache) OpenDB() (err error)
```

OpenDB はキャッシュ用の DB をオープンします\. キャッシュ・ディレクトリが存在しない場合は、テンポラリディレクトリに新規に作成します\.

このメソッドは、Get\(\) Set\(\) でも呼び出されるため、利用時に OpenDB\(\) CloseDB\(\) を行う必要はありません\.

### func \(\*TCache\) [Set](<https://github.com/Qithub-BOT/QiiTrans/blob/main/src/cache/TCache.Set.go#L11>)

```go
Expand Down
4 changes: 4 additions & 0 deletions src/cache/TCache.CloseDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"github.com/Qithub-BOT/QiiTrans/src/utils"
)

// CloseDB はキャッシュの DB をクローズします. DB がオープンされていない場合は何もしません.
// クローズに失敗した場合はパニックを起こします.
//
// このメソッドは、Get() Set() でも呼び出されるため、利用時に OpenDB() CloseDB() を行う必要はありません.
func (c *TCache) CloseDB() {
if c.cacheDB == nil {
utils.LogDebug("closing DB that was not opened")
Expand Down
3 changes: 3 additions & 0 deletions src/cache/TCache.OpenDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"github.com/dgraph-io/badger/v3"
)

// OpenDB はキャッシュ用の DB をオープンします. キャッシュ・ディレクトリが存在しない場合は、テンポラリディレクトリに新規に作成します.
//
// このメソッドは、Get() Set() でも呼び出されるため、利用時に OpenDB() CloseDB() を行う必要はありません.
func (c *TCache) OpenDB() (err error) {
// キャッシュ用の DB をオープン。存在しない場合は新規作成してオープン
pathDirCache := c.GetPathDirCache()
Expand Down
8 changes: 5 additions & 3 deletions src/cache/TCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package cache

import "github.com/dgraph-io/badger/v3"

const (
NameDirCacheDefault = "QiiTrans"
)
// NameDirCacheDefault はキャッシュ時のデフォルトのディレクトリ名もしくはプレフィックス(接頭辞)です.
//
// テンポラリ・ディレクトリの、この名前の付いたディレクトリは削除可能です.
const NameDirCacheDefault = "QiiTrans"

// TCache はキャッシュ DB の構造体です. [badger](https://github.com/dgraph-io/badger) のラッパーです.
type TCache struct {
cacheDB *badger.DB
NameDirCache string
Expand Down
3 changes: 2 additions & 1 deletion src/cache/docs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Package cache は key-value 型の簡易 DB です.
/*
Package cache は key-value 型の簡易 DB です.
New() でインスタンスが作成されると、テンポラリ・ディレクトリにキャッシュ用のディレクトリを作成します。
主に "Set(<翻訳前テキスト>, <翻訳後テキスト>)" のように、翻訳結果をキャッシュするのに使われます。
Expand Down
2 changes: 2 additions & 0 deletions src/engines/deepleng/GetURLBaseAPI.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package deepleng

import "github.com/Qithub-BOT/QiiTrans/src/engines/engine"

// GetURLBaseAPI は DeepL の翻訳 API のエンドポイントのドメインを返します.
// 無料・有料アカウントでドメインは異なるため、アクセス・トークン(認証キー)から自動検知して返します.
func GetURLBaseAPI(p *engine.Properties) string {
apiDomain := "https://api.deepl.com"

Expand Down
Loading

0 comments on commit cf8204d

Please sign in to comment.