Skip to content

Commit

Permalink
feat: chaneg action
Browse files Browse the repository at this point in the history
  • Loading branch information
wujie committed Jan 16, 2024
1 parent 6b22290 commit 0bbbefa
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 85 deletions.
63 changes: 17 additions & 46 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ on:
push:
tags:
- 'v*'
# on:
# push:
# branches:
# - '*'
# pull_request:
# workflow_dispatch:

jobs:
build-release:
strategy:
fail-fast: false
matrix:
platform: [macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
Expand All @@ -26,60 +19,38 @@ jobs:
QINIU_SECRET_KEY: ${{ secrets.QINIU_SECRET_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:

- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

- name: Checkout repository
uses: actions/checkout@v3

- name: Node.js setup
uses: actions/setup-node@v3
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18

- name: Rust setup
uses: dtolnay/rust-toolchain@stable

- name: Rust Cache
uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
workspaces: ./src-tauri

- run: npm install

- run: node script/ffmpeg.js v0.0.8

- name: Build
uses: tauri-apps/tauri-action@v0

# - run: npm run tauri build
# - run: node script/upload.js ${{ steps.get_version.outputs.VERSION }}
- run: node script/upload.js v0.0.8
- run: node script/ffmpeg.js ${{ github.ref_name }}
- uses: tauri-apps/tauri-action@v0
- run: node script/upload.js ${{ github.ref_name }}
- name: Upload release
if: github.event.release.tag_name
run: gh release upload ${{ github.event.release.tag_name }} src-tauri/target/release/bundle/${{ runner.os == 'Windows' && 'msi' || 'dmg' }}/ave_${{ github.ref_name }}_x64.${{ runner.os == 'Windows' && 'en-US.msi' || 'dmg' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

updater:
needs: build-release
runs-on: ubuntu-latest
needs: [build-release]
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
QINIU_ACCESS_KEY: ${{ secrets.QINIU_ACCESS_KEY }}
QINIU_SECRET_KEY: ${{ secrets.QINIU_SECRET_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Node.js setup
uses: actions/setup-node@v3
- uses: actions/setup-node@v3
with:
node-version: 18

- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

- name: Checkout repository
uses: actions/checkout@v3

- uses: actions/checkout@v3
- run: npm install
- run: node script/publish.js v0.0.8
- run: node script/publish.js ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion .github/workflows/Test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Test

on: [push, pull_request]
on:
push:
branches: [ main ]

jobs:
build-release:
Expand Down
2 changes: 1 addition & 1 deletion config/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
ffmpegZip: 'http://49.232.147.237',
ffmpegZip: 'https://github.com/eugeneware/ffmpeg-static/releases/latest/download/',
serviceUrl: 'http://ave.jcbsb.com/'
}
91 changes: 54 additions & 37 deletions script/ffmpeg.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const compressing = require('compressing');
const fs= require('fs')
const path = require('path')
const urllib = require('urllib');
Expand All @@ -22,34 +21,45 @@ async function main () {
} else if (platform === 'win32') {
arg = 'win'
}
const url = `${config.ffmpegZip}/ave/${arg}/ffmpeg.zip`
const ff = {
mac: ['ffmpeg-x86_64-apple-darwin', 'ffplay-x86_64-apple-darwin', 'ffprobe-x86_64-apple-darwin'],
win: ['ffmpeg-x86_64-pc-windows-msvc.exe', 'ffplay-x86_64-pc-windows-msvc.exe', 'ffprobe-x86_64-pc-windows-msvc.exe'],
}
const urlRes = ff[arg]
const dir = path.join(__dirname, '../', 'src-tauri/bin')
await fs.mkdirSync(dir)
const tmp = path.join(dir, 'test.zip')
return urllib.request(url, {
streaming: true,
followRedirect: true,
})
.then(async result => {
const r = result.res.pipe(fs.createWriteStream(tmp))
r.on('finish', () => {
console.log('ffmpeg finish')
compressing.zip.uncompress(tmp, dir).then(() => {
console.log('unzip ffmpeg success');
getAveJava(arg, dir)
}).catch(console.error);
})
r.on('error', ((err) => {
console.error(err)
}))
})
.then(() => {
console.log('get ffmpeg done')
if (!fs.existsSync(dir)) {
await fs.mkdirSync(dir)
}
for (let index = 0; index < urlRes.length; index++) {
const ele = urlRes[index]
const tmp = path.join(dir, ele)
const url = `${config.ffmpegZip}/${ele}`
await getFfmpeg(url, tmp)
console.log(ele)
}
await getAveJava(arg, dir)
}

async function getFfmpeg(url, tmp) {
return new Promise((resolve, reject) => {
urllib.request(url, {
streaming: true,
followRedirect: true,
}).then(async result => {
const r = result.res.pipe(fs.createWriteStream(tmp))
r.on('finish', () => {
resolve(r)
})
r.on('error', ((err) => {
reject(err)
}))
}).catch((err) => {
reject(err)
});
})
.catch(console.error);
}

function getAveJava(arg, dir) {
async function getAveJava(arg, dir) {
let url = ''
let name = ''
if (arg === 'darwin' || arg === 'mac') {
Expand All @@ -66,19 +76,26 @@ function getAveJava(arg, dir) {
name = 'ave_java-x86_64-pc-windows-msvc.exe'
url = `https://github.com/schizobulia/ave_java/releases/download/v0.0.1/ave_java.exe`
}
urllib.request(url, {
streaming: true,
followRedirect: true,
}).then((result) => {
const tmp = path.join(dir, name)
const r = result.res.pipe(fs.createWriteStream(tmp))
r.on('finish', () => {
console.log('ave_java finish')
})
r.on('error', ((err) => {
return new Promise((resolve, reject) => {
urllib.request(url, {
streaming: true,
followRedirect: true,
}).then((result) => {
const tmp = path.join(dir, name)
const r = result.res.pipe(fs.createWriteStream(tmp))
r.on('finish', () => {
console.log('ave_java finish')
resolve(true)
})
r.on('error', ((err) => {
console.error(err)
reject(err)
}))
}).catch((err) => {
console.error(err)
}))
}).catch(console.error)
reject(err)
})
})
}

main()

0 comments on commit 0bbbefa

Please sign in to comment.