项目作者: felipecrs

项目描述 :
semantic-release plugin to package and publish VS Code extensions
高级语言: JavaScript
项目地址: git://github.com/felipecrs/semantic-release-vsce.git
创建时间: 2017-11-15T23:12:17Z
项目社区:https://github.com/felipecrs/semantic-release-vsce

开源协议:MIT License

下载


semantic-release-vsce

semantic-release plugin to package and publish VS Code extensions.

npm
downloads
ci
dependencies
peerDependencies
semantic-release

Step Description
verify Verify the package.json and the validity of the personal access tokens against Visual Studio Marketplace and/or Open VSX Registry when publish is enabled
prepare Generate the .vsix file using vsce (can be be controlled by the packageVsix config option
publish Publish the extension to Visual Studio Marketplace and/or Open VSX Registry (learn more here)

Install

  1. npm install --save-dev semantic-release-vsce

or

  1. yarn add --dev semantic-release-vsce

Usage

The plugin can be configured in the semantic-release configuration file:

  1. {
  2. "plugins": [
  3. "@semantic-release/commit-analyzer",
  4. "@semantic-release/release-notes-generator",
  5. [
  6. "semantic-release-vsce",
  7. {
  8. "packageVsix": true
  9. }
  10. ],
  11. [
  12. "@semantic-release/github",
  13. {
  14. "assets": [
  15. {
  16. "path": "*.vsix"
  17. }
  18. ]
  19. }
  20. ]
  21. ]
  22. }

Configuration

packageVsix

Whether to package or not the extension into a .vsix file, or where to place it. This controls if vsce package gets called or not, and what value will be used for vsce package --out.

Value Description
"auto" (default) behave as true in case publish is disabled or the OVSX_PAT environment variable is present
true package the extension .vsix, and place it at the current working directory
false disables packaging the extension .vsix entirely
a string package the extension .vsix and place it at the specified path

publish

Whether to publish or not the extension to Visual Studio Marketplace and/or to Open VSX Registry. This controls if vsce publish or ovsx publish gets called or not. Learn more here.

Value Description
true (default) publishes the extension to Visual Studio Marketplace and/or to Open VSX Registry
false disables publishing the extension to Visual Studio Marketplace and/or to Open VSX Registry

publishPackagePath

Which .vsix file (or files) to publish. This controls what value will be used for vsce publish --packagePath.

Value Description
"auto" (default) uses the .vsix packaged during the prepare step (if packaged), or behave as false otherwise
false do not use a .vsix file to publish, which causes vsce to package the extension as part of the publish process
a string publish the specified .vsix file(s). This can be a glob pattern, or a comma-separated list of files

packageRoot

The directory of the extension relative to the current working directory. Defaults to cwd.

Environment variables

The following environment variables are supported by this plugin:

Variable Description
OVSX_PAT Optional. The personal access token to push to Open VSX Registry
VSCE_PAT Optional. The personal access token to publish to Visual Studio Marketplace. Note: Cannot be set at the same time as VSCE_AZURE_CREDENTIAL.
VSCE_AZURE_CREDENTIAL Optional. When set to true or 1, vsce will use the --azure-credential flag to authenticate. Note: Cannot be set at the same time as VSCE_PAT.
VSCE_TARGET Optional. The target to use when packaging or publishing the extension (used as vsce package --target ${VSCE_TARGET}). When set to universal, behave as if VSCE_TARGET was not set (i.e. build the universal/generic vsix). See the platform-specific example

Configuring vsce

You can set vsce options in the package.json, like:

  1. {
  2. "vsce": {
  3. "baseImagesUrl": "https://my.custom/base/images/url",
  4. "dependencies": true,
  5. "yarn": false
  6. }
  7. }

For more information, check the vsce docs.

Publishing

This plugin can publish extensions to Visual Studio Marketplace and/or Open VSX Registry.

You can enable or disable publishing with the publish config option.

When publish is enabled (default), the plugin will publish to Visual Studio Marketplace if the VSCE_PAT environment variable is present, and/or to Open VSX Registry if the OVSX_PAT environment variable is present.

For example, you may want to disable publishing if you only want to publish the .vsix file as a GitHub release asset.

Publishing to Visual Studio Marketplace

Publishing extensions to Visual Studio Marketplace using this plugin is easy:

  1. Create your personal access token for Visual Studio Marketplace. Learn more here.

  2. Configure the VSCE_PAT environment variable in your CI with the token that you created.

  3. Enjoy! The plugin will automatically detect the environment variable and it will publish to Visual Studio Marketplace, no additional configuration is needed.

Publishing to Open VSX Registry

Publishing extensions to Open VSX Registry using this plugin is easy:

  1. Create your personal access token for Open VSX Registry. Learn more here.

  2. Configure the OVSX_PAT environment variable in your CI with the token that you created.

  3. Enjoy! The plugin will automatically detect the environment variable and it will publish to Open VSX Registry, no additional configuration is needed.

Examples

GitHub Actions

  1. name: release
  2. on:
  3. push:
  4. branches:
  5. - master
  6. permissions:
  7. contents: read # for checkout
  8. jobs:
  9. release:
  10. runs-on: ubuntu-latest
  11. permissions:
  12. contents: write # to be able to publish a GitHub release
  13. issues: write # to be able to comment on released issues
  14. pull-requests: write # to be able to comment on released pull requests
  15. steps:
  16. - uses: actions/checkout@v4
  17. - uses: actions/setup-node@v4
  18. with:
  19. node-version: 22
  20. - run: npm ci
  21. - run: npm audit signatures
  22. - run: npx semantic-release
  23. env:
  24. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  25. # In case you want to publish to Visual Studio Marketplace
  26. VSCE_PAT: ${{ secrets.VSCE_PAT }}
  27. # In case you want to publish to Open VSX Registry
  28. OVSX_PAT: ${{ secrets.OVSX_PAT }}

Platform-specific on GitHub Actions

  1. Install semantic-release-stop-before-publish

    1. npm install --save-dev semantic-release-stop-before-publish

    We will use it to make semantic-release stop before publishing anything, so that we can use semantic-release to build each .vsix in a matrix.

  2. Separate your semantic-release configuration into two, one for packaging and another for publishing.

    The one for packaging has semantic-release-stop-before-publish so that semantic-release does not publish anything (which includes the git tag).

    1. // package.release.config.js
    2. /**
    3. * @type {import('semantic-release').GlobalConfig}
    4. */
    5. export default {
    6. plugins: [
    7. '@semantic-release/commit-analyzer',
    8. '@semantic-release/release-notes-generator',
    9. [
    10. 'semantic-release-vsce',
    11. {
    12. packageVsix: true,
    13. publish: false,
    14. },
    15. ],
    16. 'semantic-release-stop-before-publish',
    17. ],
    18. };

    The one for publishing does not package the .vsix, but publishes all the *.vsix files.

    1. // publish.release.config.js
    2. /**
    3. * @type {import('semantic-release').GlobalConfig}
    4. */
    5. export default {
    6. plugins: [
    7. '@semantic-release/commit-analyzer',
    8. '@semantic-release/release-notes-generator',
    9. [
    10. 'semantic-release-vsce',
    11. {
    12. packageVsix: false,
    13. publishPackagePath: '*.vsix',
    14. },
    15. ],
    16. [
    17. '@semantic-release/github',
    18. {
    19. assets: '*.vsix',
    20. },
    21. ],
    22. ],
    23. };

    Note: do not forget to remove your existing semantic-release configuration.

  3. Create a workflow file like below:

  1. # .github/workflows/ci.yaml
  2. name: ci
  3. on:
  4. push:
  5. branches:
  6. - master
  7. permissions:
  8. contents: read # for checkout
  9. jobs:
  10. build:
  11. strategy:
  12. matrix:
  13. include:
  14. - os: windows-latest
  15. target: win32-x64
  16. npm_config_arch: x64
  17. - os: windows-latest
  18. target: win32-arm64
  19. npm_config_arch: arm64
  20. - os: ubuntu-latest
  21. target: linux-x64
  22. npm_config_arch: x64
  23. - os: ubuntu-latest
  24. target: linux-arm64
  25. npm_config_arch: arm64
  26. - os: ubuntu-latest
  27. target: linux-armhf
  28. npm_config_arch: arm
  29. - os: ubuntu-latest
  30. target: alpine-x64
  31. npm_config_arch: x64
  32. - os: ubuntu-latest
  33. target: alpine-arm64
  34. npm_config_arch: arm64
  35. - os: macos-latest
  36. target: darwin-x64
  37. npm_config_arch: x64
  38. - os: macos-latest
  39. target: darwin-arm64
  40. npm_config_arch: arm64
  41. - os: ubuntu-latest
  42. target: universal
  43. runs-on: ${{ matrix.os }}
  44. # Even though semantic-release will not publish anything, it still needs to
  45. # validate the GITHUB_TOKEN
  46. permissions:
  47. contents: write # to be able to publish a GitHub release
  48. issues: write # to be able to comment on released issues
  49. pull-requests: write # to be able to comment on released pull requests
  50. steps:
  51. - uses: actions/checkout@v4
  52. - uses: actions/setup-node@v4
  53. with:
  54. node-version: 22
  55. - if: matrix.target != 'universal'
  56. name: Install dependencies (with binaries)
  57. run: npm ci
  58. env:
  59. npm_config_arch: ${{ matrix.npm_config_arch }}
  60. - if: matrix.target == 'universal'
  61. name: Install dependencies (without binaries)
  62. run: npm ci
  63. - run: npx semantic-release --extends ./package.release.config.js
  64. env:
  65. VSCE_TARGET: ${{ matrix.target }}
  66. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  67. - uses: actions/upload-artifact@v4
  68. with:
  69. name: ${{ matrix.target }}
  70. path: '*.vsix'
  71. # vsce updates the version in package.json and package-lock.json during
  72. # package step, so we need to save them for the publish step
  73. - if: matrix.target == 'universal'
  74. uses: actions/upload-artifact@v4
  75. with:
  76. name: package-json
  77. path: |
  78. package.json
  79. package-lock.json
  80. release:
  81. runs-on: ubuntu-latest
  82. needs: build
  83. permissions:
  84. contents: write # to be able to publish a GitHub release
  85. issues: write # to be able to comment on released issues
  86. pull-requests: write # to be able to comment on released pull requests
  87. steps:
  88. - uses: actions/checkout@v4
  89. - uses: actions/download-artifact@v4
  90. with:
  91. merge-multiple: true
  92. - uses: actions/setup-node@v4
  93. with:
  94. node-version: 22
  95. - run: npm ci
  96. - run: npm audit signatures
  97. - run: npx semantic-release --extends ./publish.release.config.js
  98. env:
  99. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  100. # In case you want to publish to Visual Studio Marketplace
  101. VSCE_PAT: ${{ secrets.VSCE_PAT }}
  102. # In case you want to publish to Open VSX Registry
  103. OVSX_PAT: ${{ secrets.OVSX_PAT }}

GitHub Actions - Release to VS Marketplace with Azure credentials

  1. name: release
  2. on:
  3. push:
  4. branches:
  5. - master
  6. permissions:
  7. contents: read # for checkout
  8. jobs:
  9. release:
  10. runs-on: ubuntu-latest
  11. permissions:
  12. contents: write # to be able to publish a GitHub release
  13. issues: write # to be able to comment on released issues
  14. pull-requests: write # to be able to comment on released pull requests
  15. steps:
  16. - uses: actions/checkout@v4
  17. - uses: azure/login@v2
  18. with:
  19. client-id: ${{ secrets.AZURE_CLIENT_ID }}
  20. tenant-id: ${{ secrets.AZURE_TENANT_ID }}
  21. subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
  22. - uses: actions/setup-node@v4
  23. with:
  24. node-version: 22
  25. - run: npm ci
  26. - run: npm audit signatures
  27. - run: npx semantic-release
  28. env:
  29. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  30. VSCE_AZURE_CREDENTIAL: 'true'

A reference implementation can also be found in the VS Code ShellCheck extension.