Skip to content

Commit

Permalink
perf: improve actions
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Sep 2, 2023
1 parent 9f900ad commit 1f92bae
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on: [push, pull_request]

jobs:
build:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- cron: "*/30 * * * *"

jobs:
check:
release:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
Expand Down Expand Up @@ -49,8 +49,8 @@ jobs:
- name: Build
run: npm run build

- name: Run Deploy
run: npx tsx ./scripts/deploy.ts
- name: Run release script
run: npx tsx ./scripts/release.ts

- name: Publish to NPM
run: npm publish --ignore-scripts || true
Expand Down
10 changes: 3 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
### 1.1.16

- Upgrade fmt.stub.php (f812fd8e336c3ec304e7175e698dafb3)
- Upgrade fmt.stub.php [(V993.0.0)](https://github.com/driade/phpfmt8/releases/tag/v993.0.0)

### 1.1.15

- Upgrade fmt.stub.php (d8b4a6889a662bc1fbdef6380f742d68)

### 1.1.14

- Upgrade fmt.stub.php (d8b4a6889a662bc1fbdef6380f742d68)
- Upgrade fmt.stub.php [(V992.0.0)](https://github.com/driade/phpfmt8/releases/tag/v992.0.0)

### 1.1.13

- Upgrade fmt.stub.php (a67d6dd6d2475326d435bdcd97d4f8cd)
- Upgrade fmt.stub.php [(V891.0.0)](https://github.com/driade/phpfmt8/releases/tag/v891.0.0)

### 1.1.12

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@
"devDependencies": {
"@kokororin/prettierrc": "^0.1.1",
"@types/adm-zip": "^0.5.0",
"@types/debug": "^4.1.8",
"@types/fs-extra": "^11.0.1",
"@types/md5": "^2.3.2",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.13",
Expand All @@ -639,6 +641,7 @@
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"fs-extra": "^11.1.1",
"md5": "^2.3.0",
"mocha": "^9.2.0",
"prettier": "^2.8.8",
Expand Down
42 changes: 27 additions & 15 deletions scripts/deploy.ts → scripts/release.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
import path from 'path';
import fs from 'fs';
import os from 'os';
import * as fs from 'fs-extra';
import phpfmt from 'phpfmt';
import AdmZip from 'adm-zip';
import md5 from 'md5';
import * as semver from 'semver';
import debug from 'debug';
import { simpleGit } from 'simple-git';
import { downloadFile } from '../src/utils';

debug.enable('simple-git,simple-git:*');

const pkgJsonPath = path.join(__dirname, '../package.json');
const changelogPath = path.join(__dirname, '../CHANGELOG.md');

void (async () => {
try {
const pkg = JSON.parse(String(await fs.promises.readFile(pkgJsonPath)));
const pkg = JSON.parse(String(await fs.readFile(pkgJsonPath)));
const currentVersion = pkg.version;

const pharUrl = phpfmt.v2.installUrl;
const pharVersionUrl = phpfmt.v2.installUrl.replace(
phpfmt.v2.pharName,
'version.txt'
);

console.log(`Download url: ${pharUrl}`);

const tmpDir = path.join(os.tmpdir(), 'vscode-phpfmt');
// eslint-disable-next-line no-sync
if (!fs.existsSync(tmpDir)) {
await fs.promises.mkdir(tmpDir);
if (!(await fs.pathExists(tmpDir))) {
await fs.mkdirp(tmpDir);
}
const currentVsixPath = path.join(tmpDir, `${currentVersion}.vsix`);
const latestPharPath = path.join(tmpDir, phpfmt.v2.pharName);
const latestPharVersionPath = path.join(
tmpDir,
`${phpfmt.v2.pharName}.version.txt`
);

console.log('Downloading vsix...');
await downloadFile(
`https://kokororin.gallery.vsassets.io/_apis/public/gallery/publisher/kokororin/extension/vscode-phpfmt/${currentVersion}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage`,
currentVsixPath
);

const stats = await fs.promises.stat(currentVsixPath);
const stats = await fs.stat(currentVsixPath);
if (stats.size < 10000) {
console.log('Download vsix failed');
return;
Expand All @@ -51,7 +62,11 @@ void (async () => {

console.log('Downloading latest phar...');
await downloadFile(pharUrl, latestPharPath);
const latestPharData = String(await fs.promises.readFile(latestPharPath));
await downloadFile(pharVersionUrl, latestPharVersionPath);
const latestPharData = String(await fs.readFile(latestPharPath));
const latestPharVersion = String(await fs.readFile(latestPharVersionPath));
console.log(`Latest phar version: ${latestPharVersion}`);

const latestMd5 = md5(latestPharData);
console.log(`Latest md5: ${latestMd5}`);

Expand All @@ -63,21 +78,18 @@ void (async () => {
const newVersion = semver.inc(currentVersion, 'patch');
console.log(`New version: ${newVersion}`);

let changelogData = String(await fs.promises.readFile(changelogPath));
let changelogData = String(await fs.readFile(changelogPath));
changelogData = `### ${newVersion}
- Upgrade ${phpfmt.v2.pharName} (${latestMd5})
- Upgrade ${phpfmt.v2.pharName} [(V${latestPharVersion})](https://github.com/driade/phpfmt8/releases/tag/v${latestPharVersion})
${changelogData}`;
await fs.promises.writeFile(changelogPath, changelogData);
await fs.writeFile(changelogPath, changelogData);

pkg.version = newVersion;
await fs.promises.writeFile(
pkgJsonPath,
JSON.stringify(pkg, null, 2) + os.EOL
);
await fs.writeFile(pkgJsonPath, JSON.stringify(pkg, null, 2) + os.EOL);

await fs.promises.writeFile(phpfmt.v2.pharPath, latestPharData);
await fs.writeFile(phpfmt.v2.pharPath, latestPharData);

const git = simpleGit({
config: [
Expand Down
52 changes: 51 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@
dependencies:
"@types/node" "*"

"@types/debug@^4.1.8":
version "4.1.8"
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.8.tgz#cef723a5d0a90990313faec2d1e22aee5eecb317"
integrity sha512-/vPO1EPOs306Cvhwv7KfVfYvOJqA/S/AXjaHQiJboCZzcNDb+TIJFN9/2C9DZ//ijSKWioNyUxD792QmDJ+HKQ==
dependencies:
"@types/ms" "*"

"@types/fs-extra@^11.0.1":
version "11.0.1"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-11.0.1.tgz#f542ec47810532a8a252127e6e105f487e0a6ea5"
integrity sha512-MxObHvNl4A69ofaTRU8DFqvgzzv8s9yRtaPPm5gud9HDNvpB3GPQFvNuTWAI59B9huVGV5jXYJwbCsmBsOGYWA==
dependencies:
"@types/jsonfile" "*"
"@types/node" "*"

"@types/json-schema@^7.0.9":
version "7.0.11"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
Expand All @@ -302,6 +317,13 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==

"@types/jsonfile@*":
version "6.1.1"
resolved "https://registry.yarnpkg.com/@types/jsonfile/-/jsonfile-6.1.1.tgz#ac84e9aefa74a2425a0fb3012bdea44f58970f1b"
integrity sha512-GSgiRCVeapDN+3pqA35IkQwasaCh/0YFH5dEF6S88iDvEn901DjOeH3/QPY+XYP1DFzDZPvIvfeEgk+7br5png==
dependencies:
"@types/node" "*"

"@types/md5@^2.3.2":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@types/md5/-/md5-2.3.2.tgz#529bb3f8a7e9e9f621094eb76a443f585d882528"
Expand All @@ -317,6 +339,11 @@
resolved "https://registry.npmjs.org/@types/mocha/-/mocha-9.1.1.tgz#e7c4f1001eefa4b8afbd1eee27a237fee3bf29c4"
integrity sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw==

"@types/ms@*":
version "0.7.31"
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197"
integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==

"@types/node@*":
version "20.5.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.5.7.tgz#4b8ecac87fbefbc92f431d09c30e176fc0a7c377"
Expand Down Expand Up @@ -1355,6 +1382,15 @@ for-each@^0.3.3:
dependencies:
is-callable "^1.1.3"

fs-extra@^11.1.1:
version "11.1.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.1.tgz#da69f7c39f3b002378b0954bb6ae7efdc0876e2d"
integrity sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -1535,7 +1571,7 @@ gopd@^1.0.1:
dependencies:
get-intrinsic "^1.1.3"

graceful-fs@^4.2.4:
graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4:
version "4.2.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==
Expand Down Expand Up @@ -1935,6 +1971,15 @@ json5@^1.0.2:
dependencies:
minimist "^1.2.0"

jsonfile@^6.0.1:
version "6.1.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
dependencies:
universalify "^2.0.0"
optionalDependencies:
graceful-fs "^4.1.6"

kind-of@^6.0.3:
version "6.0.3"
resolved "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
Expand Down Expand Up @@ -2934,6 +2979,11 @@ unbox-primitive@^1.0.2:
has-symbols "^1.0.3"
which-boxed-primitive "^1.0.2"

universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==

uri-js@^4.2.2:
version "4.4.1"
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e"
Expand Down

0 comments on commit 1f92bae

Please sign in to comment.