Skip to content

Commit

Permalink
Added release workflow (KreativJos#74)
Browse files Browse the repository at this point in the history
Added
- Manual workflow
- Package script
- Package step in pipeline
- Build step in tests workflow
- Yarn compile
- Completed release workflow

Fixed
- Renamed deploy script to publish
- Workflow edited to push @ test branch
- Release workflow dependency
- eslint line end unix
- Fixed eslint errors
- Updated typescript-eslint parser and plugin

Co-authored-by: Jos Wagenmakers <[email protected]>
Co-authored-by: Sante Barbuto <[email protected]>
  • Loading branch information
3 people authored Apr 18, 2022
1 parent 44928ab commit a8951ce
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 130 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
}
],
"linebreak-style": [
"warn",
"windows"
"error",
"unix"
],
"quotes": [
"error",
Expand All @@ -44,4 +44,4 @@
}
]
}
}
}
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

*.js text eol=lf
*.ts text eol=lf
75 changes: 75 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Release

on:
release:
types: [released]

env:
NODE_VERSION: '16'
EXTENSION_OUTPUT_FILE: 'csharpextensions.vsix'

jobs:
update:
name: Update Changelog
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: main

- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1
with:
release-notes: ${{ github.event.release.body }}
latest-version: ${{ github.event.release.name }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md

prepare:
name: Prepare
runs-on: ubuntu-latest
needs: update
if: "success()"
steps:
- name: Prepare build
uses: DerYeger/yarn-setup-action@master
with:
node-version: ${{ env.NODE_VERSION }}

package:
name: Package
runs-on: ubuntu-latest
needs: prepare
if: "success()"
steps:
- name: Prepare Package
uses: DerYeger/yarn-setup-action@master
with:
node-version: ${{ env.NODE_VERSION }}
- name: Yarn package
run: yarn package -o ${{ env.EXTENSION_OUTPUT_FILE }}

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.EXTENSION_OUTPUT_FILE }}
path: ${{ env.EXTENSION_OUTPUT_FILE }}
retention-days: 30
- name: Publish Patch
run: yarn publish --patch
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}
if: "contains(github.event.release.body, 'Fixed')"
- name: Publish Minor
run: yarn publish --minor
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}
if: "contains(github.event.release.body, 'Added')"
- name: Push tags
run: git push --tags
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ env.NODE_VERSION }}
- run: yarn install
- name: Install dependencies
run: yarn install
- name: Build extension
run: yarn compile
- run: xvfb-run -a yarn test
if: runner.os == 'Linux'
- run: yarn test
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@
},
"scripts": {
"vscode:prepublish": "tsc -p ./ && webpack --mode production",
"compile": "tsc -p ./ && yarn run lint",
"compileDev": "tsc -p ./ && yarn run lint && webpack --mode development",
"compile": "tsc -p ./ && yarn lint",
"compileDev": "tsc -p ./ && yarn lint && webpack --mode development",
"watch": "tsc -watch -p ./",
"lint": "eslint src --ext ts",
"pretest": "tsc -p ./",
"test": "node ./out/test/runTest.js"
"test": "node ./out/test/runTest.js",
"package": "vsce package --yarn",
"publish": "vsce publish --yarn"
},
"devDependencies": {
"@types/glob": "^7.1.3",
Expand All @@ -186,8 +187,8 @@
"@types/node": "^12.11.7",
"@types/vscode": "^1.56.0",
"@types/xml2js": "^0.4.9",
"@typescript-eslint/eslint-plugin": "^4.28.5",
"@typescript-eslint/parser": "^4.28.5",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"@vscode/test-electron": "^2.1.3",
"eslint": "^7.19.0",
"glob": "^7.1.6",
Expand Down
4 changes: 2 additions & 2 deletions src/codeActionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class CodeActionProvider implements VSCodeCodeActionProvider {
addInitalizeFromCtor(MemberGenerationType.ReadonlyProperty);
addInitalizeFromCtor(MemberGenerationType.Property);

const ctorPAction = this.getCtorpAction(document, range, context, token);
const ctorPAction = this.getCtorpAction(document);

if (ctorPAction) codeActions.push(ctorPAction);

Expand Down Expand Up @@ -117,7 +117,7 @@ export default class CodeActionProvider implements VSCodeCodeActionProvider {
}
}

private getCtorpAction(document: TextDocument, range: Range, context: CodeActionContext, token: CancellationToken): CodeAction | undefined {
private getCtorpAction(document: TextDocument): CodeAction | undefined {
const editor = window.activeTextEditor;

if (!editor) return;
Expand Down
26 changes: 19 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ export function activate(context: vscode.ExtensionContext): void {
const extension = Extension.GetInstance();

Extension.GetKnownTemplates().forEach(template => {
context.subscriptions.push(vscode.commands.registerCommand(template.getCommand(),
async (args: any) => await extension.createFromTemplate(args, template)));
context.subscriptions.push(
vscode.commands.registerCommand(
template.getCommand(),
async (options: RegisterCommandCallbackArgument) => await extension.createFromTemplate(options, template)
)
);
});

const documentSelector: vscode.DocumentSelector = {
Expand All @@ -34,17 +38,17 @@ export function deactivate(): void { /* Nothing to do here */ }
export class Extension {
private constructor() { /**/ }

private _getIncomingPath(args: any): string | undefined {
if (args) {
return args._fsPath || args.fsPath || args.path;
private _getIncomingPath(options: RegisterCommandCallbackArgument): string | undefined {
if (options) {
return options._fsPath || options.fsPath || options.path;
}

return vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length
? vscode.workspace.workspaceFolders[0].uri.fsPath : undefined;
}

public async createFromTemplate(args: any, template: Template): Promise<void> {
const incomingPath = this._getIncomingPath(args);
public async createFromTemplate(options: RegisterCommandCallbackArgument, template: Template): Promise<void> {
const incomingPath = this._getIncomingPath(options);

if (!incomingPath) {
vscode.window.showErrorMessage(`Could not find the path for this action.${EOL}If this problem persists, please create an issue in the github repository.`);
Expand Down Expand Up @@ -96,6 +100,7 @@ export class Extension {

private static TemplatesPath = 'templates';
private static KnownTemplates: Map<string, Template>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private static CurrentVscodeExtension: vscode.Extension<any> | undefined = undefined;
private static Instance: Extension;
private static KnownExtensionNames = [
Expand All @@ -111,6 +116,7 @@ export class Extension {
return this.Instance;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private static GetCurrentVscodeExtension(): vscode.Extension<any> | undefined {
if (!this.CurrentVscodeExtension) {
for (let i = 0; i < this.KnownExtensionNames.length; i++) {
Expand Down Expand Up @@ -154,3 +160,9 @@ export class Extension {
return this.KnownTemplates;
}
}

interface RegisterCommandCallbackArgument {
_fsPath: string,
fsPath: string,
path: string,
}
2 changes: 1 addition & 1 deletion src/template/xamlTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class XamlTemplate extends Template {
const csTemplatePath = this._getTemplatePath(templatesPath, `${this.getName()}.cs`);
const xamlFilePath = `${pathWithoutExtension}.xaml`;
const csFilePath = `${pathWithoutExtension}.xaml.cs`;

await this._createFile(csTemplatePath, csFilePath, filename);
await this._createFile(xamlTemplatePath, xamlFilePath, filename);
}
Expand Down
Loading

0 comments on commit a8951ce

Please sign in to comment.