From bad7fd1f4a70422405815a67e8cfc916c113411d Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Sun, 29 Nov 2020 12:39:13 -0500 Subject: [PATCH] Moving from Travis to Github Actions --- .github/workflows/codeql-analysis.yml | 71 +++++++++++++++++++++++++++ .github/workflows/run-tests.yml | 44 +++++++++++++++++ .golangci.yml | 2 +- .make/Makefile.go | 19 ++++--- .travis.yml | 29 ----------- README.md | 56 +++++++++++---------- 6 files changed, 158 insertions(+), 63 deletions(-) create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/run-tests.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..bdbb1cd --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,71 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +name: "CodeQL" + +on: + push: + branches: [master] + pull_request: + # The branches below must be a subset of the branches above + branches: [master] + schedule: + - cron: '0 23 * * 0' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + # Override automatic language detection by changing the below list + # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] + language: ['go'] + # Learn more... + # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + # We must fetch at least the immediate parents so that if this is + # a pull request then we can checkout the head. + fetch-depth: 2 + + # If this run was triggered by a pull request event, then checkout + # the head of the pull request instead of the merge commit. + - run: git checkout HEAD^2 + if: ${{ github.event_name == 'pull_request' }} + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..89e29ed --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,44 @@ +name: run-go-tests + +env: + GO111MODULE: on + +on: + pull_request: + branches: + - "*" + push: + branches: + - "*" + schedule: + - cron: '* 22 * * *' + +jobs: + test: + strategy: + matrix: + go-version: [ 1.15.x ] + #go-version: [ 1.14.x, 1.15.x ] + os: [ ubuntu-latest ] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: | + ~/go/pkg/mod # Module download cache + ~/.cache/go-build # Build cache (Linux) + ~/Library/Caches/go-build # Build cache (Mac) + '%LocalAppData%\go-build' # Build cache (Windows) + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Run linter and tests + run: make test-ci + - name: Update code coverage + run: bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 12bb0c4..7901156 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -372,7 +372,7 @@ issues: # it can be disabled by `exclude-use-default: false`. To list all # excluded by default patterns execute `golangci-lint run --help` exclude: - - abcdef + - Using the variable on range scope .* in function literal # Excluding configuration per-path, per-linter, per-text and per-source exclude-rules: diff --git a/.make/Makefile.go b/.make/Makefile.go index 3cc31f7..8a093b7 100644 --- a/.make/Makefile.go +++ b/.make/Makefile.go @@ -42,9 +42,11 @@ install-go: ## Install the application (Using Native Go) lint: ## Run the golangci-lint application (install if not found) @#Travis (has sudo) - @if [ "$(shell command -v golangci-lint)" = "" ] && [ $(TRAVIS) ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.32.2 && sudo cp ./bin/golangci-lint $(go env GOPATH)/bin/; fi; + @if [ "$(shell command -v golangci-lint)" = "" ] && [ $(TRAVIS) ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.33.0 && sudo cp ./bin/golangci-lint $(go env GOPATH)/bin/; fi; @#AWS CodePipeline - @if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(CODEBUILD_BUILD_ID)" != "" ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.32.2; fi; + @if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(CODEBUILD_BUILD_ID)" != "" ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.33.0; fi; + @#Github Actions + @if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(GITHUB_WORKFLOW)" != "" ]; then curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b $(go env GOPATH)/bin v1.33.0; fi; @#Brew - MacOS @if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(shell command -v brew)" != "" ]; then brew install golangci-lint; fi; @echo "running golangci-lint..." @@ -60,14 +62,19 @@ test-short: ## Runs vet, lint and tests (excludes integration tests) @echo "running tests (short)..." @go test ./... -v -test.short -test-travis: ## Runs all tests via Travis (also exports coverage) +test-ci: ## Runs all tests via CI (exports coverage) @$(MAKE) lint - @echo "running tests..." + @echo "running tests (CI)..." @go test ./... -race -coverprofile=coverage.txt -covermode=atomic -test-travis-short: ## Runs unit tests via Travis (also exports coverage) +test-ci-no-race: ## Runs all tests via CI (no race) (exports coverage) @$(MAKE) lint - @echo "running tests (short)..." + @echo "running tests (CI - no race)..." + @go test ./... -coverprofile=coverage.txt -covermode=atomic + +test-ci-short: ## Runs unit tests via CI (exports coverage) + @$(MAKE) lint + @echo "running tests (CI - unit tests only)..." @go test ./... -test.short -race -coverprofile=coverage.txt -covermode=atomic uninstall: ## Uninstall the application (and remove files) diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index abd6f1c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -# Fast runner (trick from @y0ssar1an) (out-dated) -sudo: false - -# Language of deployment -language: go - -# Version -go: - - 1.15.x - -# Environment variables -env: - - GO111MODULE=on - -# Only clone the most recent commit -git: - depth: 1 - -# Notifications off -notifications: - email: false - -# Run all scripts -script: - - make test-travis - -# After build success -after_success: - - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/README.md b/README.md index 102a9c9..4ba6d48 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ > Simple library of sanitation methods for data sanitation and reduction [![Release](https://img.shields.io/github/release-pre/mrz1836/go-sanitize.svg?logo=github&style=flat)](https://github.com/mrz1836/go-sanitize/releases) -[![Build Status](https://travis-ci.com/mrz1836/go-sanitize.svg?branch=master)](https://travis-ci.com/mrz1836/go-sanitize) +[![Build Status](https://img.shields.io/github/workflow/status/mrz1836/go-sanitize/run-go-tests?logo=github&v=3)](https://github.com/mrz1836/go-sanitize/actions) [![Report](https://goreportcard.com/badge/github.com/mrz1836/go-sanitize?style=flat)](https://goreportcard.com/report/github.com/mrz1836/go-sanitize) [![codecov](https://codecov.io/gh/mrz1836/go-sanitize/branch/master/graph/badge.svg)](https://codecov.io/gh/mrz1836/go-sanitize) [![Go](https://img.shields.io/github/go-mod/go-version/mrz1836/go-sanitize)](https://golang.org/) @@ -60,37 +60,39 @@ make help List of all current commands: ```text -all Runs multiple commands -clean Remove previous builds and any test cache data -clean-mods Remove all the Go mod cache -coverage Shows the test coverage -godocs Sync the latest tag with GoDocs -help Show this help message -install Install the application -install-go Install the application (Using Native Go) -lint Run the golangci-lint application (install if not found) -release Full production release (creates release in Github) -release Runs common.release then runs godocs -release-snap Test the full release (build binaries) -release-test Full production test release (everything except deploy) -replace-version Replaces the version in HTML/JS (pre-deploy) -tag Generate a new tag and push (tag version=0.0.0) -tag-remove Remove a tag if found (tag-remove version=0.0.0) -tag-update Update an existing tag to current commit (tag-update version=0.0.0) -test Runs vet, lint and ALL tests -test-short Runs vet, lint and tests (excludes integration tests) -test-travis Runs all tests via Travis (also exports coverage) -test-travis-short Runs unit tests via Travis (also exports coverage) -uninstall Uninstall the application (and remove files) -update-linter Update the golangci-lint package (macOS only) -vet Run the Go vet application +all Runs multiple commands +clean Remove previous builds and any test cache data +clean-mods Remove all the Go mod cache +coverage Shows the test coverage +godocs Sync the latest tag with GoDocs +help Show this help message +install Install the application +install-go Install the application (Using Native Go) +lint Run the golangci-lint application (install if not found) +release Full production release (creates release in Github) +release Runs common.release then runs godocs +release-snap Test the full release (build binaries) +release-test Full production test release (everything except deploy) +replace-version Replaces the version in HTML/JS (pre-deploy) +tag Generate a new tag and push (tag version=0.0.0) +tag-remove Remove a tag if found (tag-remove version=0.0.0) +tag-update Update an existing tag to current commit (tag-update version=0.0.0) +test Runs vet, lint and ALL tests +test-ci Runs all tests via CI (exports coverage) +test-ci-no-race Runs all tests via CI (no race) (exports coverage) +test-ci-short Runs unit tests via CI (exports coverage) +test-short Runs vet, lint and tests (excludes integration tests) +uninstall Uninstall the application (and remove files) +update-linter Update the golangci-lint package (macOS only) +vet Run the Go vet application ```
## Examples & Tests -All unit tests and [examples](sanitize_test.go) run via [Travis CI](https://travis-ci.org/mrz1836/go-sanitize) and uses [Go version 1.15.x](https://golang.org/doc/go1.15). View the [deployment configuration file](.travis.yml). +All unit tests and [examples](examples) run via [Github Actions](https://github.com/mrz1836/go-sanitize/actions) and +uses [Go version 1.15.x](https://golang.org/doc/go1.15). View the [configuration file](.github/workflows/run-tests.yml). Run all tests (including any integration tests) ```shell script @@ -113,7 +115,7 @@ Read more about this Go project's [code standards](CODE_STANDARDS.md).
## Usage -- View the [examples](sanitize_test.go) +- View the [examples](examples) - View the [benchmarks](sanitize_test.go) - View the [tests](sanitize_test.go)