|
| 1 | +name: Go test |
| 2 | + |
| 3 | +# This workflow uses actions that are not certified by GitHub. |
| 4 | +# They are provided by a third-party and are governed by |
| 5 | +# separate terms of service, privacy policy, and support |
| 6 | +# documentation. |
| 7 | + |
| 8 | +on: |
| 9 | + schedule: |
| 10 | + - cron: '0 10 * * *' |
| 11 | + # If any commit message in your push or the HEAD commit of your PR contains the strings |
| 12 | + # [skip ci], [ci skip], [no ci], [skip actions], or [actions skip] |
| 13 | + # workflows triggered on the push or pull_request events will be skipped. |
| 14 | + # https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/ |
| 15 | + push: |
| 16 | + branches: [ master ] |
| 17 | + # Publish semver tags as releases. |
| 18 | + tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ] |
| 19 | + # If any commit message in your push or the HEAD commit of your PR contains the strings |
| 20 | + # [skip ci], [ci skip], [no ci], [skip actions], or [actions skip] |
| 21 | + # workflows triggered on the push or pull_request events will be skipped. |
| 22 | + # https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/ |
| 23 | + pull_request: |
| 24 | + branches: [ master ] |
| 25 | + |
| 26 | +env: |
| 27 | + GOLANG_VERSION: ^1.18 |
| 28 | + |
| 29 | +jobs: |
| 30 | + build: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + permissions: |
| 33 | + actions: none |
| 34 | + checks: none |
| 35 | + contents: read |
| 36 | + deployments: none |
| 37 | + issues: none |
| 38 | + discussions: none |
| 39 | + packages: none |
| 40 | + pull-requests: none |
| 41 | + repository-projects: none |
| 42 | + security-events: none |
| 43 | + statuses: none |
| 44 | + |
| 45 | + steps: |
| 46 | + # This action checks-out your repository under $GITHUB_WORKSPACE, so your workflow can access it. |
| 47 | + # https://github.com/actions/checkout |
| 48 | + - |
| 49 | + name: Checkout repository |
| 50 | + id: checkout |
| 51 | + # You may pin to the exact commit or the version. |
| 52 | + # uses: https://github.com/actions/checkout/tags |
| 53 | + uses: actions/checkout@v3 |
| 54 | + |
| 55 | + # This action sets up a go environment for use in actions by: |
| 56 | + # - Optionally downloading and caching a version of Go by version and adding to PATH. |
| 57 | + # - Registering problem matchers for error output. |
| 58 | + # https://github.com/actions/setup-go |
| 59 | + - |
| 60 | + name: Setup Golang |
| 61 | + id: setup-go |
| 62 | + # You may pin to the exact commit or the version. |
| 63 | + # uses: https://github.com/actions/setup-go/tags |
| 64 | + uses: actions/setup-go@v3 |
| 65 | + with: |
| 66 | + go-version: ${{ env.GOLANG_VERSION }} |
| 67 | + |
| 68 | + # This action allows caching dependencies and build outputs to improve workflow execution time. |
| 69 | + # https://github.com/actions/cache |
| 70 | + - |
| 71 | + name: Cache Go Modules |
| 72 | + id: cache-go |
| 73 | + uses: actions/cache@v3 |
| 74 | + with: |
| 75 | + path: | |
| 76 | + ~/.cache/go-build |
| 77 | + ~/go/pkg/mod |
| 78 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 79 | + restore-keys: | |
| 80 | + ${{ runner.os }}-go- |
| 81 | +
|
| 82 | + # A GitHub Action for golang tests |
| 83 | + - |
| 84 | + name: Golang Tests |
| 85 | + id: go-tests |
| 86 | + run: | |
| 87 | + go version |
| 88 | + rm -rf example |
| 89 | + go test -v -race -covermode=atomic -coverprofile=coverage.out ./... |
| 90 | + go tool cover -html=coverage.out -o coverage.html |
0 commit comments