Repository navigation
123 lines (108 loc) · 3.44 KB
/
Copy pathencode.yml
File metadata and controls
123 lines (108 loc) · 3.44 KB
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
name: Encode & Obfuscate Worker
on:
push:
branches:
- main
- master
paths:
- 'worker.js'
- 'src/**'
- 'worker_convertor.py'
- 'package.json'
- '.github/workflows/encode.yml'
pull_request:
branches:
- main
- master
paths:
- 'worker.js'
- 'src/**'
- 'worker_convertor.py'
- 'package.json'
workflow_dispatch:
inputs:
bundle_single_file:
description: 'Bundle all modules into a single standalone worker.encoded.js'
required: true
type: boolean
default: true
encode_all_modules:
description: 'Encode all modular files into dist_encoded directory'
required: true
type: boolean
default: true
commit_changes:
description: 'Commit and push encoded files back to repository'
required: true
type: boolean
default: true
permissions:
contents: write
jobs:
build-and-encode:
name: Build, Bundle & Encode
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
if [ -f package-lock.json ]; then
npm ci
else
npm install
fi
- name: Validate source code syntax
run: npm run build
- name: Encode Worker (Standalone Bundle)
if: ${{ github.event_name != 'workflow_dispatch' || inputs.bundle_single_file }}
run: |
echo "Bundling modular worker and encoding into worker.encoded.js..."
python3 worker_convertor.py encode --bundle -o worker.encoded.js
- name: Encode All Modules (Modular Architecture)
if: ${{ github.event_name != 'workflow_dispatch' || inputs.encode_all_modules }}
run: |
echo "Encoding all modular files into dist_encoded/..."
python3 worker_convertor.py encode --all -o dist_encoded
- name: Verify encoded worker syntax
run: |
if [ -f worker.encoded.js ]; then
echo "Verifying syntax of worker.encoded.js..."
node --check worker.encoded.js
echo "worker.encoded.js syntax verified successfully!"
fi
- name: Upload Encoded Artifacts
uses: actions/upload-artifact@v4
with:
name: encoded-worker
path: |
worker.encoded.js
dist_encoded/
if-no-files-found: warn
- name: Commit and push changes
if: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.commit_changes) }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add worker.encoded.js
if [ -d dist_encoded ]; then
git add dist_encoded
fi
if git diff --staged --quiet; then
echo "No changes in encoded files to commit."
else
git commit -m "chore(build): update encoded worker [skip ci]"
git push
echo "Encoded files pushed to repository."
fi