Skip to content

Commit 0d048f1

Browse files
committed
chore: upload the package as artifact on pr
1 parent 7bb056e commit 0d048f1

File tree

10 files changed

+135
-81
lines changed

10 files changed

+135
-81
lines changed

.github/workflows/build-check.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,26 @@ jobs:
2020
with:
2121
node-version: ${{ matrix.node-version }}
2222
cache: 'npm'
23-
- name: 'Install Dependencies'
23+
- name: 'Installing Dependencies'
2424
run: npm ci
25-
- name: 'Lint'
25+
- name: 'Linting'
2626
run: npm run lint
27-
- name: 'Unit Test'
27+
- name: 'Testing(Unit)'
2828
run: npm run test:unit
29-
- name: 'Build'
30-
run: npm run vscode:prepublish
29+
- name: 'Building'
30+
run: ./build.sh "${{ secrets.OAUTHCLIENTID }}" "${{ secrets.OAUTHCLIENTSECRET }}"
31+
- name: 'Preparing VSCE'
32+
run: npm i -g vsce
33+
- name: 'Versioning'
34+
id: version
35+
run: echo "VERSION=1.0.0-beta.$(date +%s)" >> $GITHUB_OUTPUT
36+
- name: 'Packaging'
37+
id: packaging
38+
run: |
39+
vsce package --pre-release --no-update-package-json --no-git-tag-version ${{ steps.version.outputs.VERSION }} && \
40+
echo "PKG_NAME=vscode-cnb-${{ steps.version.outputs.VERSION }}.vsix" >> $GITHUB_OUTPUT
41+
- name: Uploading the Package
42+
uses: actions/upload-artifact@v3
43+
with:
44+
name: ${{ steps.packaging.outputs.PKG_NAME }}
45+
path: ./${{ steps.packaging.outputs.PKG_NAME }}

.github/workflows/marketplace-publish.yml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,21 @@ jobs:
1919
matrix:
2020
node-version: [16.x]
2121
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
22-
2322
steps:
2423
- uses: actions/checkout@v2
2524
- name: Use Node.js ${{ matrix.node-version }}
2625
uses: actions/setup-node@v2
2726
with:
2827
node-version: ${{ matrix.node-version }}
2928
cache: 'npm'
30-
- run: echo "VERSION=${GITHUB_REF#refs/*/}"
31-
# add tag value to env
32-
- run: echo "VERSION=${GITHUB_REF#refs/*/}" | sed 's/v//' >> $GITHUB_ENV
33-
- run: echo "version:\ ${{ env.VERSION }}"
34-
# globally install vsce
35-
- run: npm i -g vsce
36-
# replace client_id
37-
- run: sed -i "s/clientId:\ 'vscode-cnb'/clientId:\ '${{ secrets.OAUTHCLIENTID }}'/" src/models/config.ts
38-
# replace client_secret
39-
- run: sed -i "s/clientSecret:\ ''/clientSecret:\ '${{ secrets.OAUTHCLIENTSECRET }}'/" src/models/config.ts
40-
- run: echo "src/models/config.ts\n" && cat src/models/config.ts
41-
# use env.VERSION to replace version property in package.json
42-
- run: sed -i 's/\"version\":\ \"[0-9]\.[0-9]\.[0-9]\"/\"version\":\ \"${{ env.VERSION }}\"/' package.json
43-
- run: echo "package.json\n" && cat package.json
44-
- run: npm ci
45-
# publish to vscode extension marketplace
46-
- run: vsce publish -p ${{ secrets.VSCETOKEN }}
29+
- name: 'Versioning'
30+
id: version
31+
run: echo "VERSION=${{ github.ref_name }}" | sed 's/v//' >> $GITHUB_OUTPUT
32+
- name: 'Installing Dependencies'
33+
run: npm ci
34+
- name: 'Building'
35+
run: ./build.sh "${{ secrets.OAUTHCLIENTID }}" "${{ secrets.OAUTHCLIENTSECRET }}"
36+
- name: 'Preparing VSCE'
37+
run: npm i -g vsce
38+
- name: 'Publishing'
39+
run: vsce publish --no-git-tag-version --no-update-package-json -p ${{ secrets.VSCETOKEN }} ${{ steps.version.outputs.VERSION }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ node_modules
55
*.vsix
66
.DS_Store
77
.idea
8+
.vscode/api-key.txt

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
// See http://go.microsoft.com/fwlink/?LinkId=827846
33
// for the documentation about the extensions.json format
4-
"recommendations": ["dbaeumer.vscode-eslint", "amodio.tsl-problem-matcher"]
4+
"recommendations": ["dbaeumer.vscode-eslint", "amodio.tsl-problem-matcher", "rioj7.command-variable"]
55
}

