Skip to content

Commit

Permalink
feat: zip 变更 tgz, 新增 dash feed (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
gclm authored Aug 30, 2022
1 parent 8061086 commit f75d1cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 65 deletions.
41 changes: 19 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,33 @@ 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
uses: jaywcjlove/create-tag-action@v1.3.6
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:
Expand All @@ -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 }}
Expand Down Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
50 changes: 8 additions & 42 deletions scripts/dash.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}`);
Expand All @@ -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()
Expand Down

0 comments on commit f75d1cb

Please sign in to comment.