Skip to content

Commit

Permalink
Restructure extension to better support multiple task versions (#1326)
Browse files Browse the repository at this point in the history
* Restructure extension task to better support multiple version

* Fix typos

* Fix build

* Fix build
  • Loading branch information
rhyskoedijk authored Sep 4, 2024
1 parent 84decec commit 03e65cc
Show file tree
Hide file tree
Showing 29 changed files with 36 additions and 29 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,25 @@ jobs:
working-directory: '${{ github.workspace }}/extension'

- name: Build
run: npm run build:prod
run: npm run build
working-directory: '${{ github.workspace }}/extension'

- name: Install tfx-cli
run: npm install -g [email protected]

- name: Replace tokens
- name: Update version numbers in vss-extension.json overrides files
uses: cschleiden/replace-tokens@v1
with:
files: '["${{ github.workspace }}/extension/overrides*.json"]'
env:
MAJOR_MINOR_PATCH: ${{ steps.gitversion.outputs.majorMinorPatch }}
BUILD_NUMBER: ${{ github.run_number }}

- name: Update values in extension/task/task.json
- name: Update version numbers in task.json
run: |
echo "`jq '.version.Major=${{ steps.gitversion.outputs.major }}' extension/task/task.json`" > extension/task/task.json
echo "`jq '.version.Minor=${{ steps.gitversion.outputs.minor }}' extension/task/task.json`" > extension/task/task.json
echo "`jq '.version.Patch=${{ github.run_number }}' extension/task/task.json`" > extension/task/task.json
echo "`jq '.version.Major=${{ steps.gitversion.outputs.major }}' extension/tasks/dependabot/dependabotV1/task.json`" > extension/tasks/dependabot/dependabotV1/task.json
echo "`jq '.version.Minor=${{ steps.gitversion.outputs.minor }}' extension/tasks/dependabot/dependabotV1/task.json`" > extension/tasks/dependabot/dependabotV1/task.json
echo "`jq '.version.Patch=${{ github.run_number }}' extension/tasks/dependabot/dependabotV1/task.json`" > extension/tasks/dependabot/dependabotV1/task.json
- name: Create Extension (dev)
run: >
Expand Down
12 changes: 9 additions & 3 deletions docs/extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@ npm install

```bash
cd extension
npm run build:prod
npm run build
```

To generate the Azure DevOps `.vsix` extension package for testing, you'll first need to [create a publisher account](https://learn.microsoft.com/en-us/azure/devops/extend/publish/overview?view=azure-devops#create-a-publisher) on the [Visual Studio Marketplace Publishing Portal](https://marketplace.visualstudio.com/manage/createpublisher?managePageRedirect=true). After this, override your publisher ID below and generate the extension with:

```bash
npx tfx-cli extension create --overrides-file overrides.local.json --override "{\"publisher\": \"your-publisher-id-here\"}" --json5
npm run package -- --overrides-file overrides.local.json --rev-version --publisher your-publisher-id-here
```

## Installing the extension

To test the extension in Azure DevOps, you'll first need to build the extension `.vsix` file (see above). After this, [publish your extension](https://learn.microsoft.com/en-us/azure/devops/extend/publish/overview?view=azure-devops#publish-your-extension), then [install your extension](https://learn.microsoft.com/en-us/azure/devops/extend/publish/overview?view=azure-devops#install-your-extension).

## Running the task locally

```bash
npm start
```

## Running the unit tests

```bash
cd extension
npm run test
npm test
```
2 changes: 1 addition & 1 deletion extension/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
.taskkey
task/**/*.js
**/*.js
*.vsix
3 changes: 1 addition & 2 deletions extension/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const config: Config.InitialOptions = {
// "^.+\\.test.tsx?$": "ts-jest",
// },
testEnvironment: 'node',
preset: 'ts-jest',
rootDir: './tests',
preset: 'ts-jest'
};

export default config;
2 changes: 1 addition & 1 deletion extension/overrides.local.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "dependabot-local",
"version": "0.1.0.6",
"version": "1.0.0.0",
"name": "Dependabot (Local)"
}
4 changes: 3 additions & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"description": "Dependabot Azure DevOps task",
"main": "''",
"scripts": {
"postdependencies": "cp -r node_modules tasks/dependabot/dependabotV1/node_modules",
"build": "tsc -p .",
"build:prod": "npm run build && cp -r node_modules task/node_modules",
"package": "npx tfx-cli extension create --json5",
"start": "node tasks/dependabot/dependabotV1/index.js",
"test": "jest"
},
"repository": {
Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as tl from 'azure-pipelines-task-lib/task';
import { ToolRunner } from 'azure-pipelines-task-lib/toolrunner';
import { IDependabotRegistry, IDependabotUpdate } from './IDependabotConfig';
import { IDependabotRegistry, IDependabotUpdate } from './utils/IDependabotConfig';
import getSharedVariables from './utils/getSharedVariables';
import { parseConfigFile } from './utils/parseConfigFile';
import { resolveAzureDevOpsIdentities } from './utils/resolveAzureDevOpsIdentities';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"demands": [],
"version": {
"Major": 1,
"Minor": 6,
"Minor": 0,
"Patch": 0
},
"instanceNameFormat": "Dependabot",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extractPlaceholder } from '../../task/utils/convertPlaceholder';
import { extractPlaceholder } from './convertPlaceholder';

describe('Parse property placeholder', () => {
it('Should return key with underscores', () => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import extractHostname from '../../task/utils/extractHostname';
import extractHostname from './extractHostname';

describe('Extract hostname', () => {
it('Should convert old *.visualstudio.com hostname to dev.azure.com', () => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import extractOrganization from '../../task/utils/extractOrganization';
import extractOrganization from './extractOrganization';

describe('Extract organization name', () => {
it('Should extract organization for on-premise domain', () => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import extractVirtualDirectory from '../../task/utils/extractVirtualDirectory';
import extractVirtualDirectory from './extractVirtualDirectory';

describe('Extract virtual directory', () => {
it('Should extract virtual directory', () => {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as fs from 'fs';
import { load } from 'js-yaml';
import { IDependabotRegistry, IDependabotUpdate } from '../../task/IDependabotConfig';
import { parseRegistries, parseUpdates, validateConfiguration } from '../../task/utils/parseConfigFile';
import { IDependabotRegistry, IDependabotUpdate } from './IDependabotConfig';
import { parseRegistries, parseUpdates, validateConfiguration } from './parseConfigFile';

describe('Parse configuration file', () => {
it('Parsing works as expected', () => {
let config: any = load(fs.readFileSync('tests/utils/dependabot.yml', 'utf-8'));
let config: any = load(fs.readFileSync('tests/config/dependabot.yml', 'utf-8'));
let updates = parseUpdates(config);
expect(updates.length).toBe(3);

Expand Down Expand Up @@ -36,7 +36,7 @@ describe('Parse configuration file', () => {

describe('Parse registries', () => {
it('Parsing works as expected', () => {
let config: any = load(fs.readFileSync('tests/utils/sample-registries.yml', 'utf-8'));
let config: any = load(fs.readFileSync('tests/config/sample-registries.yml', 'utf-8'));
let registries = parseRegistries(config);
expect(Object.keys(registries).length).toBe(11);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as fs from 'fs';
import { load } from 'js-yaml';
import * as path from 'path';
import { URL } from 'url';
import { IDependabotConfig, IDependabotRegistry, IDependabotUpdate } from '../IDependabotConfig';
import { IDependabotConfig, IDependabotRegistry, IDependabotUpdate } from './IDependabotConfig';
import { convertPlaceholder } from './convertPlaceholder';
import { ISharedVariables } from './getSharedVariables';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import { describe } from 'node:test';
import { isHostedAzureDevOps, resolveAzureDevOpsIdentities } from '../../task/utils/resolveAzureDevOpsIdentities';
import { isHostedAzureDevOps, resolveAzureDevOpsIdentities } from './resolveAzureDevOpsIdentities';

describe('isHostedAzureDevOps', () => {
it('Old visualstudio url is hosted.', () => {
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions extension/vss-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "dependabot",
"name": "Dependabot",
"version": "0.1.0",
"version": "1.0.0",
"publisher": "tingle-software",
"public": false,
"targets": [
Expand Down Expand Up @@ -31,7 +31,7 @@
},
"files": [
{
"path": "task"
"path": "tasks"
},
{
"path": "images",
Expand All @@ -44,7 +44,7 @@
"type": "ms.vss-distributed-task.task",
"targets": ["ms.vss-distributed-task.tasks"],
"properties": {
"name": "task"
"name": "tasks/dependabot"
}
}
]
Expand Down

0 comments on commit 03e65cc

Please sign in to comment.