Get Bing Wallpaper #570
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: Get Bing Wallpaper | |
on: | |
schedule: | |
- cron: '0 7 * * *' # 每天下午3点运行 (北京时间) | |
push: | |
paths: | |
- '.github/**' # 监听 .github 文件夹的修改 | |
workflow_dispatch: # 添加 workflow_dispatch 触发器,手动触发工作流程 | |
jobs: | |
get_today_wallpaper: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Install jq | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y jq | |
- name: Get Date | |
run: | | |
echo "YEAR=$(date +%Y)" >> $GITHUB_ENV | |
echo "MONTH=$(date +%m)" >> $GITHUB_ENV | |
- name: Create folders | |
run: | | |
mkdir -p "wallpapers/${{ env.YEAR }}/${{ env.MONTH }}" | |
- name: Download Today's Bing Wallpaper | |
run: | | |
IMAGE_URL=$(curl -sL "https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US" | jq -r '.images[0].url') | |
FULL_IMAGE_URL="https://www.bing.com${IMAGE_URL/1920x1080/UHD}" | |
FILENAME=$(date +'%Y%m%d').jpg | |
echo "Downloading Bing Wallpaper: $FULL_IMAGE_URL" | |
wget -q -O "$FILENAME" "$FULL_IMAGE_URL" | |
mv "$FILENAME" "wallpapers/${{ env.YEAR }}/${{ env.MONTH }}/$FILENAME" | |
- name: Check for changes | |
id: check_changes | |
run: | | |
if git diff --quiet; then | |
echo "No changes to commit. Exiting workflow." | |
exit 0 | |
fi | |
- name: 提交并推送更改 | |
if: steps.check_changes.outputs.result != 'true' | |
run: | | |
git config --local user.email "[email protected]" # 替换为您的 GitHub 邮箱地址 | |
git config --local user.name "RashidaKAKU" # 替换为您的 GitHub 用户名 | |
git add wallpapers/* | |
if git diff --cached --quiet; then | |
echo "No changes to commit. Exiting workflow." | |
exit 0 | |
else | |
git commit -m "添加必应壁纸 $(date +'%Y/%m/%d')" | |
git push origin main # 假设主分支为 main,请根据实际情况替换为您的主分支名称 | |
fi |