-
Notifications
You must be signed in to change notification settings - Fork 8
172 lines (150 loc) · 5.7 KB
/
sync_alist_files.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Build and Push Docker Image
on:
workflow_dispatch:
push:
tags:
- 'v*'
paths:
- 'action.txt'
# 添加权限配置
permissions:
contents: write
packages: write
issues: write
pull-requests: write
env:
DOCKER_IMAGE: ${{ github.repository }} # 请替换成你的 Docker Hub 用户名和镜像名
PLATFORMS: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x
jobs:
alist-sync-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get version from tag
if: startsWith(github.ref, 'refs/tags/')
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
- name: Update Docker Hub Description
if: github.event_name != 'pull_request'
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ env.DOCKER_IMAGE }}
readme-filepath: ./README.md
short-description: "Alist-Sync - A tool for syncing files between Alist storages"
# 以下是新增的 Release 相关步骤
- name: Create Source Archive
if: startsWith(github.ref, 'refs/tags/')
run: |
# 创建临时目录
TEMP_DIR="/tmp/alist-sync-release"
mkdir -p "$TEMP_DIR"
# 定义要包含的文件列表
INCLUDE_FILES=(
"alist-sync-web.py"
"alist_sync.py"
"requirements.txt"
"Dockerfile"
"docker-compose.yml"
"README.md"
"static"
"templates"
)
# 定义平台列表
PLATFORMS=(
"linux-386"
"linux-amd64"
"linux-arm-v6"
"linux-arm-v7"
"linux-arm64"
"linux-ppc64le"
"linux-s390x"
)
# 为每个平台创建一个包
for platform in "${PLATFORMS[@]}"; do
# 创建平台特定的临时目录
PLATFORM_DIR="$TEMP_DIR/$platform"
mkdir -p "$PLATFORM_DIR"
# 复制文件到平台目录
for item in "${INCLUDE_FILES[@]}"; do
if [ -e "$item" ]; then
cp -r "$item" "$PLATFORM_DIR/"
fi
done
# 在平台目录中创建压缩包
cd "$PLATFORM_DIR"
# 创建 ZIP 文件
zip -r "alist-sync-${{ github.ref_name }}-${platform}.zip" ./*
# 创建 TAR.GZ 文件
tar --exclude='.[^/]*' -czf "alist-sync-${{ github.ref_name }}-${platform}.tar.gz" ./*
# 移动压缩包到工作目录
mv "alist-sync-${{ github.ref_name }}-${platform}.zip" "$GITHUB_WORKSPACE/"
mv "alist-sync-${{ github.ref_name }}-${platform}.tar.gz" "$GITHUB_WORKSPACE/"
done
- name: Generate Release Body
if: startsWith(github.ref, 'refs/tags/')
id: release_body
run: |
# 将 release 内容保存到输出变量
CONTENT=$(cat RELEASE.md)
echo "RELEASE_BODY<<EOF" >> "$GITHUB_OUTPUT"
echo "$CONTENT" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Create Release
if: startsWith(github.ref, 'refs/tags/')
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
draft: false
prerelease: false
body: ${{ steps.release_body.outputs.RELEASE_BODY }}
files: |
alist-sync-${{ github.ref_name }}-linux-386.zip
alist-sync-${{ github.ref_name }}-linux-386.tar.gz
alist-sync-${{ github.ref_name }}-linux-amd64.zip
alist-sync-${{ github.ref_name }}-linux-amd64.tar.gz
alist-sync-${{ github.ref_name }}-linux-arm-v6.zip
alist-sync-${{ github.ref_name }}-linux-arm-v6.tar.gz
alist-sync-${{ github.ref_name }}-linux-arm-v7.zip
alist-sync-${{ github.ref_name }}-linux-arm-v7.tar.gz
alist-sync-${{ github.ref_name }}-linux-arm64.zip
alist-sync-${{ github.ref_name }}-linux-arm64.tar.gz
alist-sync-${{ github.ref_name }}-linux-ppc64le.zip
alist-sync-${{ github.ref_name }}-linux-ppc64le.tar.gz
alist-sync-${{ github.ref_name }}-linux-s390x.zip
alist-sync-${{ github.ref_name }}-linux-s390x.tar.gz