diff --git a/.github/scripts/publish_greasyfork.sh b/.github/scripts/publish_greasyfork.sh deleted file mode 100644 index ce574ca..0000000 --- a/.github/scripts/publish_greasyfork.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/bash - -set -eu - -AUTH_TOKEN="" - -COOKIE_FILE_PATH="/tmp/cookies.txt" - -BASE_URL="https://greasyfork.org" -# "/en/search" appears to be the lightest -INITIAL_PAGE_PATH="/en/search" - -LOGIN_URL="$BASE_URL/en/users/sign_in?return_to=$INITIAL_PAGE_PATH" -UPDATE_URL="$BASE_URL/en/scripts/$GREASYFORK_SCRIPT_ID/versions" -INITIAL_URL="$BASE_URL$INITIAL_PAGE_PATH" - -case $GREASYFORK_SCRIPT_TYPE in - "public") GREASYFORK_SCRIPT_TYPE=1 ;; - "unlisted") GREASYFORK_SCRIPT_TYPE=2 ;; - "library") GREASYFORK_SCRIPT_TYPE=3 ;; -esac - -request() { - curl -fsSL -b "$COOKIE_FILE_PATH" -c "$COOKIE_FILE_PATH" "$@" -} - -extract_auth_token() { - awk -F '"' '/name="csrf-token"/{print $4}' <<< "$@" -} - -cleanup() { - rm -f "$COOKIE_FILE_PATH" -} - -trap cleanup EXIT - -# Get initial page to retrieve the initial auth token -INITIAL_RESPONSE="$(request "$INITIAL_URL")" -AUTH_TOKEN="$(extract_auth_token "$INITIAL_RESPONSE")" - -# Log in to retrieve the final login auth token -LOGIN_RESPONSE="$(request \ - -d "authenticity_token=$AUTH_TOKEN" \ - -d "user[email]=$GREASYFORK_USER_EMAIL" \ - -d "user[password]=$GREASYFORK_USER_PASS" \ - -d "user[remember_me]=0" \ - -d "commit=Log in" \ - "$LOGIN_URL")" - -# Check if login was successful -if [[ "$LOGIN_RESPONSE" != *"sign-out-link"* ]]; then - echo -e "\e[38;2;103;103;103m$LOGIN_RESPONSE\e[0m\n" - echo -e "\e[1;31mFailed: Sign in\e[0m - Unknown reason" - exit 1 -fi - -# Extract updated authenticity token after successful login -AUTH_TOKEN="$(extract_auth_token "$LOGIN_RESPONSE")" - -# Update the script -SCRIPT_FILE_PATH="$(find . -iwholename "$SCRIPT_FILE_PATH" -print -quit)" -SCRIPT_UPDATE_RESPONSE="$(request \ - -F "authenticity_token=$AUTH_TOKEN" \ - -F "script_version[code]=" \ - -F "code_upload=@$SCRIPT_FILE_PATH" \ - -F "script_version[additional_info][0][attribute_default]=true" \ - -F "script_version[additional_info][0][value_markup]=html" \ - -F "script_version[additional_info][0][attribute_value]=" \ - -F "script_version[attachments][]=" \ - -F "script_version[changelog_markup]=html" \ - -F "script_version[changelog]=" \ - -F "script[script_type]=$GREASYFORK_SCRIPT_TYPE" \ - -F "script[adult_content_self_report]=0" \ - -F "commit=Post new version" \ - "$UPDATE_URL")" - -# Check if the script update was successful -if [[ "$SCRIPT_UPDATE_RESPONSE" != *"id=\"install-area\""* ]]; then - echo -e "\e[38;2;103;103;103m$SCRIPT_UPDATE_RESPONSE\e[0m\n" - if [[ "$SCRIPT_UPDATE_RESPONSE" == *"validation-errors"* ]]; then - echo -e "\e[1;31mFailed: Publish to GreasyFork\e[0m - Validation errors were reported" - else - echo -e "\e[1;31mFailed: Publish to GreasyFork\e[0m - Unknown reason" - fi - exit 1 -fi diff --git a/.github/scripts/publish_to_greasyfork/main.ts b/.github/scripts/publish_to_greasyfork/main.ts new file mode 100644 index 0000000..423ce69 --- /dev/null +++ b/.github/scripts/publish_to_greasyfork/main.ts @@ -0,0 +1,159 @@ +import { readFileSync } from 'fs'; + +async function main() { + const greasyfork_user_email = process.env.GREASYFORK_USER_EMAIL; + if (!greasyfork_user_email) { + throw new Error('Environment variable "GREASYFORK_USER_EMAIL" must be set'); + } + + const greasyfork_user_pass = process.env.GREASYFORK_USER_PASS; + if (!greasyfork_user_pass) { + throw new Error('Environment variable "GREASYFORK_USER_PASS" must be set'); + } + + const greasyfork_script_id = process.env.GREASYFORK_SCRIPT_ID; + if (!greasyfork_script_id) { + throw new Error('Environment variable "GREASYFORK_SCRIPT_ID" must be set'); + } + + const greasyfork_script_type = (() => { + switch (process.env.GREASYFORK_SCRIPT_TYPE) { + case 'public': return '1'; + case 'unlisted': return '2'; + case 'library': return '3'; + } + })(); + if (!greasyfork_script_type) { + throw new Error('Environment variable "GREASYFORK_SCRIPT_TYPE" must be set'); + } + + const script_path_to_upload = process.env.SCRIPT_PATH_TO_UPLOAD; + if (!script_path_to_upload) { + throw new Error('Environment variable "SCRIPT_PATH_TO_UPLOAD" must be set'); + } + + await publish_to_greasyfork(greasyfork_user_email, greasyfork_user_pass, greasyfork_script_id, greasyfork_script_type, script_path_to_upload); +} + +function extract_authenticity_token(text: string): string | null { + const match = text.match(/name="csrf-token" content="([^"]+)"/); + return match ? match[1] : null; +} + +class Cookies { + static cookies: string; + + static set(response: Response) { + this.cookies = response.headers.getSetCookie().join('; '); + } + + static get() { + return this.cookies; + } +} + +async function publish_to_greasyfork(user_email: string, user_pass: string, script_id: string, script_type: string, file_path_to_upload: string) { + const BASE_URL = 'https://greasyfork.org'; + + // "/en/search" appears to be the lightest page + const LIGHTEST_PAGE_URL= `${BASE_URL}/en/search`; + + // Get initial page to retrieve the initial tokens + const initial_response = await fetch(LIGHTEST_PAGE_URL); + + const initial_response_body = await initial_response.text(); + + Cookies.set(initial_response); + let authenticity_token = extract_authenticity_token(initial_response_body); + + if (!authenticity_token) { + throw new Error('Could not retrieve initial authenticity token'); + } + + const login_request_url= `${BASE_URL}/en/users/sign_in`; + + const login_request_options: RequestInit = { + method: 'POST', + headers: { 'Cookie': Cookies.get() }, + body: new URLSearchParams({ + 'authenticity_token': authenticity_token, + 'user[email]': user_email, + 'user[password]': user_pass, + 'user[remember_me]': '0', + 'commit': 'Log in', + }), + redirect: 'manual', + }; + + // Log in to retrieve the final login tokens + const login_response = await fetch(login_request_url, login_request_options); + + Cookies.set(login_response); + + if (login_response.ok) { + const login_response_body = await login_response.text(); + if (login_response_body.includes('class="alert">Invalid')) { + console.log('\x1b[1;31mFailed: Sign in\x1b[0m - Incorrect Email or password'); + } else { + console.log(`\x1b[1;31mFailed: Sign in\x1b[0m - Unknown reason`); + } + process.exitCode = 1; + return; + } else if (login_response.status >= 300 && login_response.status < 400) { + const redirect_response = await fetch(LIGHTEST_PAGE_URL, { + headers: { 'Cookie': Cookies.get() }, + }); + + const redirect_response_body = await redirect_response.text(); + + Cookies.set(redirect_response); + authenticity_token = extract_authenticity_token(redirect_response_body); + } else { + console.log(`\x1b[1;31mFailed: Sign in\x1b[0m - ${login_response.status} ${login_response.statusText}`); + process.exitCode = 1; + return; + } + + const script_file_blob = new Blob([readFileSync(file_path_to_upload)]); + + const update_body = new FormData(); + update_body.set('authenticity_token', authenticity_token); + update_body.set('script_version[code]', ''); + update_body.set('code_upload', script_file_blob); + update_body.set('script_version[additional_info][0][attribute_default]', 'true'); + update_body.set('script_version[additional_info][0][value_markup]', 'html'); + update_body.set('script_version[additional_info][0][attribute_value]', ''); + update_body.set('script_version[attachments][]', ''); + update_body.set('script_version[changelog_markup]', 'html'); + update_body.set('script_version[changelog]', ''); + update_body.set('script[script_type]', script_type); + update_body.set('script[adult_content_self_report]', '0'); + update_body.set('commit', 'Post new version'); + + const upload_request_url= `${BASE_URL}/en/scripts/${script_id}/versions`; + + const upload_request_options: RequestInit = { + method: 'POST', + headers: { 'Cookie': Cookies.get() }, + body: update_body, + }; + + const upload_response = await fetch(upload_request_url, upload_request_options); + + const upload_response_body = await upload_response.text(); + + // Check if the upload was successful + if (!upload_response_body.includes('id="install-area"')) { + console.log(`\x1b[38;2;103;103;103m${upload_response_body}\x1b[0m`); + if (upload_response_body.includes('validation-errors')) { + console.log('\x1b[1;31mFailed: Publish to GreasyFork\x1b[0m - Validation errors were reported'); + } else { + console.log('\x1b[1;31mFailed: Publish to GreasyFork\x1b[0m - Unknown reason'); + } + + process.exitCode = 1; + return; + } +} + +main(); diff --git a/.github/scripts/publish_to_greasyfork/package-lock.json b/.github/scripts/publish_to_greasyfork/package-lock.json new file mode 100644 index 0000000..44f5d5b --- /dev/null +++ b/.github/scripts/publish_to_greasyfork/package-lock.json @@ -0,0 +1,484 @@ +{ + "name": "publish-to-greasyfork", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "publish-to-greasyfork", + "version": "0.0.0", + "devDependencies": { + "@types/node": "22.2.0", + "esbuild": "0.23.0" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.23.0.tgz", + "integrity": "sha512-3sG8Zwa5fMcA9bgqB8AfWPQ+HFke6uD3h1s3RIwUNK8EG7a4buxvuFTs3j1IMs2NXAk9F30C/FF4vxRgQCcmoQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.23.0.tgz", + "integrity": "sha512-+KuOHTKKyIKgEEqKbGTK8W7mPp+hKinbMBeEnNzjJGyFcWsfrXjSTNluJHCY1RqhxFurdD8uNXQDei7qDlR6+g==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.23.0.tgz", + "integrity": "sha512-EuHFUYkAVfU4qBdyivULuu03FhJO4IJN9PGuABGrFy4vUuzk91P2d+npxHcFdpUnfYKy0PuV+n6bKIpHOB3prQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.23.0.tgz", + "integrity": "sha512-WRrmKidLoKDl56LsbBMhzTTBxrsVwTKdNbKDalbEZr0tcsBgCLbEtoNthOW6PX942YiYq8HzEnb4yWQMLQuipQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.23.0.tgz", + "integrity": "sha512-YLntie/IdS31H54Ogdn+v50NuoWF5BDkEUFpiOChVa9UnKpftgwzZRrI4J132ETIi+D8n6xh9IviFV3eXdxfow==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.23.0.tgz", + "integrity": "sha512-IMQ6eme4AfznElesHUPDZ+teuGwoRmVuuixu7sv92ZkdQcPbsNHzutd+rAfaBKo8YK3IrBEi9SLLKWJdEvJniQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.23.0.tgz", + "integrity": "sha512-0muYWCng5vqaxobq6LB3YNtevDFSAZGlgtLoAc81PjUfiFz36n4KMpwhtAd4he8ToSI3TGyuhyx5xmiWNYZFyw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.23.0.tgz", + "integrity": "sha512-XKDVu8IsD0/q3foBzsXGt/KjD/yTKBCIwOHE1XwiXmrRwrX6Hbnd5Eqn/WvDekddK21tfszBSrE/WMaZh+1buQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.23.0.tgz", + "integrity": "sha512-SEELSTEtOFu5LPykzA395Mc+54RMg1EUgXP+iw2SJ72+ooMwVsgfuwXo5Fn0wXNgWZsTVHwY2cg4Vi/bOD88qw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.23.0.tgz", + "integrity": "sha512-j1t5iG8jE7BhonbsEg5d9qOYcVZv/Rv6tghaXM/Ug9xahM0nX/H2gfu6X6z11QRTMT6+aywOMA8TDkhPo8aCGw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.23.0.tgz", + "integrity": "sha512-P7O5Tkh2NbgIm2R6x1zGJJsnacDzTFcRWZyTTMgFdVit6E98LTxO+v8LCCLWRvPrjdzXHx9FEOA8oAZPyApWUA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.23.0.tgz", + "integrity": "sha512-InQwepswq6urikQiIC/kkx412fqUZudBO4SYKu0N+tGhXRWUqAx+Q+341tFV6QdBifpjYgUndV1hhMq3WeJi7A==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.23.0.tgz", + "integrity": "sha512-J9rflLtqdYrxHv2FqXE2i1ELgNjT+JFURt/uDMoPQLcjWQA5wDKgQA4t/dTqGa88ZVECKaD0TctwsUfHbVoi4w==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.23.0.tgz", + "integrity": "sha512-cShCXtEOVc5GxU0fM+dsFD10qZ5UpcQ8AM22bYj0u/yaAykWnqXJDpd77ublcX6vdDsWLuweeuSNZk4yUxZwtw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.23.0.tgz", + "integrity": "sha512-HEtaN7Y5UB4tZPeQmgz/UhzoEyYftbMXrBCUjINGjh3uil+rB/QzzpMshz3cNUxqXN7Vr93zzVtpIDL99t9aRw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.23.0.tgz", + "integrity": "sha512-WDi3+NVAuyjg/Wxi+o5KPqRbZY0QhI9TjrEEm+8dmpY9Xir8+HE/HNx2JoLckhKbFopW0RdO2D72w8trZOV+Wg==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.23.0.tgz", + "integrity": "sha512-a3pMQhUEJkITgAw6e0bWA+F+vFtCciMjW/LPtoj99MhVt+Mfb6bbL9hu2wmTZgNd994qTAEw+U/r6k3qHWWaOQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.23.0.tgz", + "integrity": "sha512-cRK+YDem7lFTs2Q5nEv/HHc4LnrfBCbH5+JHu6wm2eP+d8OZNoSMYgPZJq78vqQ9g+9+nMuIsAO7skzphRXHyw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.23.0.tgz", + "integrity": "sha512-suXjq53gERueVWu0OKxzWqk7NxiUWSUlrxoZK7usiF50C6ipColGR5qie2496iKGYNLhDZkPxBI3erbnYkU0rQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.23.0.tgz", + "integrity": "sha512-6p3nHpby0DM/v15IFKMjAaayFhqnXV52aEmv1whZHX56pdkK+MEaLoQWj+H42ssFarP1PcomVhbsR4pkz09qBg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.23.0.tgz", + "integrity": "sha512-BFelBGfrBwk6LVrmFzCq1u1dZbG4zy/Kp93w2+y83Q5UGYF1d8sCzeLI9NXjKyujjBBniQa8R8PzLFAUrSM9OA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.23.0.tgz", + "integrity": "sha512-lY6AC8p4Cnb7xYHuIxQ6iYPe6MfO2CC43XXKo9nBXDb35krYt7KGhQnOkRGar5psxYkircpCqfbNDB4uJbS2jQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.23.0.tgz", + "integrity": "sha512-7L1bHlOTcO4ByvI7OXVI5pNN6HSu6pUQq9yodga8izeuB1KcT2UkHaH6118QJwopExPn0rMHIseCTx1CRo/uNA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.23.0.tgz", + "integrity": "sha512-Arm+WgUFLUATuoxCJcahGuk6Yj9Pzxd6l11Zb/2aAuv5kWWvvfhLFo2fni4uSK5vzlUdCGZ/BdV5tH8klj8p8g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@types/node": { + "version": "22.2.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.2.0.tgz", + "integrity": "sha512-bm6EG6/pCpkxDf/0gDNDdtDILMOHgaQBVOJGdwsqClnxA3xL6jtMv76rLBc006RVMWbmaf0xbmom4Z/5o2nRkQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.13.0" + } + }, + "node_modules/esbuild": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.0.tgz", + "integrity": "sha512-1lvV17H2bMYda/WaFb2jLPeHU3zml2k4/yagNMG8Q/YtfMjCwEUZa2eXXMgZTVSL5q1n4H7sQ0X6CdJDqqeCFA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.23.0", + "@esbuild/android-arm": "0.23.0", + "@esbuild/android-arm64": "0.23.0", + "@esbuild/android-x64": "0.23.0", + "@esbuild/darwin-arm64": "0.23.0", + "@esbuild/darwin-x64": "0.23.0", + "@esbuild/freebsd-arm64": "0.23.0", + "@esbuild/freebsd-x64": "0.23.0", + "@esbuild/linux-arm": "0.23.0", + "@esbuild/linux-arm64": "0.23.0", + "@esbuild/linux-ia32": "0.23.0", + "@esbuild/linux-loong64": "0.23.0", + "@esbuild/linux-mips64el": "0.23.0", + "@esbuild/linux-ppc64": "0.23.0", + "@esbuild/linux-riscv64": "0.23.0", + "@esbuild/linux-s390x": "0.23.0", + "@esbuild/linux-x64": "0.23.0", + "@esbuild/netbsd-x64": "0.23.0", + "@esbuild/openbsd-arm64": "0.23.0", + "@esbuild/openbsd-x64": "0.23.0", + "@esbuild/sunos-x64": "0.23.0", + "@esbuild/win32-arm64": "0.23.0", + "@esbuild/win32-ia32": "0.23.0", + "@esbuild/win32-x64": "0.23.0" + } + }, + "node_modules/undici-types": { + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.13.0.tgz", + "integrity": "sha512-xtFJHudx8S2DSoujjMd1WeWvn7KKWFRESZTMeL1RptAYERu29D6jphMjjY+vn96jvN3kVPDNxU/E13VTaXj6jg==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/.github/scripts/publish_to_greasyfork/package.json b/.github/scripts/publish_to_greasyfork/package.json new file mode 100644 index 0000000..8f697f9 --- /dev/null +++ b/.github/scripts/publish_to_greasyfork/package.json @@ -0,0 +1,16 @@ +{ + "name": "publish-to-greasyfork", + "version": "0.0.0", + "private": true, + "type": "module", + "scripts": { + "build": "esbuild main.ts --bundle --outdir=dist --platform=node --format=esm --sourcemap" + }, + "engines": { + "node": ">=20" + }, + "devDependencies": { + "@types/node": "22.2.0", + "esbuild": "0.23.0" + } +} diff --git a/.github/scripts/publish_to_greasyfork/tsconfig.json b/.github/scripts/publish_to_greasyfork/tsconfig.json new file mode 100644 index 0000000..734e23f --- /dev/null +++ b/.github/scripts/publish_to_greasyfork/tsconfig.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "compilerOptions": { + "lib": ["ESNext"], + "module": "NodeNext", + + "strict": true, + } + } diff --git a/.github/workflows/publish_to_greasyfork.yml b/.github/workflows/publish_to_greasyfork.yml new file mode 100644 index 0000000..17dfdde --- /dev/null +++ b/.github/workflows/publish_to_greasyfork.yml @@ -0,0 +1,41 @@ +name: Publish to GreasyFork + +on: + workflow_dispatch: + workflow_call: + +jobs: + publish_to_greasyfork: + name: Publish to GreasyFork + runs-on: ubuntu-latest + + defaults: + run: + working-directory: ./.github/scripts/publish_to_greasyfork + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: lts/* + + - name: Install dependencies + run: npm ci + + - name: Build + run: npm run build + + - name: Publish to GreasyFork + run: node dist/main.js --enable-source-maps + env: + GREASYFORK_USER_EMAIL: ${{ secrets.GREASYFORK_USER_EMAIL }} + GREASYFORK_USER_PASS: ${{ secrets.GREASYFORK_USER_PASS }} + GREASYFORK_SCRIPT_ID: '423851' + # public - for all to see and use. + # unlisted - for (semi-)private use. Available by direct access, but not linked to from anywhere on Greasy Fork. + # library - intended to be @require-d from other scripts and not installed directly. + GREASYFORK_SCRIPT_TYPE: public + SCRIPT_PATH_TO_UPLOAD: ${{ github.workspace }}/dist/Simple-YouTube-Age-Restriction-Bypass.user.js diff --git a/.github/workflows/release_and_publish.yml b/.github/workflows/release_and_publish.yml index 09c929d..5217989 100644 --- a/.github/workflows/release_and_publish.yml +++ b/.github/workflows/release_and_publish.yml @@ -15,17 +15,19 @@ env: USERSCRIPT_FILE_PATH: dist/Simple-YouTube-Age-Restriction-Bypass.user.js jobs: - release_and_publish: + release: + name: Release runs-on: ubuntu-latest + steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.event.release.target_commitish }} fetch-depth: 0 - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: lts/* @@ -40,7 +42,7 @@ jobs: run: npm run build - name: Upload assets to GitHub release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: files: | ${{ env.USERSCRIPT_FILE_PATH }} @@ -67,16 +69,10 @@ jobs: git tag -f "$TAG_NAME" git push -f origin "$TAG_NAME" - - name: Publish on GreasyFork - # Prevent running this in forks and also if this is a prerelease - if: github.event.repository.fork == false && github.event.release.prerelease == false - env: - GREASYFORK_USER_EMAIL: ${{ secrets.GREASYFORK_USER_EMAIL }} - GREASYFORK_USER_PASS: ${{ secrets.GREASYFORK_USER_PASS }} - GREASYFORK_SCRIPT_ID: "423851" - # public - for all to see and use. - # unlisted - for (semi-)private use. Available by direct access, but not linked to from anywhere on Greasy Fork. - # library - intended to be @require-d from other scripts and not installed directly. - GREASYFORK_SCRIPT_TYPE: public - SCRIPT_FILE_PATH: ./${{ env.USERSCRIPT_FILE_PATH }} - run: bash ./.github/scripts/publish_greasyfork.sh + publish: + name: Publish to GreasyFork + needs: release + # Prevent running this in forks and also if this is a prerelease + if: github.event.repository.fork == false && github.event.release.prerelease == false + uses: ./.github/workflows/publish_to_greasyfork.yml + secrets: inherit