From d04218d76212aef34a0f447da6453b07d2b2a4da Mon Sep 17 00:00:00 2001 From: djeeno <29125616+djeeno@users.noreply.github.com> Date: Mon, 30 Nov 2020 17:09:49 +0900 Subject: [PATCH] Add log, Update CI and Makefile (#19) * Add log * Update CI * Update Makefile * Create tools/generatewalker.bash --- .github/workflows/main.yml | 36 ++++++++++++++++++------------------ Makefile | 4 ++-- main.go | 3 +++ tools/generatewalker.bash | 4 ++++ 4 files changed, 27 insertions(+), 20 deletions(-) create mode 100755 tools/generatewalker.bash diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fcc6d65..01db77e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,44 +10,43 @@ on: pull_request: branches: - main - ## NOTE(djeeno): ref. https://docs.github.com/actions/reference/events-that-trigger-workflows#schedule - #schedule: - # - cron: '30 * * * *' - -env: - REPOSITORY_PATH: src/github.com/djeeno/bqtableschema - #COVERAGE_HTML: src/github.com/djeeno/bqtableschema/coverage.html + # NOTE(djeeno): ref. https://docs.github.com/actions/reference/events-that-trigger-workflows#schedule + schedule: + - cron: '0 9 * * *' jobs: ci: name: CI + # NOTE(djeeno): https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - with: - path: ${{ env.REPOSITORY_PATH }} + # NOTE(djeeno): https://github.com/actions/setup-go#usage - uses: actions/setup-go@v2 with: go-version: ^1.15 - # https://github.com/actions/cache/blob/main/examples.md#go---modules + # NOTE(djeeno): https://github.com/actions/cache/blob/main/examples.md#go---modules - uses: actions/cache@v2 with: - path: ${{ github.workspace }}/pkg/mod + path: | + ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} ${{ runner.os }}-go- - - name: Run go mod download if not cache hit - if: steps.cache.outputs.cache-hit != 'true' + # NOTE(djeeno): https://github.com/actions/cache#skipping-steps-based-on-cache-hit + - name: Run go mod tidy (if not cache hit) env: GO111MODULE: auto - working-directory: ${{ env.REPOSITORY_PATH }} run: | - go mod download + go mod tidy + git diff --exit-code go.mod + git diff --exit-code go.sum + # NOTE(djeeno): https://github.com/google-github-actions/setup-gcloud#usage - uses: google-github-actions/setup-gcloud@v0.2.0 with: project_id: ${{ secrets.GCLOUD_PROJECT_ID }} ## NOTE(djeeno): JSON の中の project_id に相当。 GitHub Actions のログに出ないようにするため @@ -58,16 +57,17 @@ jobs: - name: Run make ci env: GO111MODULE: auto - working-directory: ${{ env.REPOSITORY_PATH }} run: | make ci + # NOTE(djeeno): https://github.com/actions/upload-artifact#usage #- uses: actions/upload-artifact@v2 # with: # name: coverage.html - # path: ${{ env.COVERAGE_HTML }} + # path: ./coverage.html + # NOTE(djeeno): https://github.com/codecov/codecov-action#example-workflowyml-with-codecov-action - uses: codecov/codecov-action@v1 with: token: ${{ secrets.CODECOV_TOKEN }} - directory: ${{ env.REPOSITORY_PATH }} + file: ./coverage.txt diff --git a/Makefile b/Makefile index 034650c..df7aba2 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ COMMAND_NAME := bqtableschema COMMIT_HASH := $(shell git rev-parse HEAD) ROOT_DIR := $(shell git rev-parse --show-toplevel) MAIN_DIR := ${ROOT_DIR} -COVERAGE_FILE := ${MAIN_DIR}/coverage.txt -COVERAGE_HTML := ${MAIN_DIR}/coverage.html +COVERAGE_FILE := ${ROOT_DIR}/coverage.txt +COVERAGE_HTML := ${ROOT_DIR}/coverage.html TEST_CMD := go test -v -race -cover -coverprofile=${COVERAGE_FILE} ./... OPEN_CMD := $(shell if command -v explorer.exe 1>/dev/null; then echo "explorer.exe"; elif uname -s | grep -q Darwin; then echo "open"; else echo "echo"; fi) diff --git a/main.go b/main.go index 67c4353..34d7b28 100644 --- a/main.go +++ b/main.go @@ -267,15 +267,18 @@ func getOptOrEnvOrDefault(optKey, optValue, envKey, defaultValue string) (string } if optValue != "" { + log.Println("use option: " + optKey + "=" + optValue) return optValue, nil } envValue := os.Getenv(envKey) if envValue != "" { + log.Println("use env: " + envKey + "=" + envValue) return envValue, nil } if defaultValue != "" { + log.Println("use default: " + optKey + "=" + defaultValue) return defaultValue, nil } diff --git a/tools/generatewalker.bash b/tools/generatewalker.bash new file mode 100755 index 0000000..0e0ff32 --- /dev/null +++ b/tools/generatewalker.bash @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -E -e -o pipefail + +grep "^\t*//go:generate go run github.com/djeeno/bqtableschema" -r "$(pwd)" -l | xargs -I{} bash -cx "go generate {}"