Skip to content

Commit e744b08

Browse files
committed
📦 Chore(custom): optimize file upload workflow
1 parent 0c44175 commit e744b08

File tree

6 files changed

+275
-16
lines changed

6 files changed

+275
-16
lines changed

.github/workflows/main.yml

Lines changed: 103 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070

7171
# step2: sign
7272
- name: Install the Apple certificates
73-
if: contains(matrix.os, 'macos') && (github.event.inputs.build_os == matrix.platform || github.event.inputs.build_os == 'All')
73+
if: contains(matrix.os_type, 'macos') && (github.event.inputs.build_os == matrix.platform || github.event.inputs.build_os == 'All')
7474
run: |
7575
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
7676
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH
@@ -82,9 +82,10 @@ jobs:
8282
node-version: "22.x"
8383

8484
- name: Install system deps
85-
if: contains(matrix.os, 'linux') && (github.event.inputs.build_os == matrix.platform || github.event.inputs.build_os == 'All')
85+
if: contains(matrix.os_type, 'linux') && (github.event.inputs.build_os == matrix.platform || github.event.inputs.build_os == 'All')
8686
run: |
8787
sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils libfuse2
88+
8889
- name: Install FPM
8990
if: matrix.os == 'ubuntu-24.04-arm' && (github.event.inputs.build_os == matrix.platform || github.event.inputs.build_os == 'All')
9091
run: |
@@ -114,10 +115,7 @@ jobs:
114115
run: |
115116
# Remove publish config if not publishing
116117
if [ "${{ github.event.inputs.publish_enabled }}" == "false" ]; then
117-
echo "Publishing disabled, removing publish config..."
118118
jq 'del(.publish)' electron-builder.json > tmp.json && mv tmp.json electron-builder.json
119-
echo "modified electron-builder.json:"
120-
cat electron-builder.json
121119
fi
122120
123121
# Configure architecture based on platform
@@ -182,18 +180,25 @@ jobs:
182180
uses: actions/upload-artifact@v4
183181
with:
184182
name: ${{ matrix.os_type }}-${{ matrix.platform == 'Windows x64' && 'x64' || matrix.platform == 'Windows ARM64' && 'arm64' || matrix.platform == 'macOS x64' && 'x64' || matrix.platform == 'macOS ARM64' && 'arm64' || matrix.platform == 'Linux x64' && 'x64' || 'arm64' }}-${{ contains(matrix.os, 'windows') && 'executables' || 'packages' }}
185-
path: dist_electron/*
183+
path: |
184+
dist_electron/*.exe
185+
dist_electron/*.dmg
186+
dist_electron/*.zip
187+
dist_electron/*.AppImage
188+
dist_electron/*.deb
189+
dist_electron/*.rpm
190+
dist_electron/*.snap
186191
retention-days: 30
187-
if-no-files-found: ${{ contains(matrix.os, 'linux') && 'ignore' || 'error' }}
192+
if-no-files-found: 'ignore'
188193

189-
- name: Upload update manifests
194+
- name: Upload yml artifacts
190195
if: github.event.inputs.build_os == matrix.platform || github.event.inputs.build_os == 'All'
191196
uses: actions/upload-artifact@v4
192197
with:
193198
name: ${{ matrix.os_type }}-${{ matrix.platform == 'Windows x64' && 'x64' || matrix.platform == 'Windows ARM64' && 'arm64' || matrix.platform == 'macOS x64' && 'x64' || matrix.platform == 'macOS ARM64' && 'arm64' || matrix.platform == 'Linux x64' && 'x64' || 'arm64' }}-yml
194-
path: dist_electron/github/*
199+
path: dist_electron/**/*.yml
195200
retention-days: 30
196-
if-no-files-found: ${{ contains(matrix.os, 'linux') && 'ignore' || 'error' }}
201+
if-no-files-found: 'ignore'
197202

