Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish Platform Specific Extension #905

Merged
merged 14 commits into from
Jan 26, 2022
29 changes: 0 additions & 29 deletions .github/workflows/build.yml

This file was deleted.

68 changes: 53 additions & 15 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,81 @@ name: Publish Preview release
on:
schedule:
# run every day at 00:15 UTC to avoid high load times at the start of every hour
- cron: '15 0 * * *'
- cron: "15 0 * * *"

jobs:
publish:
name: Publish Preview to VS Code Marketplace
runs-on: ubuntu-latest
build:
name: Package
strategy:
matrix:
include:
- vsce_target: win32-x64
ls_target: windows_amd64
npm_config_arch: x64
- vsce_target: win32-ia32
ls_target: windows_386
npm_config_arch: ia32
- vsce_target: win32-arm64
ls_target: windows_arm64
npm_config_arch: arm
- vsce_target: linux-x64
ls_target: linux_amd64
npm_config_arch: x64
- vsce_target: linux-arm64
ls_target: linux_arm64
npm_config_arch: arm64
- vsce_target: linux-armhf
ls_target: linux_arm
npm_config_arch: arm
- vsce_target: darwin-x64
ls_target: darwin_amd64
npm_config_arch: x64
- vsce_target: darwin-arm64
ls_target: darwin_arm64
npm_config_arch: arm64
runs-on: "ubuntu-latest"
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Set preview in package.json
id: set-preview
run: |
./build/preview

- name: Read extension version
id: ext-version
run: |
content=`cat ./package.json | jq -r .version`
echo "::set-output name=content::$content"

- uses: actions/setup-node@v2
with:
node-version-file: '.nvmrc'

node-version-file: ".nvmrc"
- name: Install dependencies
run: npm ci

- name: vsce package
run: npx -- vsce package --out=${{ runner.temp }}/terraform-${{ steps.ext-version.outputs.content }}.vsix

env:
npm_config_arch: ${{ matrix.npm_config_arch }}
- name: Package VSIX
run: npm run package -- --target=${{ matrix.vsce_target }}
env:
ls_target: ${{ matrix.ls_target }}
- name: Upload vsix as artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.vsce_target }}
path: "*.vsix"
- name: Check latest published version
shell: bash
run: |
export EXTENSION_ID=`cat package.json | jq -r '.publisher + "." + .name'`
npx -- vsce show --json $EXTENSION_ID | jq '.versions[0]'

- name: vsce publish
run: npx -- vsce publish --no-git-tag-version --packagePath=${{ runner.temp }}/terraform-${{ steps.ext-version.outputs.content }}.vsix
publish:
name: Publish All
runs-on: ubuntu-latest
needs: build
if: success() && startsWith( github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v2
- name: Publish Preview Extension
run: npx vsce publish --no-git-tag-version --packagePath $(find . -iname *.vsix)
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}
61 changes: 48 additions & 13 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,36 @@ on:
- 'v[0-9]+.[0-9]+.[0-9]+*'

jobs:
publish:
name: Publish to VS Code Marketplace
runs-on: ubuntu-latest
build:
name: Package
strategy:
matrix:
include:
- vsce_target: win32-x64
ls_target: windows_amd64
npm_config_arch: x64
- vsce_target: win32-ia32
ls_target: windows_386
npm_config_arch: ia32
- vsce_target: win32-arm64
ls_target: windows_arm64
npm_config_arch: arm
- vsce_target: linux-x64
ls_target: linux_amd64
npm_config_arch: x64
- vsce_target: linux-arm64
ls_target: linux_arm64
npm_config_arch: arm64
- vsce_target: linux-armhf
ls_target: linux_arm
npm_config_arch: arm
- vsce_target: darwin-x64
ls_target: darwin_amd64
npm_config_arch: x64
- vsce_target: darwin-arm64
ls_target: darwin_arm64
npm_config_arch: arm64
runs-on: "ubuntu-latest"
steps:
- name: Check out repository
uses: actions/checkout@v2
Expand All @@ -29,18 +56,26 @@ jobs:
node-version-file: '.nvmrc'
- name: Install dependencies
run: npm ci
- name: vsce package
run: npx -- vsce package --out=${{ runner.temp }}/terraform-${{ steps.ext-version.outputs.content }}.vsix
env:
npm_config_arch: ${{ matrix.npm_config_arch }}
- name: Package VSIX
run: npm run package -- --target=${{ matrix.vsce_target }}
env:
ls_target: ${{ matrix.ls_target }}
- name: Upload vsix as artifact
uses: actions/upload-artifact@v2
with:
name: terraform-${{ steps.ext-version.outputs.content }}
path: ${{ runner.temp }}/terraform-${{ steps.ext-version.outputs.content }}.vsix
- name: Check latest published version
run: |
export EXTENSION_ID=`cat package.json | jq -r '.publisher + "." + .name'`
npx -- vsce show --json $EXTENSION_ID | jq '.versions[0]'
- name: vsce publish
run: npx -- vsce publish --no-git-tag-version --packagePath=${{ runner.temp }}/terraform-${{ steps.ext-version.outputs.content }}.vsix
name: ${{ matrix.vsce_target }}
path: "*.vsix"

