-
Notifications
You must be signed in to change notification settings - Fork 2
61 lines (53 loc) · 2.37 KB
/
test.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
name: Build and Test
on:
pull_request:
types: [opened, reopened, synchronize]
branches: [prod]
jobs:
build:
runs-on: ubuntu-22.04
# Because the testing job is different, we need to out the Netlify URL so we can access it in another job
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idoutputs
outputs:
deploy_url: ${{steps.build_site.outputs.NETLIFY_URL}}
steps:
- name: Checkout Repo Code
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install Node Modules
run: npm install
- name: Deploy to Netlify
id: build_site
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
run: ./_actions/netlify_deploy.sh
- uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'The build works! You can view the deploy preview at ${{steps.build_site.outputs.NETLIFY_URL}}'
})
# Creating a new job for the tests to run in
test:
# Because the website has to have built first, we're defining a dependency on the `needs` property, that the test job needs to have the build job complete first
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idneeds
needs: build
runs-on: ubuntu-22.04
steps:
# Jobs run in their own separate environments, so we need to checkout the repo code again so we can run tests that are defined in the repo
- name: Checkout Repo Code
uses: actions/checkout@v3
- name: Percy Test
env:
# To authenticate, Percy will look for the PERCY_TOKEN env variable, so we can pass the secret through as an environment variable similarly to in the Netlify script previously
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
# We'll pass the deploy URL in as an output of the build job
# https://docs.github.com/en/actions/learn-github-actions/contexts#needs-context
run: npx @percy/cli snapshot snapshots.yml --base-url ${{ needs.build.outputs.deploy_url }}