198203
- name: Get version
199204
if: (github.event.inputs.build_os == matrix.platform || github.event.inputs.build_os == 'All') && matrix.platform == 'Windows x64' && github.event.inputs.publish_enabled == true
@@ -214,3 +219,91 @@ jobs:
214219
tag_name: v${{ steps.get_version.outputs.version }}
215220
name: Release v${{ steps.get_version.outputs.version }}
216221
token: ${{ secrets.GH_TOKEN }}
222+
223+
combine-and-upload-yml:
224+
name: Combine YML files and upload to S3
225+
needs: release
226+
runs-on: ubuntu-latest
227+
228+
steps:
229+
- name: Check out git repository
230+
uses: actions/checkout@v6
231+
232+
- name: Install Node.js
233+
uses: actions/setup-node@v6
234+
with:
235+
node-version: "22.x"
236+
237+
- name: Install dependencies
238+
shell: bash
239+
run: |
240+
yarn config set ignore-engines true
241+
yarn
242+
243+
- name: Download all yml artifacts
244+
uses: actions/download-artifact@v4
245+
with:
246+
pattern: '*-yml'
247+
path: ./yml-artifacts
248+
merge-multiple: false
249+
250+
- name: List downloaded artifacts
251+
run: |
252+
echo "Downloaded artifacts structure:"
253+
find ./yml-artifacts -type f -name "*.yml"
254+
tree ./yml-artifacts
255+
256+
- name: Combine and deduplicate yml files
257+
run: |
258+
node scripts/combine-yml.cjs ./yml-artifacts ./dist_electron/combined
259+
echo "Combined YML files:"
260+
ls -la ./dist_electron/combined/
261+
echo "Latest combined YML content:"
262+
cat ./dist_electron/combined/latest.yml
263+
echo "Latest macOS combined YML content:"
264+
cat ./dist_electron/combined/latest-mac.yml
265+
echo "Latest linux combined YML content:"
266+
cat ./dist_electron/combined/latest-linux.yml
267+
echo "Latest linux ARM64 combined YML content:"
268+
cat ./dist_electron/combined/latest-linux-arm64.yml
269+
270+
- name: Configure AWS credentials
271+
uses: aws-actions/configure-aws-credentials@v4
272+
if: github.event.inputs.publish_enabled == 'true'
273+
with:
274+
aws-access-key-id: ${{ secrets.R2_SECRET_ID }}
275+
aws-secret-access-key: ${{ secrets.R2_SECRET_KEY }}
276+
aws-region: us-east-1
277+
278+
- name: Upload combined yml files to S3/R2
279+
if: github.event.inputs.publish_enabled == 'true'
280+
run: |
281+
for file in ./dist_electron/combined/*.yml; do
282+
if [ -f "$file" ]; then
283+
filename=$(basename "$file")
284+
echo "Uploading $filename to S3/R2..."
285+
aws s3 cp "$file" "s3://piclist-dl/latest/$filename" \
286+
--endpoint-url "https://7ab4ed5cb1f4052a13d3b573876ecf33.r2.cloudflarestorage.com" \
287+
echo "Uploaded $filename successfully"
288+
fi
289+
done
290+
echo "All yml files uploaded to S3/R2!"
291+
292+
- name: Get version for release
293+
id: get_version
294+
run: |
295+
VERSION=$(node -p "require('./package.json').version")
296+
echo "version=$VERSION" >> $GITHUB_OUTPUT
297+
298+
- name: Upload combined yml files to GitHub Release
299+
if: github.event.inputs.publish_enabled == 'true'
300+
uses: softprops/action-gh-release@v2
301+
with:
302+
draft: true
303+
tag_name: v${{ steps.get_version.outputs.version }}
304+
files: |
305+
./dist_electron/combined/latest.yml
306+
./dist_electron/combined/latest-mac.yml
307+
./dist_electron/combined/latest-linux.yml
308+
./dist_electron/combined/latest-linux-arm64.yml
309+
token: ${{ secrets.GH_TOKEN }}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"fs-extra": "^11.3.3",
6464
"got": "^14.6.6",
6565
"hpagent": "^1.2.0",
66-
"js-yaml": "^4.1.1",
6766
"lodash-es": "^4.17.22",
6867
"marked": "^17.0.1",
6968
"mime": "^4.1.0",
@@ -119,6 +118,7 @@
119118
"eslint-plugin-unicorn": "^62.0.0",
120119
"eslint-plugin-vue": "^10.6.2",
121120
"globals": "^16.5.0",
121+
"js-yaml": "^4.1.1",
122122
"highlight.js": "^11.11.1",
123123
"husky": "^9.1.7",
124124
"lucide-vue-next": "^0.562.0",

scripts/combine-yml.cjs

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const yaml = require('js-yaml')
4+
5+
function removeDuplicates(files) {
6+
if (!files || !Array.isArray(files)) return files
7+
8+
const seen = new Set()
9+
return files.filter(file => {
10+
if (seen.has(file.url)) {
11+
return false
12+
}
13+
seen.add(file.url)
14+
return true
15+
})
16+
}
17+
18+
function combineYmlFiles(ymlFiles, outputPath) {
19+
if (ymlFiles.length === 0) {
20+
console.log(`No yml files found for ${outputPath}`)
21+
return
22+
}
23+
24+
let combinedData = null
25+
26+
for (const ymlFile of ymlFiles) {
27+
const content = fs.readFileSync(ymlFile, 'utf8')
28+
const data = yaml.load(content)
29+
30+
if (!combinedData) {
31+
combinedData = data
32+
} else {
33+
if (data.files && Array.isArray(data.files)) {
34+
combinedData.files = [...(combinedData.files || []), ...data.files]
35+
}
36+
37+
if (
38+
data.releaseDate &&
39+
(!combinedData.releaseDate || new Date(data.releaseDate) > new Date(combinedData.releaseDate))
40+
) {
41+
combinedData.releaseDate = data.releaseDate
42+
}
43+
}
44+
}
45+
46+
if (combinedData && combinedData.files) {
47+
combinedData.files = removeDuplicates(combinedData.files)
48+
}
49+
50+
const ymlContent = yaml.dump(combinedData, { lineWidth: -1 })
51+
fs.writeFileSync(outputPath, ymlContent, 'utf8')
52+
console.log(`Created ${outputPath} with ${combinedData?.files?.length || 0} file entries`)
53+
}
54+
55+
function processSingleYmlFile(ymlFile, outputPath) {
56+
if (!fs.existsSync(ymlFile)) {
57+
console.log(`File not found: ${ymlFile}`)
58+
return
59+
}
60+
61+
const content = fs.readFileSync(ymlFile, 'utf8')
62+
const data = yaml.load(content)
63+
64+
if (data && data.files) {
65+
data.files = removeDuplicates(data.files)
66+
}
67+
68+
const ymlContent = yaml.dump(data, { lineWidth: -1 })
69+
fs.writeFileSync(outputPath, ymlContent, 'utf8')
70+
console.log(`Processed ${outputPath} with ${data?.files?.length || 0} file entries`)
71+
}
72+
73+
function findYmlInFolder(basePath, folderPattern, ymlFileName) {
74+
const folders = fs.existsSync(basePath)
75+
? fs.readdirSync(basePath).filter(f => {
76+
const fullPath = path.join(basePath, f)
77+
return fs.statSync(fullPath).isDirectory() && f.includes(folderPattern)
78+
})
79+
: []
80+
81+
const ymlFiles = []
82+
for (const folder of folders) {
83+
const ymlPath = path.join(basePath, folder, ymlFileName)
84+
if (fs.existsSync(ymlPath)) {
85+
ymlFiles.push(ymlPath)
86+
}
87+
}
88+
return ymlFiles
89+
}
90+
91+
function main() {
92+
const distPath = process.argv[2] || './dist_electron'
93+
const outputDir = process.argv[3] || './dist_electron/combined'
94+
95+
console.log(`Processing yml files from: ${distPath}`)
96+
console.log(`Output directory: ${outputDir}`)
97+
98+
if (!fs.existsSync(outputDir)) {
99+
fs.mkdirSync(outputDir, { recursive: true })
100+
}
101+
102+
const windowsX64Ymls = findYmlInFolder(distPath, 'windows-x64-yml', 'latest.yml')
103+
const windowsArm64Ymls = findYmlInFolder(distPath, 'windows-arm64-yml', 'latest.yml')
104+
const macX64Ymls = findYmlInFolder(distPath, 'macos-x64-yml', 'latest-mac.yml')
105+
const macArm64Ymls = findYmlInFolder(distPath, 'macos-arm64-yml', 'latest-mac.yml')
106+
const linuxX64Ymls = findYmlInFolder(distPath, 'linux-x64-yml', 'latest-linux.yml')
107+
const linuxArm64Ymls = findYmlInFolder(distPath, 'linux-arm64-yml', 'latest-linux-arm64.yml')
108+
109+
console.log('\nFound yml files:')
110+
console.log(`Windows x64: ${windowsX64Ymls.map(f => path.basename(path.dirname(f))).join(', ')}`)
111+
console.log(`Windows ARM64: ${windowsArm64Ymls.map(f => path.basename(path.dirname(f))).join(', ')}`)
112+
console.log(`macOS x64: ${macX64Ymls.map(f => path.basename(path.dirname(f))).join(', ')}`)
113+
console.log(`macOS ARM64: ${macArm64Ymls.map(f => path.basename(path.dirname(f))).join(', ')}`)
114+
console.log(`Linux x64: ${linuxX64Ymls.map(f => path.basename(path.dirname(f))).join(', ')}`)
115+
console.log(`Linux ARM64: ${linuxArm64Ymls.map(f => path.basename(path.dirname(f))).join(', ')}`)
116+
117+
const windowsYmls = [...windowsX64Ymls, ...windowsArm64Ymls]
118+
if (windowsYmls.length > 0) {
119+
console.log(`\nCombining ${windowsYmls.length} Windows yml files...`)
120+
combineYmlFiles(windowsYmls, path.join(outputDir, 'latest.yml'))
121+
} else {
122+
console.log('\nNo Windows yml files found to combine')
123+
}
124+
125+
const macYmls = [...macX64Ymls, ...macArm64Ymls]
126+
if (macYmls.length > 0) {
127+
console.log(`\nCombining ${macYmls.length} macOS yml files...`)
128+
combineYmlFiles(macYmls, path.join(outputDir, 'latest-mac.yml'))
129+
} else {
130+
console.log('\nNo macOS yml files found to combine')
131+
}
132+
if (linuxX64Ymls.length > 0) {
133+
console.log('\nProcessing Linux x64 yml file (deduplicate only)...')
134+
processSingleYmlFile(linuxX64Ymls[0], path.join(outputDir, 'latest-linux.yml'))
135+
} else {
136+
console.log('\nNo Linux x64 yml files found')
137+
}
138+
if (linuxArm64Ymls.length > 0) {
139+
console.log('\nProcessing Linux ARM64 yml file (deduplicate only)...')
140+
processSingleYmlFile(linuxArm64Ymls[0], path.join(outputDir, 'latest-linux-arm64.yml'))
141+
} else {
142+
console.log('\nNo Linux ARM64 yml files found')
143+
}
144+
145+
console.log('\nYML combination and deduplication complete!')
146+
}
147+
148+
main()

scripts/config.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,31 @@ const linux = [
2020
{
2121
appNameWithPrefix: 'PicList-',
2222
ext: '.AppImage',
23-
arch: '',
23+
arch: '-x86_64',
2424
'version-file': 'latest-linux.yml',
2525
},
2626
{
27-
appNameWithPrefix: 'piclist_',
27+
appNameWithPrefix: 'PicList-',
28+
ext: '.AppImage',
29+
arch: '-arm64',
30+
'version-file': 'latest-linux.yml',
31+
},
32+
{
33+
appNameWithPrefix: 'PicList-',
2834
ext: '.snap',
29-
arch: '_amd64',
35+
arch: '-amd64',
36+
'version-file': 'latest-linux.yml',
37+
},
38+
{
39+
appNameWithPrefix: 'PicList-',
40+
ext: '.deb',
41+
arch: '-amd64',
42+
'version-file': 'latest-linux.yml',
43+
},
44+
{
45+
appNameWithPrefix: 'PicList-',
46+
ext: '.deb',
47+
arch: '-arm64',
3048
'version-file': 'latest-linux.yml',
3149
},
3250
]

scripts/generate-release-notes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cat > "$OUTPUT_FILE" << EOF
3737
### Linux
3838
3939
- AppImage:
40-
[**x64**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/PicList-${VERSION}-x64.AppImage) |
40+
[**x64**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/PicList-${VERSION}-x86_64.AppImage) |
4141
[**ARM64**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/PicList-${VERSION}-arm64.AppImage)
4242
- deb:
4343
[**x64**](https://github.com/Kuingsmile/PicList/releases/download/v${VERSION}/Piclist-${VERSION}-amd64.deb) |

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8044,7 +8044,7 @@ got@^11.7.0, got@^11.8.5:
80448044
p-cancelable "^2.0.0"
80458045
responselike "^2.0.0"
80468046

8047-
got@^14.6.5:
8047+
got@^14.6.6:
80488048
version "14.6.6"
80498049
resolved "https://registry.yarnpkg.com/got/-/got-14.6.6.tgz#5adf7f576f89de8e291fd782e8b277f9bcc8e6c0"
80508050
integrity sha512-QLV1qeYSo5l13mQzWgP/y0LbMr5Plr5fJilgAIwgnwseproEbtNym8xpLsDzeZ6MWXgNE6kdWGBjdh3zT/Qerg==

0 commit comments

Comments
 (0)