Alist Sync #13
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: Alist Sync | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
reload_storage: | ||
description: 删除现有存储库,并从配置文件或远程配置中重新创建存储器 | ||
type: boolean | ||
required: false | ||
default: false | ||
debug: | ||
description: 开启调试模式 | ||
type: boolean | ||
required: false | ||
default: false | ||
env: | ||
_ALIST_SYNC_NAME: "action-${{github.actor}}-${{github.run_id}}-${{github.run_number}}" | ||
_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@v3 | ||
- name: Setup Python v4 | ||
uses: actions/setup-python@v4 | ||
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 and Init Alist Server | ||
env: | ||
_ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }} | ||
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' }} or ${{ steps.alist-data-cache.outputs.cache-hit != 'true'}} | ||
env: | ||
_ALIST_ADMIN_PASSWORD: ${{ secrets.ALIST_ADMIN_PASSWORD }} | ||
_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 $(pwd) | ||
cat > alist-backup-config.json << EOF | ||
${{ secrets.ALIST_BACKUP_CONFIG }} | ||
EOF | ||
python3 tools/create_storage.py | ||
- name: Create Tunnel for Cloudflare | ||
if: ${{ secrets.CLOUDFLARE_TUNNEL_TOKEN != '' }} | ||
Check failure on line 78 in .github/workflows/alist-sync.yaml GitHub Actions / Alist SyncInvalid workflow file
|
||
run: | | ||
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 | ||
run: | | ||
cat > config.yaml << EOF | ||
${{ secrets.SYNC_CONFIG }} | ||
EOF | ||
set -ex | ||
export TERM=dumb | ||
export FORCE_COLOR=true | ||
export COLUMNS=160 | ||
./bootstrap.sh main test-config | ||
./bootstrap.sh main sync | ||
- name: Debugger | ||
if: ${{ github.event.inputs.debug == 'true' and failure() }} | ||
run: | | ||
echo "Debugging" | ||
if [ -z "$(sudo netstat -ntlp |grep -v grep |grep :22 |grep sshd)" ]; then | ||
echo "sshd is not running." | ||
if [ ! -f /lib/systemd/system/ssh.service ]; then | ||
echo sshd is not installed. will install ... | ||
sudo apt-get update; | ||
sudo apt-get install -y openssh-server; | ||
fi | ||
echo "starting sshd ..." | ||
sudo systemctl restart sshd | ||
fi | ||
git clone https://gist.github.com/lee-cq/ed0f7e2bf9e039f1797c5b700ba118ec | ||
mkdir -p ~/.ssh | ||
cd ed0f7e2bf9e039f1797c5b700ba118ec || exit 1 | ||
chmod +x setup.sh && ./setup.sh | ||
touch /tmp/keepalive | ||
echo 'created keepalive file.' | ||
echo 'timeout 21000s(5h 50m).' | ||
timeout 21000 bash -c 'stopout=21000; while true;do echo $((stopout=$stopout-3)) > /tmp/stopout ; test -f /tmp/keepalive || break; sleep 3; done ' || echo Timeouted. | ||
echo 'The VM will be shutdown in 10 minutes.' | ||