Skip to content

Sync ISP Function

Sync ISP Function #9

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 temporary file
awk '/function cleanIspInfo/,/^}/' $SOURCE_FILE > /tmp/cleanIspInfo.js
# Iterate over the target files and replace the cleanIspInfo function
for TARGET_FILE in "${TARGET_FILES[@]}"; do
# Remove the existing cleanIspInfo function in the target file
sed -i '/function cleanIspInfo/,/^}/d' $TARGET_FILE
# Append the new cleanIspInfo function to the target file
cat /tmp/cleanIspInfo.js >> $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