publish:
name: Publish All
runs-on: ubuntu-latest
needs: build
if: success() && startsWith( github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v2
- name: Publish Extension
run: npx vsce publish --no-git-tag-version --packagePath $(find . -iname *.vsix)
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin/
out/
node_modules/
*.vsix
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "connor4312.esbuild-problem-matchers"]
}
10 changes: 3 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
"name": "Launch Client",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"outFiles": ["${workspaceRoot}/out/**/*.js"],
"preLaunchTask": {
"type": "npm",
"script": "watch"
}
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: watch"
},
{
"name": "Run Extension Tests",
Expand Down
18 changes: 10 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"group": "build",
"problemMatcher": "$esbuild-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
"label": "npm: watch"
},
{
"type": "npm",
"script": "build",
"group": "build",
"problemMatcher": "$esbuild",
"label": "npm: build"
},
{
"label": "terraformInitAndWatch",
Expand Down
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.vscode-test
build/
lsp/
node_modules/
src/
**/__mocks__
out/*.test.*
Expand Down
112 changes: 94 additions & 18 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,108 @@
# Building
# Development

The extension makes use of the [VSCode Language Server](https://github.com/Microsoft/vscode-languageserver-node) client package to integrate with [terraform-ls](https://github.com/hashicorp/terraform-ls) for [language features](https://code.visualstudio.com/api/language-extensions/programmatic-language-features). The directions below cover how to build and package the extension; please see the `terraform-ls` documentation for how to build the language server executable.
We are an open source project on GitHub and would enjoy your contributions! Please [open a new issue](https://github.com/hashicorp/terraform-vscode-extension/issues) before working on a PR that requires significant effort. This will allow us to make sure the work is in line with the project's goals.

Requirements:
## Building

- Node
- npm
- VSCode
The extension makes use of the [VSCode Language Server](https://github.com/Microsoft/vscode-languageserver-node) client package to integrate with [terraform-ls](https://github.com/hashicorp/terraform-ls) for [language features](https://code.visualstudio.com/api/language-extensions/programmatic-language-features). The directions below cover how to build and package the extension; please see the [`terraform-ls`](https://github.com/hashicorp/terraform-ls) documentation for how to build the language server executable.

After cloning the repo, run `npm i` to install dependencies. There's an included build task to compile the TypeScript files to JavaScript; you can run it directly with `npm run compile`.
### Requirements

In order to use an independently built or installed version of `terraform-ls`, you will need to set `terraform.languageServer.pathToBinary` to the correct executable path.
- VSCode >= 1.61
- Node >= 16.13.2
- npm >= 8.x

The extension can be run in a development mode (useful for testing syntax highlighting changes, for example) via the debug task called `Launch Client`. This will open a new window with the extension loaded, and from there you can open any files or folders you want to check against. This extension development window can also be used to run commands, and use the language server installer.
### Getting the code

To package your local development copy for testing, use the [vsce](https://www.npmjs.com/package/vsce) tool with `vcse package`.
```
git clone https://github.com/hashicorp/vscode-terraform
```

# Development
### Dependencies

We are an open source project on GitHub and would enjoy your contributions! Please [open a new issue](https://github.com/hashicorp/terraform-vscode-extension/issues) before working on a PR that requires significant effort. This will allow us to make sure the work is in line with the project's goals.
After cloning the repo, run `npm install` to install dependencies. There's an included build task to compile the TypeScript files to JavaScript; you can run it directly with `npm run compile`.

```
> npm install
> npm run compile
```

> In order to use an independently built or installed version of terraform-ls, you will need to set `terraform.languageServer.pathToBinary` to the correct executable path.

## Running the Extension

The extension can be run in a development mode via the launch task called `Launch Client`. This will open a new VS Code window with the extension loaded, and from there you can open any files or folders you want to check against. This extension development window can also be used to run commands or any other feature the extension provides.

> New to VS Code development? You can get started [here](https://code.visualstudio.com/api/get-started/your-first-extension)

## Tests

Automated `unit` and `integration` tests can be written using [mocha](https://mochajs.org) and live inside `./src/test` with file pattern `*.test.ts`.

> It is *required* that `terraform` is available on `$PATH` to run the tests.

To run the `unit tests` from the command-line run:

```bash
> `npm test:unit`
```

To run the `integration tests` from the command-line without any configuration, run `npm test`. By default, `npm test` will test against VS Code Stable. If you want to test against a different VS Code version, or if you want to have VS Code remain open, use an environment variable to indicate which version of VS Code to test against:

```bash
# VS Code Stable is open, use Insiders:
> VSCODE_VERSION='insiders' npm test

# VS Code Insiders is open, use Stable:
> VSCODE_VERSION='stable' npm test

# Test against VS Code v1.55.8:
> VSCODE_VERSION='1.55.8' npm test
```

To run the `integration` tests in PowerShell, set the environment variable accordingly:

```powershell
# VS Code Stable is open, use Insiders:
> $env:VSCODE_VERSION ='insiders'
> npm test
```

The tests can also be run within VSCode itself, using the launch task `Run Extension Tests`. This will open a new VS Code window, run the test suite, and exit with the test results.

### Acceptance Tests

End to end acceptance tests with the extension running against the language server are a work in progress. An example can be seen in [`./src/test/integration/symbols.test.ts`](src/test/integration/symbols.test.ts).

Unfortunately automated user input does not appear to be possible (keypresses, cursor clicks) at the moment, but some integration testing can be performed by using the vscode API to open/edit files, and triggering events/commands such as language server requests and verifying the responses.

The `terraform init` command runs automatically when tests are executed.

### Test Fixture Data

Sample files for tests should be added to the [`./testFixture`](testFixture/) folder, this is the folder vscode will open during tests. Starting from this folder will prevent the language server from walking other folders that typically exist such as `node_modules`.

## Packaging

To package the extension into a [`platform specific extension`](https://code.visualstudio.com/api/working-with-extensions/publishing-extension#platformspecific-extensions) VSIX ready for testing run the following command:

# Testing
```
npm run package -- --target=win32-x64
```

Automated tests can be written using [mocha](https://mochajs.org) and live inside `./src` with file pattern `*.test.ts`. To run the tests from the command-line with `npm t` you will need to have closed any open VSCode windows. The tests can also be run within VSCode itself, using the debug task `Run Extension Tests`. It is required that `terraform` is available on `$PATH` for integration tests of the language server.
Replace `target` with the platform/architecture combination that is on the supported matrix list.

## Integration Tests
It is possible to write integration tests with the extension running against the language server. An example can be seen in [`./src/test/symbols.test.ts`](src/test/symbols.test.ts). Unfortunately automated user input does not appear to be possible (keypresses, cursor clicks), but some integration testing can be performed by using the vscode API to open/edit files, and triggering events/commands such as language server requests and verifying the responses.
platform | terraform-ls | extension | vs code
-- | -- | -- | --
macOS | darwin_amd64 | darwin_x64 | ✅
macOS | darwin_arm64 | darwin_arm64 | ✅
Linux | linux_amd64 | linux_x64 | ✅
Linux | linux_arm | linux_armhf | ✅
Linux | linux_arm64 | linux_arm64 | ✅
Windows | windows_386 | win32_ia32 | ✅
Windows | windows_amd64 | win32_x64 | ✅
Windows | windows_arm64 | win32_arm64 | ✅

Any of the [built in commands](https://code.visualstudio.com/api/references/commands) along with any custom commands the extension has defined can be triggered. Where needed, [expose items to the public API](https://github.com/hashicorp/vscode-terraform/blob/70bfcf060e3e2d75cfa67a453cd4c9e1cec9a1d4/src/extension.ts#L87) of the extension for [inspection](https://github.com/hashicorp/vscode-terraform/blob/70bfcf060e3e2d75cfa67a453cd4c9e1cec9a1d4/src/test/helper.ts#L33) during tests. Helpers, such as the `open` helper should be added to [`./src/test/helper.ts`](src/test/helper.ts).
This will run several chained commands which will download the specified version of terraform-ls, minify the extension using esbuild, and package the extension using vsce into a VSIX.

Sample files for tests should be added to the [`./testFixture`](testFixture/) folder, this is the folder vscode will open with during tests, the running of `terraform init` has been automated. Starting from this folder will prevent the language server from walking this projects other folders that typically exist such as `node_modules`, however `process.cwd()` is still be the project root.
> You can run `npm run package` without paramaters, but this will not produce a platform specific extension.
Loading