name: fetch-better-cf-ip on: push: branches: - 'master' paths: - '.github/workflows/fetch-better-cf-ip.yml' workflow_dispatch: schedule: - cron: '0 16 1 * *' jobs: fetch-better-cf-ip: runs-on: ubuntu-latest permissions: contents: write steps: - name: Check latest release tag uses: actions/github-script@v7 id: latest_tag with: result-encoding: string retries: 3 script: | const ret = await github.rest.repos.getLatestRelease({ owner: "XIU2", repo: "CloudflareSpeedTest" }) console.log(ret.data.tag_name) return ret.data.tag_name - name: Fetch reference branch 1 uses: dsaltares/fetch-gh-release-asset@master with: repo: XIU2/CloudflareSpeedTest version: tags/${{steps.latest_tag.outputs.result}} regex: true file: "CloudflareST_*" target: 'ref1/' - name: Checkout target branch uses: actions/checkout@v4 with: ref: better-cf-ip path: target - name: Clean target branch continue-on-error: true run: rm target/* - name: Rebuild target branch run: | match=CloudflareST for filepath in ref1/*; do rename=$(echo $filepath | awk -F'[./]' '{print $2}' | sed "s/$match/cf/g") exename=$(tar -tf $filepath 2>/dev/null | grep -i $match || true) if [ ! -z $exename ]; then echo "Extracting $rename" tar -xf $filepath $exename -O >./target/$rename fi exename=$(unzip -l $filepath 2>/dev/null | awk '{print $4}' | grep -i $match || true) if [ ! -z $exename ]; then appendix=$(echo $exename | awk -F'.' '{print $2}') if [ ! -z $appendix ]; then rename=$rename.$appendix fi echo "Extracting $rename" unzip -op $filepath $exename >./target/$rename fi done - name: Push to target branch continue-on-error: true run: | cd target git config --global user.name "${GITHUB_ACTOR}" git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" git add . git commit -m "update $(date +%Y-%m-%d)" git push -q