-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
action.yml
149 lines (135 loc) · 4.94 KB
/
action.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Update playwright snapshots on PR
description: |
Update the playwright snapshots on PR by pushing a commit (and upload them as artifact).
The remote repository containing the PR branch must be checked out
using `https`. If you are using the GitHub `hub` CLI, you can
achieve that using `git config --global hub.protocol https`
inputs:
# Mandatory inputs
github_token:
description: "The GitHub token to use, must have pull_request:write access"
required: true
test_folder:
description: The folder defining the playwright tests
required: true
# Optional inputs
npm_client:
description: The command to execute the scripts (yarn, npm, jlpm)
required: false
default: yarn
server_url:
description: The server URL to wait for (see https://github.com/iFaxity/wait-on-action `resource`)
required: false
default: http-get://localhost:8888
artifact_name:
description: The uploaded snapshots artifact name
required: false
default: playwright-snapshots
report_name:
description: The uploaded report artifact name
required: false
default: playwright-report
browser:
description: The playwright browser to install (one of [`chromium`, `firefox`, `webkit`])
required: false
default: chromium
continue_on_error:
description: Whether to continue on error when updating snapshots or not (one of [`yes`, `no`]).
required: false
default: yes
dry_run:
description: Whether this is a dry run (one of [`yes`, `no`])
required: false
default: no
git_username:
description: The Git Username to Use for the Commit
required: false
default: github-actions[bot]
git_email:
description: The Git Email to Use for the Commit
required: false
default: github-actions[bot]@users.noreply.github.com
start_server_script:
description: The script to execute to start the server; set it to `null` if Playwright is handling it.
required: false
default: start
update_script:
description: The script to execute to update the snapshots
required: false
default: test:update
runs:
using: composite
steps:
- name: Start the server
if: ${{ inputs.start_server_script != 'null' }}
working-directory: ${{ inputs.test_folder }}
shell: bash -l {0}
run: (${{ inputs.npm_client }} run ${{ inputs.start_server_script }} 1>/tmp/snapshots-update-server.log 2>&1) &
- name: Setup integration tests
shell: bash -l {0}
working-directory: ${{ inputs.test_folder }}
run: |
${{ inputs.npm_client }} install
# Force installing the dependencies
npx playwright install-deps || true
${{ inputs.npm_client }} run playwright install ${{ inputs.chromium }}
- name: Wait for the server
if: ${{ inputs.start_server_script != 'null' }}
uses: ifaxity/wait-on-action@v1
with:
resource: ${{ inputs.server_url }}
timeout: 360000
- name: Generate new snapshots
# Get as much update as possible
continue-on-error: ${{ inputs.continue_on_error == 'yes' }}
shell: bash -l {0}
working-directory: ${{ inputs.test_folder }}
run: ${{ inputs.npm_client }} run ${{ inputs.update_script }}
- name: Compress snapshots
if: ${{ runner.os == 'Linux' }}
shell: bash -l {0}
working-directory: ${{ inputs.test_folder }}
run: |
sudo apt install optipng
# Apply compression only on new and modified versioned files
# - this does not filter out deleted files but it should not happen.
echo "::group::Optimize PNG files"
git ls-files --exclude-standard -om | grep -e "\.png$" | xargs optipng
echo "::endgroup::"
- name: Upload snapshots as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact_name }}
path: ${{ inputs.test_folder }}/**/*-snapshots/*.*
- name: Upload report as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.report_name }}
path: ${{ inputs.test_folder }}/playwright-report
- name: Commit new snapshots
shell: bash -l {0}
working-directory: ${{ inputs.test_folder }}
run: |
git config user.name '${{ inputs.git_username }}'
git config user.email '${{ inputs.git_email }}'
git pull --no-tags
git add ./*-snapshots/*.*
git commit -m "Update Playwright Snapshots"
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
- name: Push new snapshots
if: ${{ inputs.dry_run != 'yes' }}
shell: bash -l {0}
working-directory: ${{ inputs.test_folder }}
run: |
git config push.default upstream
git push
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
- name: Server log
if: ${{ inputs.start_server_script != 'null' && always() }}
shell: bash -l {0}
run: |
echo "::group::Server log"
cat /tmp/snapshots-update-server.log
echo "::endgroup::"