Update blank.yml

This commit is contained in:
Sliverkiss
2024-02-20 21:39:59 +08:00
committed by GitHub
parent b6f4a4b36c
commit e185a1d5a6

View File

@@ -1,104 +1,54 @@
name: Generate Image JSON name: Image Workflow
on: on:
push: push:
branches:
- main
paths: paths:
- '**/QuantumultX/icon/**' - 'icon/**'
pull_request:
paths:
- 'icon/**'
workflow_dispatch: workflow_dispatch:
inputs:
dummy-trigger:
description: 'Dummy trigger for manual run'
default: 'Run workflow'
jobs: jobs:
generate-json: generate_json:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Set up Node.js
uses: actions/setup-node@v4.0.0
with:
node-version: '16'
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Display Node.js version - name: Set up Python
run: node --version uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Debug - Current working directory and list files - name: Install dependencies
run: | run: |
pwd python -m pip install --upgrade pip
ls -la pip install requests
- name: Generate JSON - name: Generate JSON
run: | run: |
IMAGES_FOLDER="icon" python .github/scripts/generate_image_json.py
JSON_FILE="sliverkiss.icons.json"
DESTINATION_FOLDER="QuantumultX"
echo "Checking current directory:"
pwd
echo "Listing files in leviicons:"
ls -al $IMAGES_FOLDER
# Create an empty JSON file
echo "[]" > $JSON_FILE
# 创建一个 JSON 文件头部
echo "{" > $JSON_FILE
echo ' "name": "Sliverkiss图标订阅",' >> $JSON_FILE
echo ' "description": "收集一些自己常用的图标 by @sliverkiss",' >> $JSON_FILE
echo ' "icons": [' >> $JSON_FILE
# Populate the array with image information - name: Load output variables
for FILE_PATH in $IMAGES_FOLDER/*; do run: |
if [ -f "$FILE_PATH" ]; then export $(dotenv -f output.env list)
FILE_NAME=$(basename "$FILE_PATH")
RAW_URL="https://raw.githubusercontent.com/Sliverkiss/QuantumultX/main/$FILE_PATH"
# 如果不是第一个图标,则在前一个图标的末尾添加逗号
if [ "$FIRST_ITEM" = false ]; then
# 在前一个图标的末尾添加逗号
sed -i '$s/}$/},/' $JSON_FILE
fi
# Append image information to the JSON file - name: Save state
echo -n ", " >> $JSON_FILE run: echo "ICONS_JSON_PATH=${ICONS_JSON_PATH}" >> $GITHUB_STATE
# 将图片信息添加到 JSON 文件
echo ' {' >> $JSON_FILE
echo ' "name": "'$FILE_NAME'",' >> $JSON_FILE
echo ' "url": "'$RAW_URL'"' >> $JSON_FILE
echo ' },' >> $JSON_FILE
fi
done
# 移除最后一个逗号 - name: Upload artifact
sed -i '$s/,$//' $JSON_FILE
# 添加 JSON 文件尾部
echo ']' >> $JSON_FILE
echo '}' >> $JSON_FILE
# Remove the leading comma
sed -i 's/^\(.\{2\}\)//' $JSON_FILE
echo "Checking generated JSON file:"
cat $JSON_FILE
# Set an environment variable with the path to the JSON file
echo "ARTIFACT_PATH=LeviIcons" >> $GITHUB_ENV
- name: Upload Artifact
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: sliverkiss.icons.json name: json-artifact
path: ${{ env.ARTIFACT_PATH }} path: $ICONS_JSON_PATH
- name: Push to TEST Repository - name: Show working directory contents (After generate_json.py)
run: ls -R
- name: Debug file existence and content
run: | run: |
git config user.name "${{ github.actor }}" echo "Current working directory:" $(pwd)
git config user.email "${{ github.actor }}@users.noreply.github.com" echo "List of files in the directory:" $(ls -R)
git add . cat $ICONS_JSON_PATH
git commit -m "Add generated JSON file"
git push origin HEAD:main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}