2021-08-26 16:53:10 +00:00
|
|
|
name: Go Tests
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
2021-10-18 21:49:32 +00:00
|
|
|
- patch-*
|
2021-11-18 23:14:29 +00:00
|
|
|
paths:
|
|
|
|
- '**.go'
|
2022-07-11 17:58:27 +00:00
|
|
|
- 'go.mod'
|
|
|
|
- 'go.sum'
|
2021-08-26 16:53:10 +00:00
|
|
|
pull_request:
|
2021-08-26 18:25:25 +00:00
|
|
|
paths:
|
|
|
|
- '**.go'
|
2022-07-11 17:58:27 +00:00
|
|
|
- 'go.mod'
|
|
|
|
- 'go.sum'
|
2022-02-14 15:13:02 +00:00
|
|
|
workflow_dispatch: # Manual
|
2022-02-14 19:38:53 +00:00
|
|
|
schedule:
|
|
|
|
- cron: '0 4 * * *'
|
2021-08-26 16:53:10 +00:00
|
|
|
|
2022-03-28 20:20:31 +00:00
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
|
2021-08-26 16:53:10 +00:00
|
|
|
jobs:
|
|
|
|
test-go:
|
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
os: [ubuntu-latest]
|
2022-03-16 18:56:58 +00:00
|
|
|
go-version: ['^1.17.8']
|
2022-04-27 23:21:16 +00:00
|
|
|
mysql: ["mysql:5.7.21", "mysql:8.0.28"]
|
2021-08-26 16:53:10 +00:00
|
|
|
runs-on: ${{ matrix.os }}
|
|
|
|
|
2022-02-14 19:38:53 +00:00
|
|
|
env:
|
|
|
|
RACE_ENABLED: false
|
|
|
|
GO_TEST_TIMEOUT: 10m
|
|
|
|
|
2021-08-26 16:53:10 +00:00
|
|
|
steps:
|
|
|
|
- name: Install Go
|
2022-05-31 13:13:26 +00:00
|
|
|
uses: actions/setup-go@b22fbbc2921299758641fab08929b4ac52b32923 # v2
|
2021-08-26 16:53:10 +00:00
|
|
|
with:
|
|
|
|
go-version: ${{ matrix.go-version }}
|
|
|
|
|
2022-07-11 11:12:33 +00:00
|
|
|
- name: Set up gotestfmt
|
|
|
|
run: go install github.com/haveyoudebuggedit/gotestfmt/v2/cmd/gotestfmt@v2.3.2
|
|
|
|
|
2021-08-26 16:53:10 +00:00
|
|
|
- name: Checkout Code
|
2022-03-16 19:42:28 +00:00
|
|
|
uses: actions/checkout@629c2de402a417ea7690ca6ce3f33229e27606a5 # v2
|
2021-08-26 16:53:10 +00:00
|
|
|
|
|
|
|
# Pre-starting dependencies here means they are ready to go when we need them.
|
|
|
|
- name: Start Infra Dependencies
|
|
|
|
# Use & to background this
|
2022-07-14 17:14:24 +00:00
|
|
|
run: FLEET_MYSQL_IMAGE=${{ matrix.mysql }} docker-compose up -d mysql_test redis redis-cluster-1 redis-cluster-2 redis-cluster-3 redis-cluster-4 redis-cluster-5 redis-cluster-6 redis-cluster-setup minio &
|
2021-08-26 16:53:10 +00:00
|
|
|
|
|
|
|
# It seems faster not to cache Go dependencies
|
|
|
|
- name: Install Go Dependencies
|
|
|
|
run: make deps-go
|
|
|
|
|
|
|
|
- name: Generate static files
|
|
|
|
run: |
|
|
|
|
export PATH=$PATH:~/go/bin
|
|
|
|
make generate-go
|
|
|
|
|
2022-02-14 19:38:53 +00:00
|
|
|
- name: Set Go race setting on schedule
|
|
|
|
if: github.event.schedule == '0 4 * * *'
|
2022-02-15 12:26:28 +00:00
|
|
|
run: |
|
|
|
|
echo "RACE_ENABLED=true" >> $GITHUB_ENV
|
|
|
|
echo "GO_TEST_TIMEOUT=1h" >> $GITHUB_ENV
|
2022-02-14 19:38:53 +00:00
|
|
|
|
2021-08-26 16:53:10 +00:00
|
|
|
- name: Run Go Tests
|
|
|
|
run: |
|
2022-07-11 11:12:33 +00:00
|
|
|
GO_TEST_EXTRA_FLAGS="-v -json -race=$RACE_ENABLED -timeout=$GO_TEST_TIMEOUT" \
|
|
|
|
TEST_LOCK_FILE_PATH=$(pwd)/lock \
|
|
|
|
NETWORK_TEST=1 \
|
|
|
|
REDIS_TEST=1 \
|
|
|
|
MYSQL_TEST=1 \
|
2022-07-14 17:14:24 +00:00
|
|
|
MINIO_STORAGE_TEST=1 \
|
2022-07-11 11:12:33 +00:00
|
|
|
make test-go 2>&1 | tee /tmp/gotest.log | gotestfmt
|
2021-08-26 16:53:10 +00:00
|
|
|
|
|
|
|
- name: Upload to Codecov
|
2022-06-29 01:26:00 +00:00
|
|
|
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378
|
2021-08-26 16:53:10 +00:00
|
|
|
with:
|
|
|
|
files: coverage.txt
|
2022-02-14 19:38:53 +00:00
|
|
|
|
|
|
|
- name: Slack Notification
|
|
|
|
if: github.event.schedule == '0 4 * * *' && failure()
|
2022-03-16 19:42:28 +00:00
|
|
|
uses: slackapi/slack-github-action@16b6c78ee73689a627b65332b34e5d409c7299da # v1.18.0
|
2022-02-14 19:38:53 +00:00
|
|
|
with:
|
|
|
|
payload: |
|
|
|
|
{
|
|
|
|
"text": "${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }}",
|
|
|
|
"blocks": [
|
|
|
|
{
|
|
|
|
"type": "section",
|
|
|
|
"text": {
|
|
|
|
"type": "mrkdwn",
|
|
|
|
"text": "Go tests result: ${{ job.status }}\nhttps://github.com/fleetdm/fleet/actions/runs/${{ github.run_id }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
env:
|
2022-04-26 17:44:46 +00:00
|
|
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_G_PLATFORM_WEBHOOK_URL }}
|
2022-02-14 19:38:53 +00:00
|
|
|
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
|
2022-07-11 11:12:33 +00:00
|
|
|
|
|
|
|
- name: Upload test log
|
|
|
|
if: always()
|
|
|
|
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v2
|
|
|
|
with:
|
|
|
|
name: test-log
|
|
|
|
path: /tmp/gotest.log
|
|
|
|
if-no-files-found: error
|