feat: zip 变更 tgz, 新增 dash feed (#411)

This commit is contained in:
孤城落寞 2022-08-30 16:26:19 +08:00 committed by GitHub
parent 8061086f1e
commit f75d1cb094
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 65 deletions

View File

@ -13,26 +13,18 @@ jobs:
with:
node-version: 16
- run: npm -v
- run: node -v
- run: npm install
- run: npm run build
- run: npm run dash
- name: Compress linux-command.docset.
run: zip -r -y linux-command.docset.zip . -x "node_modules/*"
working-directory: .deploy/linux-command.docset
- run: cp -rp .deploy/linux-command.docset/linux-command.docset.zip ./
- run: rm -rf .deploy/linux-command.docset
- name: Generate Contributors Images
uses: jaywcjlove/github-action-contributors@main
with:
filter-author: (renovate\[bot\]|renovate-bot|dependabot\[bot\])
avatarSize: 42
- run: cp CONTRIBUTORS.svg .deploy
- name: Build Linux Command
run: |
npm install
npm run dash
cp CONTRIBUTORS.svg .deploy
rm -rf .deploy/linux-command.docset
- name: Create Tag
id: create_tag
@ -40,10 +32,14 @@ jobs:
with:
package-path: ./package.json
- name: get tag version
- name: Get Tag Version
id: tag_version
uses: jaywcjlove/changelog-generator@v1.5.3
- name: Update Dash Feed
run: |
echo "<entry><version>${{steps.create_tag.outputs.versionNumber}}</version><url>https://jaywcjlove.github.io/linux-command/linux-command.docset.tgz</url></entry>" > .deploy/linux-command-docset.xml
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
@ -64,7 +60,7 @@ jobs:
uses: ncipollo/release-action@v1
if: steps.create_tag.outputs.successful
with:
artifacts: 'linux-command.docset.zip'
artifacts: 'linux-command.docset.tgz'
token: ${{ secrets.GITHUB_TOKEN }}
name: ${{ steps.create_tag.outputs.version }}
tag: ${{ steps.create_tag.outputs.version }}
@ -106,18 +102,19 @@ jobs:
http://localhost:9665/
```
- run: npm install @jsdevtools/npm-publish -g
- run: npm-publish --token="${{ secrets.NPM_TOKEN }}" ./package.json
- run: rm -rf .deploy/linux-command.docset.zip
- name: Push Npm
run: |
npm install @jsdevtools/npm-publish -g
npm-publish --token="${{ secrets.NPM_TOKEN }}" ./package.json
# Create Docker Image
- name: Docker login
run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
- name: Build linux-command image
run: docker image build -t linux-command .
run: |
rm -rf .deploy/linux-command.docset.tgz
docker image build -t linux-command .
- name: Tags & Push image(latest)
run: |

View File

@ -27,9 +27,9 @@
"devDependencies": {
"@uiw/github-corners": "~1.5.11",
"@wcj/dark-mode": "~1.0.14",
"archiver": "~5.3.0",
"colors-cli": "~1.0.28",
"ejs": "~3.1.6",
"compressing": "^1.6.2",
"fs-extra": "~10.1.0",
"markdown-to-html-cli": "~3.4.1",
"sitemap-generator": "~8.5.1",

View File

@ -2,7 +2,8 @@ import fs from 'fs-extra';
import path from 'path';
import { resolve as pathResolve, join as pathJoin } from 'path';
import sqlite3 from 'sqlite3';
import archiver from 'archiver';
import {tgz} from 'compressing';
import { spawn } from 'child_process';
import {fileURLToPath} from 'url';
const __filename = fileURLToPath(import.meta.url);
@ -103,45 +104,6 @@ async function buildApi(dbPath) {
await createDatabase(arr, dbPath);
}
function compressing() {
new Promise((resolve, reject) => {
const outputPaht = pathJoin(process.cwd(), '.deploy', 'linux-command.docset.zip');
// create a file to stream archive data to.
const output = fs.createWriteStream(outputPaht);
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
});
// listen for all archive data to be written
// 'close' event is fired only when a file descriptor is involved
output.on('close', () => {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
resolve();
});
// good practice to catch warnings (ie stat failures and other non-blocking errors)
archive.on('warning', (err) => {
if (err.code === 'ENOENT') {
console.log('warning:::', err)
// log warning
} else {
// throw error
throw err;
}
});
// good practice to catch this error explicitly
archive.on('error', function(err) {
reject(err);
});
// pipe archive data to the file
archive.pipe(output);
archive.directory(pathJoin(process.cwd(), '.deploy', 'linux-command.docset'), false);
archive.finalize();
})
}
async function build() {
console.log(`mkdir -p ${RESOURCES_DIR}`);
@ -154,8 +116,12 @@ async function build() {
console.info('build documents');
await buildApi(DB_PATH);
console.info('compressing zip');
await compressing();
console.info('compressing tgz');
// https://github.com/node-modules/compressing/issues/42 建议最好休眠15s等待其余资源复制完毕
spawn("sleep", ['15'])
const tgzPath = pathJoin(process.cwd(), '.deploy', 'linux-command.docset');
const outputPath = pathJoin(process.cwd(), '.deploy', 'linux-command.docset.tgz');
await tgz.compressDir(tgzPath, outputPath);
}
build()