Update IP-1.js #5
This file contains 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: Sync ISP Function | |
on: | |
push: | |
paths: | |
- 'Module/Panel/IP-info/Moore/IP-1.js' | |
workflow_dispatch: # 允许手动触发 | |
jobs: | |
sync-function: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 # 使用v3版本的actions/checkout将代码检出 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 # 使用v3版本的actions/setup-node设置Node.js环境 | |
with: | |
node-version: '20' # 安装Node.js 20 | |
- name: Sync ISP function to other files | |
run: | | |
# Define the file paths | |
SOURCE_FILE="Module/Panel/IP-info/Moore/IP-1.js" | |
TARGET_FILES=("Module/Panel/IP-info/Moore/IP-2.js" "Module/Panel/IP-info/Moore/IP-3.js" "Module/Panel/IP-info/Moore/IP-4.js") | |
# Extract the cleanIspInfo function from the source file and save to a variable | |
FUNCTION_CODE=$(awk '/function cleanIspInfo/,/^}/' $SOURCE_FILE) | |
# Iterate over the target files and replace the cleanIspInfo function | |
for TARGET_FILE in "${TARGET_FILES[@]}"; do | |
# Use awk to replace the old function with the new one | |
awk -v new_func="$FUNCTION_CODE" ' | |
BEGIN {found=0} | |
/function cleanIspInfo/ {found=1; print new_func; next} | |
found && /^}/ {found=0; next} | |
!found' $TARGET_FILE > tmp && mv tmp $TARGET_FILE | |
done | |
# Check if there are any changes | |
if [ -n "$(git status --porcelain)" ]; then | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add . | |
git commit -m "Sync cleanIspInfo function from IP-1.js to IP-2.js, IP-3.js, IP-4.js" | |
git push | |
else | |
echo "No changes detected" | |
fi |