.vscode/settings.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313
"editor.formatOnSave": true,
1414
"cSpell.words": [
1515
"ASPNETCORE",
16+
"CLIENTID",
17+
"CLIENTSECRET",
1618
"fluentui",
1719
"iconfont",
1820
"ings",
1921
"nbsp",
22+
"OAUTHCLIENTID",
23+
"OAUTHCLIENTSECRET",
2024
"randomstring",
2125
"singleline",
2226
"tailwindcss",
23-
"untildify"
27+
"untildify",
28+
"vsix"
2429
],
2530
"json.format.enable": false,
2631
"eslint.alwaysShowStatus": true,

.vscode/tasks.json

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,31 @@
77
"NODE_ENV": "Development"
88
}
99
},
10+
"inputs": [
11+
{
12+
"id": "ClientId",
13+
"type": "command",
14+
"command": "extension.commandvariable.file.content",
15+
"args": {
16+
"fileName": "${workspaceFolder}/.vscode/api-key.txt",
17+
"key": "CLIENTID"
18+
}
19+
},
20+
{
21+
"id": "ClientSecret",
22+
"type": "command",
23+
"command": "extension.commandvariable.file.content",
24+
"args": {
25+
"fileName": "${workspaceFolder}/.vscode/api-key.txt",
26+
"key": "CLIENTSECRET"
27+
}
28+
}
29+
],
1030
"tasks": [
1131
{
12-
"type": "npm",
13-
"script": "watch",
32+
"type": "shell",
33+
"label": "npm: watch",
34+
"command": "npm run watch -- --env CLIENTID=${input:ClientId} --env CLIENTSECRET=${input:ClientSecret}",
1435
"problemMatcher": ["$ts-webpack-watch", "$tslint-webpack-watch"],
1536
"isBackground": true,
1637
"presentation": {
@@ -19,7 +40,8 @@
1940
},
2041
"group": {
2142
"kind": "build"
22-
}
43+
},
44+
"runOptions": { "reevaluateOnRerun": false }
2345
},
2446
{
2547
"type": "npm",

build.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
npm run package -- --env CLIENTID="${1?"Please provide the CLIENTID"}" --env CLIENTSECRET="${2?"Please provide the CLIENTSECRET"}"
6+
npm run ui:package
7+

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,12 +1015,11 @@
10151015
]
10161016
},
10171017
"scripts": {
1018-
"vscode:prepublish": "npm run package",
10191018
"compile": "webpack && npm run ui:compile",
10201019
"ui:compile": "webpack -c ./ui/webpack.config.mjs",
10211020
"watch": "webpack --watch",
10221021
"ui:watch": "webpack watch -c ./ui/webpack.config.mjs",
1023-
"package": "webpack --mode production --devtool hidden-source-map && npm run ui:package",
1022+
"package": "webpack --mode production --devtool hidden-source-map",
10241023
"ui:package": "webpack --mode production --devtool hidden-source-map -c ./ui/webpack.config.mjs",
10251024
"compile-tests": "tsc -p ./tsconfig.integration.json --outDir out",
10261025
"test:integration:watch": "npm run compile-tests -- --watch",

src/models/config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ export interface IExtensionConfig {
1919

2020
export const isDev = () => process.env.NODE_ENV === 'Development';
2121

22+
declare const CNBLOGS_CLIENTID: string;
23+
declare const CNBLOGS_CLIENTSECRET: string;
24+
2225
export const defaultConfig: IExtensionConfig = {
2326
oauth: {
2427
authority: 'https://oauth.cnblogs.com',
2528
tokenEndpoint: '/connect/token',
2629
authorizeEndpoint: '/connect/authorize',
2730
userInfoEndpoint: '/connect/userinfo',
28-
clientId: 'vscode-cnb',
29-
clientSecret: '',
31+
clientId: CNBLOGS_CLIENTID,
32+
clientSecret: CNBLOGS_CLIENTSECRET,
3033
responseType: 'code',
3134
scope: 'openid profile CnBlogsApi CnblogsAdminApi',
3235
revocationEndpoint: '/connection/revocation',

webpack.config.mjs

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
12
/* eslint-disable @typescript-eslint/naming-convention */
23
//@ts-check
34

@@ -7,65 +8,73 @@ import path from 'path';
78
import CopyWebpackPlugin from 'copy-webpack-plugin';
89
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
910
import { fileURLToPath } from 'url';
11+
import webpack from 'webpack';
1012

1113
const __filename = fileURLToPath(import.meta.url);
1214
const __dirname = path.dirname(__filename);
1315

1416
//@ts-check
1517
/** @typedef {import('webpack').Configuration} WebpackConfig **/
1618

17-
/** @type WebpackConfig */
18-
const extensionConfig = {
19-
target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
20-
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
19+
export default env => {
20+
/** @type WebpackConfig */
21+
const extensionConfig = {
22+
target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
23+
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
2124

22-
entry: { extension: './src/extension.ts', markdown: './src/markdown/markdown.entry.ts' }, // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
23-
output: {
24-
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
25-
path: path.resolve(__dirname, 'dist'),
26-
filename: '[name].js',
27-
libraryTarget: 'commonjs2',
28-
},
29-
externals: {
30-
vscode: 'commonjs vscode', // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
31-
// modules added here also need to be added in the .vscodeignore file
32-
},
33-
resolve: {
34-
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
35-
extensions: ['.ts', '.js'],
36-
plugins: [new TsconfigPathsPlugin({ configFile: './tsconfig.json' })],
37-
},
38-
module: {
39-
rules: [
40-
{
41-
test: /\.ts$/,
42-
exclude: /node_modules\/(?!lodash-es.*)/,
43-
use: [
25+
entry: { extension: './src/extension.ts', markdown: './src/markdown/markdown.entry.ts' }, // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
26+
output: {
27+
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
28+
path: path.resolve(__dirname, 'dist'),
29+
filename: '[name].js',
30+
libraryTarget: 'commonjs2',
31+
},
32+
externals: {
33+
vscode: 'commonjs vscode', // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
34+
// modules added here also need to be added in the .vscodeignore file
35+
},
36+
resolve: {
37+
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
38+
extensions: ['.ts', '.js'],
39+
plugins: [new TsconfigPathsPlugin({ configFile: './tsconfig.json' })],
40+
},
41+
module: {
42+
rules: [
43+
{
44+
test: /\.ts$/,
45+
exclude: /node_modules\/(?!lodash-es.*)/,
46+
use: [
47+
{
48+
loader: 'ts-loader',
49+
},
50+
],
51+
},
52+
],
53+
},
54+
devtool: 'nosources-source-map',
55+
infrastructureLogging: {
56+
level: 'log', // enables logging required for problem matchers
57+
},
58+
plugins: [
59+
new CopyWebpackPlugin({
60+
patterns: [
4461
{
45-
loader: 'ts-loader',
62+
//Note:- No wildcard is specified hence will copy all files and folders
63+
from: 'src/assets', //Will resolve to RepoDir/src/assets
64+
to: 'assets', //Copies all files from above dest to dist/assets
65+
},
66+
{
67+
from: 'node_modules/@cnblogs/code-highlight-adapter/index.min.css',
68+
to: 'assets/styles/highlight-code-lines.css',
4669
},
4770
],
48-
},
71+
}),
72+
new webpack.DefinePlugin({
73+
CNBLOGS_CLIENTID: JSON.stringify(env.CLIENTID || 'vscode-cnb'),
74+
CNBLOGS_CLIENTSECRET: JSON.stringify(env.CLIENTSECRET || ''),
75+
}),
4976
],
50-
},
51-
devtool: 'nosources-source-map',
52-
infrastructureLogging: {
53-
level: 'log', // enables logging required for problem matchers
54-
},
55-
plugins: [
56-
new CopyWebpackPlugin({
57-
patterns: [
58-
{
59-
//Note:- No wildcard is specified hence will copy all files and folders
60-
from: 'src/assets', //Will resolve to RepoDir/src/assets
61-
to: 'assets', //Copies all files from above dest to dist/assets
62-
},
63-
{
64-
from: 'node_modules/@cnblogs/code-highlight-adapter/index.min.css',
65-
to: 'assets/styles/highlight-code-lines.css',
66-
},
67-
],
68-
}),
69-
],
77+
};
78+
79+
return extensionConfig;
7080
};
71-
export default [extensionConfig];

0 commit comments

Comments
 (0)