forked from bambulab/BambuStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (147 loc) · 5.67 KB
/
Copy pathcd-deploy-apt.yml
File metadata and controls
162 lines (147 loc) · 5.67 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
name: 'CD: APT Repository'
run-name: "APT update (${{ inputs.channel || 'stable' }}) — ${{ github.event.release.tag_name || inputs.tag || 'latest' }}"
on:
release:
types: [released]
workflow_dispatch:
inputs:
tag:
description: 'Release tag (empty = latest stable)'
required: false
type: string
channel:
description: 'APT channel to update'
required: false
type: choice
default: stable
options: [stable, nightly]
workflow_call:
inputs:
tag:
description: 'Release tag'
required: true
type: string
channel:
description: 'APT channel: stable or nightly'
required: false
type: string
default: stable
permissions: read-all
concurrency:
group: cd-deploy-apt-${{ inputs.channel || 'stable' }}
cancel-in-progress: false
jobs:
update-apt-repo:
name: Update APT Repository (${{ inputs.channel || 'stable' }})
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- name: Harden Runner
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: audit
- name: Determine tag and channel
id: tag
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
# release event is always stable; workflow_call/dispatch use inputs
if [[ "${{ github.event_name }}" == "release" ]]; then
TAG="${{ github.event.release.tag_name }}"
CHANNEL="stable"
elif [[ -n "${{ inputs.tag }}" ]]; then
TAG="${{ inputs.tag }}"
CHANNEL="${{ inputs.channel || 'stable' }}"
else
TAG=$(gh release list --repo "${{ github.repository }}" \
--exclude-pre-releases \
--limit 1 --json tagName -q '.[0].tagName')
CHANNEL="stable"
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "channel=$CHANNEL" >> "$GITHUB_OUTPUT"
echo "Using tag: $TAG channel: $CHANNEL"
- name: Install tools
run: sudo apt-get install -y --no-install-recommends dpkg-dev apt-utils knockd rsync
- name: Download .deb from release
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
TAG="${{ steps.tag.outputs.tag }}"
mkdir -p pool/main/b/bambu-studio
gh release download "$TAG" \
--repo "${{ github.repository }}" \
--pattern "bambustudio_*_amd64.deb" \
--dir pool/main/b/bambu-studio/ \
--clobber
ls -lh pool/main/b/bambu-studio/
[ -n "$(ls pool/main/b/bambu-studio/*.deb 2>/dev/null)" ] || \
{ echo "ERROR: no bambustudio .deb found in release $TAG" >&2; exit 1; }
- name: Generate Packages index
run: |
set -euo pipefail
CHANNEL="${{ steps.tag.outputs.channel }}"
mkdir -p "dists/${CHANNEL}/main/binary-amd64"
dpkg-scanpackages pool/ \
> "dists/${CHANNEL}/main/binary-amd64/Packages"
gzip -k -f "dists/${CHANNEL}/main/binary-amd64/Packages"
bzip2 -k -f "dists/${CHANNEL}/main/binary-amd64/Packages"
echo "Packages: $(wc -l < "dists/${CHANNEL}/main/binary-amd64/Packages") lines"
- name: Generate Release file
run: |
set -euo pipefail
CHANNEL="${{ steps.tag.outputs.channel }}"
if [[ "$CHANNEL" == "nightly" ]]; then
DESCRIPTION="BenJule BambuStudio APT Repository — Nightly Channel"
else
DESCRIPTION="BenJule BambuStudio APT Repository"
fi
apt-ftparchive \
-o APT::FTPArchive::Release::Origin="BenJule BambuStudio" \
-o APT::FTPArchive::Release::Label="BenJule BambuStudio" \
-o "APT::FTPArchive::Release::Suite=${CHANNEL}" \
-o "APT::FTPArchive::Release::Codename=${CHANNEL}" \
-o APT::FTPArchive::Release::Architectures=amd64 \
-o APT::FTPArchive::Release::Components=main \
-o "APT::FTPArchive::Release::Description=${DESCRIPTION}" \
release "dists/${CHANNEL}" \
> "dists/${CHANNEL}/Release"
cat "dists/${CHANNEL}/Release"
- name: Sign Release
run: |
set -euo pipefail
CHANNEL="${{ steps.tag.outputs.channel }}"
echo "${{ secrets.APT_SIGNING_KEY }}" | gpg --batch --import
gpg --batch --yes \
--default-key 1726EB3278D7246499B5F2C319BC754BE4AC6B68 \
--clearsign \
-o "dists/${CHANNEL}/InRelease" \
"dists/${CHANNEL}/Release"
gpg --batch --yes \
--default-key 1726EB3278D7246499B5F2C319BC754BE4AC6B68 \
-abs \
-o "dists/${CHANNEL}/Release.gpg" \
"dists/${CHANNEL}/Release"
- name: Setup SSH key
run: |
set -euo pipefail
mkdir -p ~/.ssh
(umask 077 && printf '%s\n' "${{ secrets.VPS_DEPLOY_KEY }}" > ~/.ssh/deploy_key)
ssh-keyscan -H "${{ secrets.VPS_HOST }}" >> ~/.ssh/known_hosts 2>/dev/null || true
- name: Port knock and deploy
run: |
set -euo pipefail
CHANNEL="${{ steps.tag.outputs.channel }}"
if [[ "$CHANNEL" == "nightly" ]]; then
DEST="/srv/apt-repo/nightly/"
else
DEST="/srv/apt-repo/"
fi
knock -d 200 "${{ secrets.VPS_HOST }}" 7000 8000 9000
sleep 1
rsync -avz --delete \
-e "ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=accept-new" \
pool dists \
"${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }}:${DEST}"