Skip to content

Commit

Permalink
Add log, Update CI and Makefile (#19)
Browse files Browse the repository at this point in the history
* Add log

* Update CI

* Update Makefile

* Create tools/generatewalker.bash
  • Loading branch information
ginokent authored Nov 30, 2020
1 parent 0bf030f commit d04218d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
project_id: ${{ secrets.GCLOUD_PROJECT_ID }} ## NOTE(djeeno): JSON の中の project_id に相当。 GitHub Actions のログに出ないようにするため
Expand All @@ -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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions tools/generatewalker.bash
Original file line number Diff line number Diff line change
@@ -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 {}"

0 comments on commit d04218d

Please sign in to comment.