Update release.yml #24
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: Generate Rules for Clash | ||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- '*.txt' | ||
- '.github/workflows/**' | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Generate rules.txt file | ||
run: | | ||
# 设置环境变量 | ||
echo "RELEASE_NAME=Released on $(date +%Y.%m.%d-%H:%M)" >> $GITHUB_ENV | ||
echo "TAG_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV | ||
# 打印出$GITHUB_REPOSITORY的值以便检查 | ||
echo "GITHUB_REPOSITORY: $GITHUB_REPOSITORY" | ||
# 下载*rules.txt文件 | ||
mkdir -p publish # 使用 -p 选项以确保目录存在时不会报错 | ||
for file in $(find "$PWD" -name "*DIY-*.txt" -type f); do | ||
echo "Found file: $file" | ||
# 打印出将要使用的URL | ||
url="https://raw.githubusercontent.com/$GITHUB_REPOSITORY/main/${file#$PWD/}" | ||
echo "Downloading from: $url" | ||
destination_path="./publish/$(basename "$file")" | ||
curl -sSL "$url" > "$destination_path" | ||
# curl -sSL "https://raw.githubusercontent.com/$GITHUB_REPOSITORY/main/${file#*./}" > "./publish/${file#*./}" | ||
# curl -sSL "https://raw.githubusercontent.com/$GITHUB_REPOSITORY/main/${file#$PWD/}" > "$destination_path" | ||
done | ||
run: | | ||
# 设置环境变量 | ||
echo "RELEASE_NAME=Released on $(date +%Y.%m.%d-%H:%M)" >> $GITHUB_ENV | ||
echo "TAG_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV | ||
# 打印出$GITHUB_REPOSITORY的值以便检查 | ||
echo "GITHUB_REPOSITORY: $GITHUB_REPOSITORY" | ||
# 下载*rules.txt文件 | ||
mkdir -p publish | ||
for file in $(find "$PWD" -name "*DIY-*.txt" -type f -print); do | ||
echo "Found file: $file" | ||
# 打印出将要使用的URL | ||
url="https://raw.xxxxxxxxxxx.com/$GITHUB_REPOSITORY/main/${file#$PWD/}" | ||
echo "Downloading from: $url" | ||
destination_path="./publish/$(basename "$file")" | ||
curl -sSL "$url" > "$destination_path" | ||
done | ||
- name: Release and upload assets | ||
uses: softprops/[email protected] | ||
with: | ||
name: ${{ env.RELEASE_NAME }} | ||
tag_name: ${{ env.TAG_NAME }} | ||
draft: false | ||
prerelease: false | ||
files: | | ||
./publish/* | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Git push assets to "release" branch | ||
run: | | ||
cd publish || exit 1 | ||
git init | ||
git config --local user.name "github-actions[bot]" | ||
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
git checkout -b release | ||
git add . | ||
git commit -m "${{ env.RELEASE_NAME }}" | ||
git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" | ||
git push -f origin release | ||
- name: Purge jsdelivr CDN | ||
run: | | ||
cd publish || exit 1 | ||
for file in $(ls); do | ||
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@release/${file}" | ||
done | ||