Sync ISP Function #4
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版本 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 # 更新到v3版本 | |
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 | |
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 | |
# Use sed to replace the old function with the new one | |
sed -i '/function cleanIspInfo/,/^}/{ | |
r /tmp/cleanIspInfo.js | |
d | |
}' $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 |