77 lines (67 loc) · 2.79 KB
/
e2e-tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Testes E2E
on: [deployment_status]
jobs:
mark-commit-status-pending:
name: Marcar "status" do commit como "pending"
if: github.event.deployment_status.state == 'pending'
runs-on: ubuntu-latest
steps:
- name: Fazer request contra API do Github com status "pending"
run: |
curl -L -X POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"state": "pending",
"context": "e2e-tests",
"description": "Aguardando a Preview URL da Zeit"
}'
e2e-tests:
name: Rodar testes E2E contra a Preview URL da Zeit
if: github.event.deployment_status.state == 'success'
runs-on: ubuntu-latest
steps:
- name: Atualizar o status "pending" com o "Workflow URL"
run: |
GITHUB_WORKFLOW_URL=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
curl -L -X POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"state": "pending",
"context": "e2e-tests",
"description": "Realizando testes E2E contra a Preview URL",
"target_url": "'${GITHUB_WORKFLOW_URL}'"
}'
- name: Puxar o código do commit
uses: actions/checkout@v2
- name: Instalar o Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Instalar as dependências do npm
run: npm install
- name: Rodar testes utilizando a Preview URL da Zeit
run: npm test
env:
NODE_ENV: 'ci'
PREVIEW_URL: ${{ github.event.deployment_status.target_url }}
- name: Fazer request contra API do Github status final
if: always()
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: |
GITHUB_WORKFLOW_URL=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
JOB_STATUS=$(echo ${JOB_CONTEXT} | jq --raw-output '.status | ascii_downcase')
curl -L -X POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"state": "'${JOB_STATUS}'",
"context": "e2e-tests",
"description": "Finalizados os testes E2E contra a Preview URL.",
"target_url": "'${GITHUB_WORKFLOW_URL}'"
}'