update #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: update | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 2 * * *' | |
repository_dispatch: | |
types: [update] | |
push: | |
branches: [main] | |
paths: | |
- '*.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 | |
wget -O ./123pan/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 | |
- name: update 123pan | |
if: steps.checkout.outputs.changed == 'true' | |
shell: bash | |
run: | | |
cd ./123pan | |
rm -rf ./choose | |
python3 ./main.py | |
cd ../ | |
git add -A | |
- name: commit | |
if: steps.checkout.outputs.changed == 'true' | |
shell: bash | |
run: | | |
git commit -m "update" | |
- 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: Push changes to 123pan | |
if: steps.checkout.outputs.changed == 'true' | |
shell: bash | |
run: | | |
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 |