mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
ac22aadc13
* WIP * Add more logging * Check rate limit at end of action * Add github client in more places * Add new published firefox 93 vulnerabilities to tests * Remove fmt printfs * Restore CI check settings * Readd newline
131 lines
3.9 KiB
YAML
131 lines
3.9 KiB
YAML
name: Go Tests
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- patch-*
|
|
paths:
|
|
- '**.go'
|
|
- 'go.mod'
|
|
- 'go.sum'
|
|
pull_request:
|
|
paths:
|
|
- '**.go'
|
|
- 'go.mod'
|
|
- 'go.sum'
|
|
- '.github/workflows/test-go.yaml'
|
|
workflow_dispatch: # Manual
|
|
schedule:
|
|
- cron: '0 4 * * *'
|
|
|
|
# This allows a subsequently queued workflow run to interrupt previous runs
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id}}
|
|
cancel-in-progress: true
|
|
|
|
defaults:
|
|
run:
|
|
# fail-fast using bash -eo pipefail. See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#exit-codes-and-error-action-preference
|
|
shell: bash
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
test-go:
|
|
strategy:
|
|
matrix:
|
|
os: [ubuntu-latest]
|
|
go-version: ['^1.19.4']
|
|
mysql: ["mysql:5.7.21", "mysql:8.0.28"]
|
|
runs-on: ${{ matrix.os }}
|
|
|
|
env:
|
|
RACE_ENABLED: false
|
|
GO_TEST_TIMEOUT: 10m
|
|
|
|
steps:
|
|
- name: Install Go
|
|
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f # v2
|
|
with:
|
|
go-version: ${{ matrix.go-version }}
|
|
|
|
- name: Checkout Code
|
|
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v2
|
|
|
|
# Pre-starting dependencies here means they are ready to go when we need them.
|
|
- name: Start Infra Dependencies
|
|
# Use & to background this
|
|
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 saml_idp &
|
|
|
|
# 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
|
|
|
|
- name: Set Go race setting on schedule
|
|
if: github.event.schedule == '0 4 * * *'
|
|
run: |
|
|
echo "RACE_ENABLED=true" >> $GITHUB_ENV
|
|
echo "GO_TEST_TIMEOUT=1h" >> $GITHUB_ENV
|
|
|
|
- name: Wait for mysql
|
|
run: |
|
|
echo "waiting for mysql..."
|
|
until docker-compose exec -T mysql_test sh -c "mysql -uroot -p\"\${MYSQL_ROOT_PASSWORD}\" -e \"SELECT 1=1\" fleet" &> /dev/null; do
|
|
echo "."
|
|
sleep 1
|
|
done
|
|
echo "mysql is ready"
|
|
|
|
- name: Run Go Tests
|
|
run: |
|
|
GO_TEST_EXTRA_FLAGS="-v -race=$RACE_ENABLED -timeout=$GO_TEST_TIMEOUT" \
|
|
TEST_LOCK_FILE_PATH=$(pwd)/lock \
|
|
NETWORK_TEST=1 \
|
|
REDIS_TEST=1 \
|
|
MYSQL_TEST=1 \
|
|
MINIO_STORAGE_TEST=1 \
|
|
SAML_IDP_TEST=1 \
|
|
NETWORK_TEST_GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} \
|
|
make test-go 2>&1 | tee /tmp/gotest.log
|
|
|
|
- name: Upload to Codecov
|
|
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378
|
|
with:
|
|
files: coverage.txt
|
|
|
|
- name: Slack Notification
|
|
if: github.event.schedule == '0 4 * * *' && failure()
|
|
uses: slackapi/slack-github-action@16b6c78ee73689a627b65332b34e5d409c7299da # v1.18.0
|
|
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:
|
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_G_PLATFORM_WEBHOOK_URL }}
|
|
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
|
|
|
|
- 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
|