-
Notifications
You must be signed in to change notification settings - Fork 10
172 lines (138 loc) · 5.54 KB
/
Copy pathupdate-qq.yml
File metadata and controls
172 lines (138 loc) · 5.54 KB
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: Update QQ
on:
workflow_dispatch:
inputs:
url:
description: 'Linux QQ 下载 URL'
required: true
type: string
build:
description: '更新后是否构建 Docker'
default: true
type: boolean
required: true
permissions:
contents: write
env:
DOCKER_REPO: initialencounter/llonebot
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Nix
uses: cachix/install-nix-action@v31
- name: Update QQ
run: |
set -euo pipefail
if [ ! -f "./update.sh" ]; then
echo "Error: update.sh not found!"
exit 1
fi
chmod +x ./update.sh
sources_file="package/qq/sources.nix"
old_version=$(grep -m1 'version = "' "$sources_file" | cut -d'"' -f2)
old_hash=$(grep -m1 'amd64_hash = "' "$sources_file" | cut -d'"' -f2)
./update.sh qq "${{ github.event.inputs.url }}"
new_version=$(grep -m1 'version = "' "$sources_file" | cut -d'"' -f2)
new_hash=$(grep -m1 'amd64_hash = "' "$sources_file" | cut -d'"' -f2)
if [[ "${old_hash}" != "${new_hash}" ]]; then
git config --local user.email "actions@github.com"
git config --local user.name "GitHub Actions"
git add "$sources_file"
if [[ "${old_version}" == "${new_version}" ]]; then
commit_msg="fix(qq): update package hash"
else
commit_msg="qq ${old_version} -> ${new_version}"
fi
git commit -m "$commit_msg"
git push origin HEAD:main
else
echo "ℹ️ No changes detected, skipping commit"
fi
build:
needs: update
if: ${{ github.event.inputs.build }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Configure binfmt for qemu
run: |
docker run --privileged --rm tonistiigi/binfmt --install arm64
- uses: cachix/install-nix-action@v31
with:
extra_nix_config: |
extra-platforms = aarch64-linux
system-features = kvm
experimental-features = nix-command flakes
- uses: DeterminateSystems/flakehub-cache-action@main
- name: Setup cross-compilation for aarch64
run: |
# 确保Nix可以访问QEMU
sudo mkdir -p /etc/nix
echo 'sandbox = false' | sudo tee -a /etc/nix/nix.conf
# 添加必要的构建支持
sudo apt-get update
sudo apt-get install -y qemu-user-static binfmt-support
# 确认 binfmt 支持已正确配置
ls -la /proc/sys/fs/binfmt_misc/
- name: Extract version information
id: version
run: |
git pull origin main
echo "LLONEBOT_VERSION=$(grep "llonebot_version = " package/sources.nix | cut -d'"' -f2)" >> $GITHUB_ENV
echo "PMHQ_VERSION=$(grep "pmhq_version = " package/sources.nix | cut -d'"' -f2)" >> $GITHUB_ENV
echo "QQ_VERSION=$(grep "version = " package/qq/sources.nix | cut -d'"' -f2 | grep -oP '(?<!-)-\K.*')" >> $GITHUB_ENV
- name: Build Docker Image AMD64
run: |
nix build --option system x86_64-linux --show-trace .#dockerImage -o docker-image-amd64
- name: Build Docker Image ARM64
run: |
nix build --option system aarch64-linux --show-trace .#dockerImage -o docker-image-aarch64
- name: Load Docker Images
run: |
docker load < docker-image-amd64
docker tag llonebot:latest ${{ env.DOCKER_REPO }}:latest-amd64
docker load < docker-image-aarch64
docker tag llonebot:latest ${{ env.DOCKER_REPO }}:latest-arm64
- name: Login Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push Docker Image
run: |
# 检查版本号是否设置
if [ -z "${{ env.LLONEBOT_VERSION}}" ]; then
echo "::error::LLONEBOT_VERSION is not set"
exit 1
fi
TAG="v${{ env.LLONEBOT_VERSION }}-${{ env.PMHQ_VERSION }}-${{ env.QQ_VERSION }}"
echo "Using tag: $TAG"
# 推送架构特定的镜像
docker push ${{ env.DOCKER_REPO }}:latest-amd64
docker push ${{ env.DOCKER_REPO }}:latest-arm64
# 创建并推送多架构manifest
docker manifest create ${{ env.DOCKER_REPO }}:latest \
--amend ${{ env.DOCKER_REPO }}:latest-amd64 \
--amend ${{ env.DOCKER_REPO }}:latest-arm64
docker manifest create ${{ env.DOCKER_REPO }}:$TAG \
--amend ${{ env.DOCKER_REPO }}:latest-amd64 \
--amend ${{ env.DOCKER_REPO }}:latest-arm64
# 为manifest明确指定架构
docker manifest annotate ${{ env.DOCKER_REPO }}:latest ${{ env.DOCKER_REPO }}:latest-amd64 --os linux --arch amd64
docker manifest annotate ${{ env.DOCKER_REPO }}:latest ${{ env.DOCKER_REPO }}:latest-arm64 --os linux --arch arm64
docker manifest annotate ${{ env.DOCKER_REPO }}:$TAG ${{ env.DOCKER_REPO }}:latest-amd64 --os linux --arch amd64
docker manifest annotate ${{ env.DOCKER_REPO }}:$TAG ${{ env.DOCKER_REPO }}:latest-arm64 --os linux --arch arm64
# 推送manifest
docker manifest push ${{ env.DOCKER_REPO }}:latest
docker manifest push ${{ env.DOCKER_REPO }}:$TAG