|
| 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: Test |
| 16 | + runs-on: ubuntu-latest |
| 17 | + timeout-minutes: 20 |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + node: [ 6, 7, 8, 10, lts/* ] |
| 21 | + steps: |
| 22 | + - name: Checkout sendgrid-nodejs |
| 23 | + uses: actions/checkout@v2 |
| 24 | + |
| 25 | + - name: Login to Docker Hub |
| 26 | + uses: docker/login-action@v1 |
| 27 | + with: |
| 28 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 29 | + password: ${{ secrets.DOCKER_AUTH_TOKEN }} |
| 30 | + |
| 31 | + - name: Set up Node |
| 32 | + uses: actions/setup-node@v2 |
| 33 | + with: |
| 34 | + node-version: ${{ matrix.node }} |
| 35 | + |
| 36 | + - run: npm install |
| 37 | + - name: Run Tests |
| 38 | + run: make test-docker |
| 39 | + |
| 40 | + deploy: |
| 41 | + name: Deploy |
| 42 | + if: success() && github.ref_type == 'tag' |
| 43 | + needs: [ test ] |
| 44 | + runs-on: ubuntu-latest |
| 45 | + steps: |
| 46 | + - name: Checkout sendgrid-nodejs |
| 47 | + uses: actions/checkout@v2 |
| 48 | + with: |
| 49 | + fetch-depth: 0 |
| 50 | + |
| 51 | + - name: Set up Node |
| 52 | + uses: actions/setup-node@v2 |
| 53 | + with: |
| 54 | + node-version: 10 |
| 55 | + |
| 56 | + - name: Create GitHub Release |
| 57 | + uses: sendgrid/dx-automator/actions/release@main |
| 58 | + env: |
| 59 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + |
| 61 | + - run: npm install |
| 62 | + - name: Publish |
| 63 | + run: | |
| 64 | + npm config set //registry.npmjs.org/:_authToken ${NODE_AUTH_TOKEN} |
| 65 | + lerna publish from-package --yes --no-verify-access |
| 66 | + env: |
| 67 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 68 | + |
| 69 | + notify-on-failure: |
| 70 | + name: Slack notify on failure |
| 71 | + if: failure() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref_type == 'tag') |
| 72 | + needs: [ test, deploy ] |
| 73 | + runs-on: ubuntu-latest |
| 74 | + steps: |
| 75 | + - uses: rtCamp/action-slack-notify@v2 |
| 76 | + env: |
| 77 | + SLACK_COLOR: failure |
| 78 | + SLACK_ICON_EMOJI: ':github:' |
| 79 | + SLACK_MESSAGE: ${{ format('Tests *{0}*, Deploy *{1}*, {2}/{3}/actions/runs/{4}', needs.test.result, needs.deploy.result, github.server_url, github.repository, github.run_id) }} |
| 80 | + SLACK_TITLE: Action Failure - ${{ github.repository }} |
| 81 | + SLACK_USERNAME: GitHub Actions |
| 82 | + SLACK_MSG_AUTHOR: twilio-dx |
| 83 | + SLACK_FOOTER: Posted automatically using GitHub Actions |
| 84 | + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
| 85 | + MSG_MINIMAL: true |
0 commit comments