Skip to content

action-lee-cq-8408135337-44 #44

action-lee-cq-8408135337-44

action-lee-cq-8408135337-44 #44

Workflow file for this run

name: Alist Sync
run-name: "action-${{github.actor}}-${{github.run_id}}-${{github.run_number}}"
on:
workflow_dispatch:
inputs:
reload_storage:
description: 删除现有存储库,并从配置文件或远程配置中重新创建存储器
type: boolean
required: false
default: false
debug:
description: 开启调试模式
type: boolean
required: false
default: false
check_only:
description: 仅检查同步动作,不执行具体操作
type: boolean
required: false
default: false
env:
_ALIST_SYNC_NAME: "${{github.run-name}}"
_ALIST_SYNC_DEBUG: ${{ github.event.inputs.debug }}
_ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }}
jobs:
run:
name: "sync-actions"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python v4
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Load Cache
id: alist-data-cache
uses: actions/cache@v4
with:
key: ${{ runner.name }}-alist-sync-data
path: |
./.alist-sync-cache/*.db
./.alist-sync-cache/*.json
./.alist-sync-cache/*.shelve
./alist/data
- name: Install Grafana Agent
env:
GRAFANA_AGENT_CONFIG: ${{ secrets.GRAFANA_AGENT_CONFIG }}
run: |
cat > grafana-agent.yaml << 'EOF'
${{ secrets.GRAFANA_AGENT_CONFIG }}
EOF
if grep -q "instance: <your-instance-name>" grafana-agent.yaml; then
echo "GRAFANA_AGENT_CONFIG is not set. Skip Grafana Agent Installation."
exit 0
fi
sed -i "s/instance: <your-instance-name>/instance: ${_ALIST_SYNC_NAME}/g" grafana-agent.yaml
sed -i "s#<your-log-path>#$(pwd)/logs/*.log#g" grafana-agent.yaml
sudo cp -f grafana-agent.yaml /etc/grafana-agent.yaml
curl -fL# https://github.com/grafana/agent/releases/download/v0.39.1/grafana-agent-0.39.1-1.amd64.deb -o grafana-agent-0.39.1-1.amd64.deb
echo -n "19ba2f69ec14fae4812128475beea6e034e7e9c1183cd0c1f6814d04d0ba788b grafana-agent-0.39.1-1.amd64.deb" | sha256sum -c - 2>&1 | grep "OK" || fatal 'Failed sha256sum check'
sudo dpkg -i "grafana-agent-0.39.1-1.amd64.deb"
sudo systemctl enable grafana-agent.service
sudo systemctl start grafana-agent.service
rm -f grafana-agent.yaml grafana-agent-0.39.1-1.amd64.deb
- name: Install and Init Alist Server
run: |
sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
bash -ex bootstrap.sh install
# init-alist 总是会重置管理员密码为环境变量。
bash -x bootstrap.sh alist-init
- name: Create Storage for Alist if load cache failed
if: github.event.inputs.reload_storage == 'true' || steps.alist-data-cache.outputs.cache-hit != 'true'
env:
_ALIST_BACKUP: ${{secrets.ALIST_BACKUP}}
_ALIST_BACKUP_URL: ${{secrets.ALIST_BACKUP_URL}}
_ALIST_BACKUP_USERNAME: ${{secrets.ALIST_BACKUP_USERNAME}}
_ALIST_BACKUP_PASSWORD: ${{secrets.ALIST_BACKUP_PASSWORD}}
_RELOAD_STORAGE: ${{ github.event.inputs.reload_storage }}
run: |
echo RUNNER = ${_ALIST_SYNC_NAME}
# 这将会导入全部的内容包括:设置,元数据,用户,存储器。
echo $(pwd)
cat > alist-backup-config.json << EOF
${{ secrets.ALIST_BACKUP_CONFIG }}
EOF
python3 tools/create_storage.py
- name: Create Tunnel for Cloudflare
run: |
echo RUNNER = ${_ALIST_SYNC_NAME}
test ! -n "${{secrets.CLOUDFLARE_TUNNEL_TOKEN}}" && {
echo "CLOUDFLARE_TUNNEL_TOKEN is not set. Skip Cloudflare Tunnel Installation."
exit 0
}
echo "Installing Cloudflare Tunnel ..."
curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb &&
sudo dpkg -i cloudflared.deb &&
sudo cloudflared service install ${{ secrets.CLOUDFLARE_TUNNEL_TOKEN }}
echo "CLOUDFLARE_INSTALLED=true" >> "$GITHUB_ENV"
echo "Cloudflare Tunnel Installed."
- name: RUN Alist Sync
env:
CHECK_ONLY: ${{ github.event.inputs.check_only }}
run: |
echo RUNNER = ${_ALIST_SYNC_NAME}
cat > config.yaml << EOF
${{ secrets.SYNC_CONFIG }}
EOF
set -ex
# export TERM=dumb
sudo mkdir -m 777 -p /mnt/.alist-sync-cache
export FORCE_COLOR=true
export COLUMNS=160
./bootstrap.sh main test-config
if [ "${CHECK_ONLY}" == "true" ]; then
echo "Check Only"
./bootstrap.sh main check
else
echo "Sync"
./bootstrap.sh main sync
fi
- name: Debugger
if: ${{ github.event.inputs.debug == 'true' && always() }}
uses: csexton/debugger-action@master
- name: Upload Logs
if: always()
uses: actions/upload-artifact@v4
with:
name: logs
path: logs/*