name: Test

on: [ push, pull_request ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Setup Go environment
        uses: actions/setup-go@v2.1.3
        with:
          go-version: 1.18

      - name: Configure Git
        run: |
          git config --global user.name "Marvin Zhang"
          git config --global user.email "tikazyq@163.com"

      - name: Write Credentials
        run: |
          echo '${{ secrets.CREDENTIAL_JSON }}' > $GITHUB_WORKSPACE/credentials.json
          echo '${{ secrets.CREDENTIAL_JSON }}' > $GITHUB_WORKSPACE/test/credentials.json
          ls -l $GITHUB_WORKSPACE/test
          mkdir -p $GITHUB_WORKSPACE/.ssh
          echo "${{ secrets.SSH_KEY }}" > $GITHUB_WORKSPACE/id_rsa
          ls -la $GITHUB_WORKSPACE
          echo "GITHUB_WORKSPACE: $GITHUB_WORKSPACE"

      - name: Install
        run: go mod tidy

      - name: Run Tests
        run: go test ./... -race
