Convert to Base64 #1237
This file contains hidden or 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: Convert to Base64 | |
| on: | |
| schedule: | |
| - cron: '0 */4 * * *' | |
| workflow_dispatch: | |
| jobs: | |
| convert: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Setup environment | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y jq coreutils | |
| - name: Download YAML file | |
| run: | | |
| curl -sL https://raw.githubusercontent.com/go4sharing/sub/refs/heads/main/sub.yaml -o input.yaml | |
| [ -s input.yaml ] || { echo "Download failed"; exit 1; } | |
| - name: Process YAML to Base64 | |
| run: | | |
| mkdir -p v2ray | |
| # Method 1: Using yq (recommended) | |
| if command -v yq &> /dev/null; then | |
| yq eval '.. | select(tag == "!!str") | @base64' input.yaml > v2ray/base64.txt | |
| else | |
| # Fallback method | |
| grep -oP '(?<=: ).*' input.yaml | while read -r line; do | |
| echo -n "$line" | base64 -w 0 | |
| echo "" | |
| done > v2ray/base64.txt | |
| fi | |
| - name: Commit changes | |
| run: | | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "[email protected]" | |
| git add v2ray/base64.txt | |
| git diff --quiet && git diff --staged --quiet || git commit -m "Auto-update base64 nodes [$(date +'%Y-%m-%d %T')]" | |
| git push | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.secrets.GH_TOKEN }} |