-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
66 lines (58 loc) · 2.45 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
inputs:
folder:
description: folder where the HTMLs (recursively throughout the folder) will be minified. use rel. path (relative to root)
required: false
default: "./_site" # for Jekyll project
runs:
using: composite
steps:
- run: |
import os, re, random, subprocess
## needed
needs = {
'act_repo': os.environ['ENV__action_repository'],
'ver': os.environ['ENV__action_ref'], # the Action version.
}
ACTION_BIO = f"{needs['act_repo']}({needs['ver']})"
## inputs
ipts = {
'folder': os.environ['IPT__folder'],
}
print('─'*99)
print(f"INFO: Running {ACTION_BIO}.")
print(f"DEBUG: (inputs) folder: {ipts['folder']}")
## get the abs.path
ABS_PTH = os.path.normpath(os.path.abspath(os.path.join(os.getcwd(), ipts['folder'])))
print(f"DEBUG: repr(ABS_PTH): {repr(ABS_PTH)}")
## checks
if not os.path.isdir(ABS_PTH): raise AssertionError(f"Not a dir: {repr(ABS_PTH)}")
## minify HTMLs
def main():
def recursing(dir_pth):
for i in os.listdir(dir_pth):
ipth = os.path.join(dir_pth, i)
if os.path.isfile(ipth):
if i.lower().endswith('.html'): # just HTML files
size0 = os.path.getsize(ipth)
subprocess.run([
'html-minifier', ipth,
'--remove-comments',
'--minify-css', 'true', '--minify-js', 'true',
'--remove-attribute-quotes',
'--remove-optional-tags',
'--remove-redundant-attributes',
'--collapse-whitespace',
'--collapse-boolean-attributes',
# '--collapse-inline-tag-whitespace', # not using this, it will remove spaces that shouldnt be removed.
'-o', ipth
])
print(f"INFO: minified: {os.path.relpath(ipth, ABS_PTH)} ({round( 100*(size0-os.path.getsize(ipth))/size0 )}%)")
else: recursing(ipth)
recursing(ABS_PTH)
main()
print(f"─── {ACTION_BIO} finished... {random.choice(['Take care!', 'You are awesome, goodbye.'])}")
shell: python
env:
ENV__action_repository: ${{ github.action_repository }}
ENV__action_ref: ${{ github.action_ref }}
IPT__folder: ${{ inputs.folder }}