-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
95 lines (92 loc) · 3.33 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
# Lighthouse-Badger | GitHub Action
#
# Description: Generates, adds & updates manually/automatically Lighthouse badges & reports from one/multiple input URL-group(s) to one/multiple target repo(s)/branch(es) in parallel
# Author: Sitdisch
# Version: v2.2
# Source: https://github.com/myactionway/lighthouse-badger-action
# License: MIT
# Copyright (c) 2021 Sitdisch
name: 'Lighthouse-Badger'
author: 'Sitdisch'
description: "Generates, adds & updates manually/automatically Lighthouse badges & reports from 1,2... URL(s) to 1,2... repo(s) in parallel"
branding:
icon: bold
color: purple
inputs:
urls:
description: 'URL(s) to be checked'
required: true
badges_args:
description: 'Badges arguments: -b, -l, -o, -r, -s'
default: '-b pagespeed -o lighthouse_results -r'
audit_type:
description: 'Audit type: mobile, desktop, both or both_p'
default: 'both'
mobile_lighthouse_params:
description: 'Lighthouse parameters mobile audit'
default: '--throttling.cpuSlowdownMultiplier=2'
desktop_lighthouse_params:
description: 'Lighthouse parameters desktop audit'
default: '--preset=desktop --throttling.cpuSlowdownMultiplier=1'
user_name:
description: 'User who should commit'
default: 'github-actions[bot]'
user_email:
description: 'User e-mail address'
default: '41898282+github-actions[bot]@users.noreply.github.com'
commit_message:
description: 'Commit message'
default: 'Lighthouse-Badger[bot]: Results Added'
max_push_attempts:
description: 'Maximum number of push attempts'
default: 5
runs:
using: "composite"
steps:
- run: |
RESULTS_PATH=`expr "${{ inputs.badges_args }}" : ".* --\?ou\?t\?p\?u\?t\?-\?p\?a\?t\?h\? \([^ ]*\).*"`;
BADGES_ARGS=$(sed -e "s/ \(\(--output-path\)\|\(-o\)\) \S*//g" <<< "${{ inputs.badges_args }}" );
AUDIT_TYPE=${{ inputs.audit_type }}
declare -A lighthouse_params
lighthouse_params[mobile]="${{ inputs.mobile_lighthouse_params }}"
lighthouse_params[desktop]="${{ inputs.desktop_lighthouse_params }}"
mkdir -p $RESULTS_PATH
cd temp_lighthouse_badges_nested
lighthouse_badger() {
export LIGHTHOUSE_BADGES_PARAMS="${lighthouse_params[$1]}"
./src/index.js -u ${{ inputs.urls }} $BADGES_ARGS -o $RESULTS_PATH/$1
cp -r $RESULTS_PATH/$1 ../$RESULTS_PATH
}
if [[ ${AUDIT_TYPE:0:4} = "both" ]]; then
if [[ ${AUDIT_TYPE:4} = "_p" ]]; then
lighthouse_badger "mobile" &
lighthouse_badger "desktop" &
wait
else
lighthouse_badger "mobile"
lighthouse_badger "desktop"
fi
else
lighthouse_badger "$AUDIT_TYPE"
fi
cd ..
git config --local user.email ${{ inputs.user_email }}
git config --local user.name ${{ inputs.user_name }}
git config --local pull.rebase false
git pull origin ${{ env.BRANCH }}
git add $RESULTS_PATH
git commit -am "${{ inputs.commit_message }}"
i=0
while true; do
{
git push && break
} || {
i=$(( $i + 1 ))
echo $i"th push attempt failed"
if [ $i = ${{ inputs.max_push_attempts }} ]; then
break
fi
git pull origin ${{ env.BRANCH }}
}
done
shell: bash