github.com/twilio/twilio-go@v1.20.1/.github/workflows/test-and-deploy.yml (about) 1 name: Test and Deploy 2 on: 3 push: 4 branches: [ '*' ] 5 tags: [ '*' ] 6 pull_request: 7 branches: [ main ] 8 schedule: 9 # Run automatically at 8AM PST Monday-Friday 10 - cron: '0 15 * * 1-5' 11 workflow_dispatch: 12 13 jobs: 14 test: 15 name: Build & Test 16 runs-on: ubuntu-latest 17 timeout-minutes: 20 18 strategy: 19 matrix: 20 go: [ '1.15', '1.16', '1.17', '1.18', '1.19' ] 21 steps: 22 - name: Setup Go environment 23 uses: actions/setup-go@v3 24 with: 25 go-version: ${{ matrix.go }} 26 27 - name: Checkout twilio-go 28 uses: actions/checkout@v3 29 with: 30 fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis 31 32 - name: golangci-lint 33 uses: golangci/golangci-lint-action@v3 34 if: matrix.go != '1.15' # Breaking changes in golang 1.16 cause some unit test files to be invalid. 35 with: 36 version: latest 37 only-new-issues: true 38 39 - name: Build 40 run: make install 41 42 - name: Run Unit Tests 43 if: matrix.go != '1.15' # Breaking changes in golang 1.16 cause some unit test files to be invalid. 44 run: make test 45 46 - name: Run Cluster Tests 47 if: (!github.event.pull_request.head.repo.fork) 48 env: 49 TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }} 50 TWILIO_API_KEY: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY}} 51 TWILIO_API_SECRET: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY_SECRET }} 52 TWILIO_FROM_NUMBER: ${{ secrets.TWILIO_FROM_NUMBER }} 53 TWILIO_TO_NUMBER: ${{ secrets.TWILIO_TO_NUMBER }} 54 run: make cluster-test 55 56 - name: Run Test Coverage 57 if: matrix.go != '1.15' # Breaking changes in golang 1.16 cause some unit test files to be invalid. 58 run: make cover 59 60 - name: Install SonarCloud scanner and run analysis 61 uses: SonarSource/sonarcloud-github-action@master 62 if: (github.event_name == 'pull_request' || github.ref_type == 'branch') && !github.event.pull_request.head.repo.fork && matrix.go == '1.19' 63 env: 64 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any 65 SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 66 67 deploy: 68 name: Deploy 69 if: success() && github.ref_type == 'tag' 70 needs: [ test ] 71 runs-on: ubuntu-latest 72 steps: 73 - name: Checkout twilio-go 74 uses: actions/checkout@v3 75 with: 76 fetch-depth: 0 77 78 - name: Login to Docker Hub 79 uses: docker/login-action@v2 80 with: 81 username: ${{ secrets.DOCKER_USERNAME }} 82 password: ${{ secrets.DOCKER_AUTH_TOKEN }} 83 84 # The expression strips off the shortest match from the front of the string to yield just the tag name as the output 85 - name: Get tagged version 86 run: echo "GITHUB_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV 87 88 - name: Create GitHub Release 89 uses: sendgrid/dx-automator/actions/release@main 90 env: 91 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 92 93 - name: Build and Push image 94 run: make docker-build docker-push 95 96 - name: Submit metric to Datadog 97 uses: sendgrid/dx-automator/actions/datadog-release-metric@main 98 env: 99 DD_API_KEY: ${{ secrets.DATADOG_API_KEY }} 100 101 notify-on-failure: 102 name: Slack notify on failure 103 if: failure() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref_type == 'tag') 104 needs: [ test, deploy ] 105 runs-on: ubuntu-latest 106 steps: 107 - uses: rtCamp/action-slack-notify@v2 108 env: 109 SLACK_COLOR: failure 110 SLACK_ICON_EMOJI: ':github:' 111 SLACK_MESSAGE: ${{ format('Test *{0}*, Deploy *{1}*, {2}/{3}/actions/runs/{4}', needs.test.result, needs.deploy.result, github.server_url, github.repository, github.run_id) }} 112 SLACK_TITLE: Action Failure - ${{ github.repository }} 113 SLACK_USERNAME: GitHub Actions 114 SLACK_MSG_AUTHOR: twilio-dx 115 SLACK_FOOTER: Posted automatically using GitHub Actions 116 SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} 117 MSG_MINIMAL: true