Test change #5
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Obfuscate and Push to Main | |
on: | |
push: | |
branches: | |
- dev | |
paths: | |
- '*.html' | |
- '*.js' | |
- '*.css' | |
jobs: | |
obfuscate-to-main: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.PAT }} | |
ref: dev | |
fetch-depth: 0 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Install dependencies | |
run: | | |
npm install html-minifier-terser --save-dev | |
npm install javascript-obfuscator --save-dev | |
- name: Process HTML | |
run: | | |
if [ -f "index.html" ]; then | |
# Process the HTML file | |
node -e ' | |
const fs = require("fs"); | |
const minify = require("html-minifier-terser").minify; | |
const JavaScriptObfuscator = require("javascript-obfuscator"); | |
async function processHtml() { | |
try { | |
let html = fs.readFileSync("index.html", "utf8"); | |
// Extract and obfuscate inline scripts | |
html = html.replace(/<script>([\s\S]*?)<\/script>/g, (match, script) => { | |
if (script.trim()) { | |
const obfuscated = JavaScriptObfuscator.obfuscate(script, { | |
compact: true, | |
controlFlowFlattening: true, | |
controlFlowFlatteningThreshold: 0.75, | |
deadCodeInjection: true, | |
deadCodeInjectionThreshold: 0.4, | |
debugProtection: true, | |
debugProtectionInterval: 2000, | |
disableConsoleOutput: false, | |
identifierNamesGenerator: "hexadecimal", | |
numbersToExpressions: true, | |
renameGlobals: false, | |
rotateStringArray: true, | |
selfDefending: true, | |
splitStrings: true, | |
stringArray: true, | |
stringArrayEncoding: ["base64"], | |
stringArrayThreshold: 0.75 | |
}); | |
return `<script>${obfuscated.getObfuscatedCode()}</script>`; | |
} | |
return match; | |
}); | |
// Add devtools protection | |
const protection = ` | |
<script> | |
(function(){ | |
let d = false; | |
setInterval(() => { | |
const w = window.outerWidth - window.innerWidth > 160; | |
const h = window.outerHeight - window.innerHeight > 160; | |
if(w || h !== d) { | |
d = w || h; | |
if(d) document.body.innerHTML = ""; | |
} | |
}, 1000); | |
})(); | |
</script> | |
`; | |
// Minify everything | |
const minified = await minify(protection + html, { | |
collapseWhitespace: true, | |
removeComments: true, | |
removeAttributeQuotes: true, | |
removeEmptyAttributes: true, | |
removeRedundantAttributes: true, | |
removeScriptTypeAttributes: true, | |
removeStyleLinkTypeAttributes: true, | |
minifyJS: true, | |
minifyCSS: true, | |
minifyURLs: true | |
}); | |
fs.writeFileSync("index.html", minified); | |
} catch (error) { | |
console.error("Error processing HTML:", error); | |
process.exit(1); | |
} | |
} | |
processHtml(); | |
' | |
else | |
echo "index.html not found" | |
exit 1 | |
fi | |
- name: Push to main | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
# Add and commit changes | |
git add . | |
git commit -m "Deploy obfuscated version from dev [skip ci]" || echo "No changes to commit" | |
# Force push to main | |
git push -f origin HEAD:main |