Skip to content

Commit 5149fd0

Browse files
committed
chore: add release workflow
1 parent cb476c5 commit 5149fd0

File tree

5 files changed

+118
-4
lines changed

5 files changed

+118
-4
lines changed

.github/workflows/release.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest]
14+
node-version: [12]
15+
steps:
16+
- name: Fetch repository
17+
uses: actions/checkout@v2
18+
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
24+
- name: Cache node modules
25+
uses: actions/cache@v2
26+
with:
27+
path: node_modules
28+
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
29+
restore-keys: |
30+
${{ runner.OS }}-build-${{ env.cache-name }}-
31+
${{ runner.OS }}-build-
32+
${{ runner.OS }}-
33+
34+
- name: yarn install, build, bundle
35+
run: |
36+
yarn install
37+
yarn make-release
38+
39+
- name: Commit files
40+
run: |
41+
git config --global user.name 'Roy Li'
42+
git config --global user.email '[email protected]'
43+
git commit -am "chore: update appcast.json"
44+
45+
- name: Push changes
46+
uses: ad-m/github-push-action@master
47+
with:
48+
github_token: ${{ secrets.GITHUB_TOKEN }}
49+
50+
- uses: ncipollo/release-action@v1
51+
with:
52+
artifacts: 'release/*.bobplugin'
53+
token: ${{ secrets.GITHUB_TOKEN }}

appcast.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"identifier": "dev.royli.bob-plugin-deepl-translate",
3+
"versions": [
4+
]
5+
}

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
"name": "bob-plugin-deepl-translate",
33
"version": "0.1.0",
44
"author": "Roy Li <[email protected]>",
5+
"homepage": "https://github.com/geekdada/bob-plugin-deepl-translate",
6+
"repository": "https://github.com/geekdada/bob-plugin-deepl-translate.git",
57
"license": "MIT",
68
"private": true,
79
"scripts": {
810
"clean": "rimraf build && rimraf release",
911
"build": "run-s clean && cross-env NODE_ENV=production rollup -c rollup.config.js",
12+
"bundle": "node scripts/bundle.js",
13+
"bundle:watch": "nodemon --watch build scripts/bundle.js",
14+
"make-release": "run-s build bundle update-appcast",
1015
"dev": "run-s clean && cross-env NODE_ENV=development rollup -c rollup.config.js --watch",
1116
"type-check": "tsc --noEmit",
12-
"bundle": "node scripts/bundle.js",
13-
"bundle:watch": "nodemon --watch build scripts/bundle.js"
17+
"update-appcast": "node scripts/update-appcast.js"
1418
},
1519
"dependencies": {
1620
"@rollup/plugin-commonjs": "^16.0.0",

scripts/bundle.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ function generateInfo() {
1111
summary: '',
1212
icon: '115',
1313
author: 'Roy Li',
14-
homepage: 'https://royli.dev',
14+
homepage: 'https://github.com/geekdada/bob-plugin-deepl-translate.git',
15+
appcast:
16+
'https://github.com/geekdada/bob-plugin-deepl-translate/raw/master/appcast.json',
1517
minBobVersion: '0.5.0',
1618
options: [
1719
{
@@ -68,7 +70,6 @@ async function main() {
6870
const info = {
6971
...generateInfo(),
7072
version,
71-
appcast: '',
7273
}
7374

7475
await fs.writeJson(join(buildDir, 'info.json'), info)

scripts/update-appcast.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const path = require('path')
2+
const fs = require('fs-extra')
3+
const crypto = require('crypto')
4+
5+
const pkg = require('../package.json')
6+
const plugAppcast = require('../appcast.json')
7+
const githubRelease = `https://github.com/geekdada/bob-plugin-deepl-translate/releases/download`
8+
9+
function main() {
10+
const pkgName = 'bob-plugin-deepl-translate'
11+
const pkgPath = path.join(
12+
__dirname,
13+
`../release/${pkgName}-v${pkg.version}.bobplugin`,
14+
)
15+
const appcastPath = path.join(__dirname, '../appcast.json')
16+
17+
const fileBuffer = fs.readFileSync(pkgPath)
18+
const sum = crypto.createHash('sha256')
19+
sum.update(fileBuffer)
20+
const hex = sum.digest('hex')
21+
22+
const version = {
23+
version: pkg.version,
24+
desc:
25+
'https://github.com/geekdada/bob-plugin-deepl-translate/blob/master/CHANGELOG.md',
26+
sha256: hex,
27+
url: `${githubRelease}/v${pkg.version}/${pkgName}-v${pkg.version}.bobplugin`,
28+
minBobVersion: '0.5.0',
29+
}
30+
31+
let versions = (plugAppcast && plugAppcast.versions) || []
32+
33+
if (!Array.isArray(versions)) versions = []
34+
35+
const index = versions.findIndex((v) => v.version === pkg.version)
36+
37+
if (index === -1) {
38+
versions.splice(0, 0, version)
39+
} else {
40+
versions.splice(index, 1, version)
41+
}
42+
43+
const appcastData = {
44+
identifier: 'dev.royli.bob-plugin-deepl-translate',
45+
versions,
46+
}
47+
48+
fs.outputJSONSync(appcastPath, appcastData, { spaces: 2 })
49+
}
50+
51+
main()

0 commit comments

Comments
 (0)