Skip to content

update

update #8

Workflow file for this run

name: update
on:
workflow_dispatch:
schedule:
- cron: '0 2 * * 0'
repository_dispatch:
types: [update]
push:
branches: [main]
paths:
- '/123pan/123pan.py'
- '/choose/main.py'
env:
WEBDAV_URL: ${{ secrets.WEBDAV_URL }}
WEBDAV_ACCOUNT: ${{ secrets.WEBDAV_ACCOUNT }}
WEBDAV_PASSWORD: ${{ secrets.WEBDAV_PASSWORD }}
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: Set up Python
uses: actions/setup-python@main
with:
python-version: '3.x'
- name: Install dependencies
run: |
python3 -m pip install requests
- name: checkout
id: checkout
shell: bash
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
wget -O ./docs/packages.json https://api.foojay.io/disco/v3.0/packages
git add -A
if git diff-index --quiet HEAD; then
# No changes
echo 'changed=false' >> $GITHUB_OUTPUT
else
# Changes detected
echo 'changed=true' >> $GITHUB_OUTPUT
fi
- name: update pages
if: steps.checkout.outputs.changed == 'true'
shell: bash
run: |
cd ./docs
rm -rf ./choose
python3 ./main.py
cd ../
git add -A
git commit -m "↑updata↑"
- name: Push changes to GitHub
if: steps.checkout.outputs.changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: update 123pan and push changes to 123pan
if: steps.checkout.outputs.changed == 'true'
shell: bash
run: |
# 拷贝一份 docs 的文件到 123pan目录
cp -r ./docs/* ./123pan/
cd ./123pan
python3 ./123pan.py
cd ../
echo "Deleting existing files from WebDAV..."
curl -u "${WEBDAV_ACCOUNT}:${WEBDAV_PASSWORD}" -X PROPFIND "${WEBDAV_URL}/PCL2-java_download_page/" | \
grep '<D:href>' | \
sed 's/.*<D:href>\(.*\)<\/D:href>.*/\1/' | \
while read -r path; do
if [[ "$path" != "${WEBDAV_URL}/PCL2-java_download_page/" ]]; then
curl -u "${WEBDAV_ACCOUNT}:${WEBDAV_PASSWORD}" -X DELETE "${WEBDAV_URL}${path}"
fi
done
echo "Uploading files to WebDAV..."
find ./123pan -type f | while read -r file; do
remote_path="${WEBDAV_URL}/PCL2-java_download_page/${file#./123pan/}"
curl -u "${WEBDAV_ACCOUNT}:${WEBDAV_PASSWORD}" --create-dirs -T "$file" "$remote_path"
done