VS Code Extensionの公開を簡単にするCircleCI Orb作りました
VS Code Extensionの公開を簡単にするCircleCI Orb作りました
作りました: https://circleci.com/orbs/registry/orb/uraway/vsce
リポジトリ: https://github.com/uraway/vsce
使い方
環境変数としてVSCODE_MARKETPLACE_TOKENにPersonal Access Tokenをセットして、package.json
のバージョンフィールドを更新してコミットすればあとは自動的に公開されます。
push-git-tag
オプションをtrue
にしてフィンガープリントもつければ、タグリリースやってくれるのでかんぺき。キャッシュの処理はキャッシュキーがややこしくなりそうなので、post-install-steps
とpre-install-steps
でユーザー定義にしました。
orbs: vsce: uraway/vsce@0.0.3 version: 2.1 workflows: test-publish: jobs: - vsce/publish: filters: branches: only: master post-install-steps: - save_cache: key: v1-node-cache-{{ .Branch }}-{{ checksum "package-lock.json" }} paths: - node_modules pre-install-steps: - restore_cache: keys: - v1-node-cache-{{ .Branch }}-{{ checksum "package-lock.json"}} - v1-node-cache-{{ .Branch }} - v1-node-cache- push-git-tag: true ssh-fingerprints: <フィンガープリント>
Orb開発
orbs: orb-tools: circleci/orb-tools@9.0.0 your-orb: your-namespace/your-orb@<<pipeline.parameters.dev-orb-version>> parameters: dev-orb-version: default: 'dev:alpha' type: string run-integration-tests: default: false type: boolean jobs: integration-tests: executor: orb-tools/ubuntu steps: - checkout version: 2.1 workflows: integration-tests_prod-release: jobs: - integration-tests - orb-tools/dev-promote-prod-from-commit-subject: add-pr-comment: true bot-user: your-namespace fail-if-semver-not-indicated: true publish-version-tag: true ssh-fingerprints: <フィンガープリント> filters: branches: only: master orb-name: your-namespace/your-orb requires: - integration-tests when: << pipeline.parameters.run-integration-tests >> lint_pack-validate_publish-dev: jobs: - orb-tools/lint - orb-tools/pack: requires: - orb-tools/lint - orb-tools/publish-dev: orb-name: your-namespace/your-orb requires: - orb-tools/pack - orb-tools/trigger-integration-tests-workflow: name: trigger-integration-dev requires: - orb-tools/publish-dev unless: << pipeline.parameters.run-integration-tests >>
orb-toolsをフルに使う
https://circleci.com/orbs/registry/orb/circleci/orb-tools
orb-tools、これはもうOrb開発に必須。だいたいこれで良い。v9.0.0になってまた使いやすくなりました。orb-tools/lint
、orb-tools/pack
、orb-tools/publish-dev
はもちろん便利ですが、orb-tools/dev-promote-prod-from-commit-subject
ジョブがまた良い仕事してくれる。
- orb-tools/dev-promote-prod-from-commit-subject: add-pr-comment: true bot-user: your-namespace fail-if-semver-not-indicated: true publish-version-tag: true ssh-fingerprints: <フィンガープリント> filters: branches: only: master orb-name: your-namespace/your-orb
プルリクエストをマージするときに、下記図のようにコミットサブジェクトに[semver:patch|minor|major|skip]を入れるとsemverにそってプロモートしてくれます。
また、add-pr-comment: true
を渡して、環境変数PR_COMMENTER_GITHUB_TOKEN
としてbot-user
に対応するGitHubトークンをプロジェクトに追加すれば、そのプルリクエストに、Orb公開したよ、とコメントしてくれます。
さらに、publish-version-tag: true
を渡して、デプロイキーのフィンガープリントをセットすればタグコミットをプッシュしてくれます。さいこう
必要であればインテグレーションテスト
Orbによっては必要なこともあるインテグレーションテスト。vsce Orbでは、外部APIであるVS Code Marketplaceとの連携をテストしたいので、リポジトリ内にテスト用のVS Code Extension (vsce-orb-integration-test
)を持ち、そのExtensionの公開・非公開をワークフロー内で繰り返しています。API制限とかあるのかな?
https://github.com/uraway/vsce
workflows: integration-tests_prod-release: jobs: - vsce/publish: name: publish-vsce publish-token-variable: VSCODE_MARKETPLACE_TOKEN push-git-tag: false package-path: vsce-orb-integration-test pre-install-steps: - restore_cache: keys: - v1-node-cache-{{ .Branch }}-{{ checksum "vsce-orb-integration-test/package-lock.json" }} - v1-node-cache-{{ .Branch }} - v1-node-cache- post-install-steps: - save_cache: key: v1-node-cache-{{ .Branch }}-{{ checksum "vsce-orb-integration-test/package-lock.json" }} paths: - node_modules - vsce/unpublish: name: unpublish-vsce publish-token-variable: VSCODE_MARKETPLACE_TOKEN package-path: vsce-orb-integration-test requires: - publish-vsce