Skip to content

Commit

Permalink
feat: add doctl (#37)
Browse files Browse the repository at this point in the history
* chore(pipeline): upgrade node 14 to 16

* chore(packages): upgrade versions

* feat: add DigitalOceanDoctlInstaller

* chore: upgrade packages

* fix: add lint and webpack azure tool changes

* fix: use lerna to group packages

* fix: direct use dependencies that has an expression for webpack

* chore: add lerna clean before run tests

* chore: upgrade packages and default node to v16

* chore: upgrade test packages

* chore: upgrade aws & semantic release packages

* test: enable sourcemaps to pass tests

* chore: upgrade aws-sdk packages

* chore: migrate to husky 7

* chore: upgrade prettier & webpack

* chore: fix lint and loglevel

* fix(download): watch for progress on object instead of request

* fix(download): remove httpDownloadProgress and use httpHeader & data

* chore: upgrade aws-sdk

* fix(doctlInstaller): get tool path and download
- Add description
- Rework messages

* chore: upgrade jest

* feat: add doctl runner

* fix: lint import rules and semicolon

* fix(webpack): auto import entries, remove replace files

* chore: upgrade packages

* test: setup initial tests

* test: add remaining tests for doctl

* chore: remove tests from tsconfig

* test: mock process cwd

* chore: upgrade packages

* docs: add @marceloavf as a contributor

* chore: add all-contributors

* docs: add @usrme as a contributor

* docs: add @TrueBrain as a contributor

* docs: add tasks information

* docs: fix typo

BREAKING CHANGE: Many packages have been updated to major versions
  • Loading branch information
marceloavf committed Dec 13, 2021
1 parent 4629088 commit 3add6cf
Show file tree
Hide file tree
Showing 67 changed files with 8,168 additions and 4,602 deletions.
49 changes: 49 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"projectName": "digitalocean-tools-vsts",
"projectOwner": "marceloavf",
"repoType": "github",
"repoHost": "https://github.com",
"files": [
"README.md"
],
"imageSize": 100,
"commit": true,
"commitConvention": "angular",
"contributors": [
{
"login": "marceloavf",
"name": "Marcelo Formentão",
"avatar_url": "https://avatars.githubusercontent.com/u/5435657?v=4",
"profile": "https://www.linkedin.com/in/marceloavf/",
"contributions": [
"question",
"code",
"content",
"design",
"doc",
"ideas",
"infra"
]
},
{
"login": "usrme",
"name": "usrme",
"avatar_url": "https://avatars.githubusercontent.com/u/5902545?v=4",
"profile": "https://usrme.xyz/",
"contributions": [
"doc"
]
},
{
"login": "TrueBrain",
"name": "Patric Stout",
"avatar_url": "https://avatars.githubusercontent.com/u/1663690?v=4",
"profile": "https://github.com/TrueBrain",
"contributions": [
"code",
"doc"
]
}
],
"contributorsPerLine": 7
}
30 changes: 30 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"prettier"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:import/recommended",
"plugin:import/typescript"
],
"rules": {
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/ban-ts-comment": 1,
"semi": [2, "never"],
"import/order": ["error"]
},
"settings": {
"import/resolver": {
"typescript": {
"alwaysTryTypes": true,
"project": "tsconfig.json"
}
}
}
}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
16 changes: 10 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"editor.formatOnSave": true,
"jest.autoEnable": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.alwaysShowStatus": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
}
17 changes: 17 additions & 0 deletions Common/Node/Doctl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as tl from 'azure-pipelines-task-lib/task'

export class Doctl {
public accessToken: string
public arguments: string
public pathToRun: string

constructor() {
try {
this.accessToken = tl.getVariable('doctl.token')
this.arguments = tl.getInput('arguments')
this.pathToRun = tl.getPathInput("pathToRun") || process.cwd()
} catch (error) {
throw new Error(error.message)
}
}
}
2 changes: 1 addition & 1 deletion Common/Node/utils/filterFiles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path'
import AWS from 'aws-sdk'
import { isEmpty } from 'lodash'
import * as path from 'path'
import matcher from 'matcher'

interface FilterFilesOnList {
Expand Down
16 changes: 14 additions & 2 deletions Extension/OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ DigitalOcean Tools provide the ability to upload and delete objects from Digital

## Tasks included

- [**DigitalOcean Spaces Upload:**](https://github.com/marceloavf/digitalocean-tools-vsts/wiki/DigitalOcean-Spaces-Upload) Upload file(s) and folder(s) content to DigitalOcean Spaces Bucket.
- [**DigitalOcean Spaces Delete:**](https://github.com/marceloavf/digitalocean-tools-vsts/wiki/DigitalOcean-Spaces-Delete) Delete file(s) from DigitalOcean Spaces Bucket.
- [**DigitalOcean Spaces Upload:**](https://github.com/marceloavf/digitalocean-tools-vsts/blob/master/Extension/OVERVIEW.md#digitalocean-spaces-upload) Upload file(s) and folder(s) content to DigitalOcean Spaces Bucket.
- [**DigitalOcean Spaces Delete:**](https://github.com/marceloavf/digitalocean-tools-vsts/blob/master/Extension/OVERVIEW.md#digitalocean-spaces-delete) Delete file(s) from DigitalOcean Spaces Bucket.
- [**DigitalOcean Spaces Download:**](https://github.com/marceloavf/digitalocean-tools-vsts/blob/master/Extension/OVERVIEW.md#digitalocean-spaces-download) Download file(s) from DigitalOcean Spaces Bucket.
- [**DigitalOcean Doctl Installer:**](https://github.com/marceloavf/digitalocean-tools-vsts/blob/master/Extension/OVERVIEW.md#digitalocean-doctl-installer) Download and install Doctl.
- [**DigitalOcean Doctl:**](https://github.com/marceloavf/digitalocean-tools-vsts/blob/master/Extension/OVERVIEW.md#digitalocean-doctl) Runs Doctl command(s).

## DigitalOcean Spaces Upload

Expand Down Expand Up @@ -54,6 +57,15 @@ Advanced Options:
- **Concurrency limit:** Specify how many files to download simultaneously.
- **Retry failed limit:** Specify how many times to retry a failed download.

## DigitalOcean Doctl Installer

No inputs needed to be provided in this task, it will install the latest version avaiable of Doctl.

## DigitalOcean Doctl

- **Arguments:** Arguments passed to the doctl script. Either ordinal parameters or named parameters.
- **Working Directory:** The working folder that the cli will be run against. Root is assumed when empty.

## Install the extension to your account

You can find the latest stable version of the Azure DevOps Extension tasks on the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=marcelo-formentao.digitalocean-tools).
Expand Down
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ DigitalOcean Tools

<h4 align="center">

[![VS Marketplace Version](https://vsmarketplacebadge.apphb.com/version-short/marcelo-formentao.digitalocean-tools.svg?label=Production&color=0080ff)](https://marketplace.visualstudio.com/items?itemName=marcelo-formentao.digitalocean-tools) ![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/marceloavf/digitalocean-tools-vsts?include_prerelease&label=Development&color=blueviolet) [![VS Marketplace Installs](https://vsmarketplacebadge.apphb.com/installs/marcelo-formentao.digitalocean-tools.svg)](https://marketplace.visualstudio.com/items?itemName=marcelo-formentao.digitalocean-tools) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?color=success)](https://github.com/semantic-release/semantic-release) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com) [![Build Status](https://dev.azure.com/precisaosistemas/VSTSExtensions/_apis/build/status/marceloavf.digitalocean-tools-vsts?branchName=master)](https://dev.azure.com/precisaosistemas/VSTSExtensions/_build/latest?definitionId=264&branchName=master) [![codecov](https://codecov.io/gh/marceloavf/digitalocean-tools-vsts/branch/master/graph/badge.svg)](https://codecov.io/gh/marceloavf/digitalocean-tools-vsts) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=marceloavf_digitalocean-tools-vsts&metric=alert_status)](https://sonarcloud.io/dashboard?id=marceloavf_digitalocean-tools-vsts) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=marceloavf_digitalocean-tools-vsts&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=marceloavf_digitalocean-tools-vsts)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmarceloavf%2Fdigitalocean-tools-vsts.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmarceloavf%2Fdigitalocean-tools-vsts?ref=badge_shield)
[![VS Marketplace Version](https://vsmarketplacebadge.apphb.com/version-short/marcelo-formentao.digitalocean-tools.svg?label=Production&color=0080ff)](https://marketplace.visualstudio.com/items?itemName=marcelo-formentao.digitalocean-tools) ![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/marceloavf/digitalocean-tools-vsts?include_prerelease&label=Development&color=blueviolet) [![VS Marketplace Installs](https://vsmarketplacebadge.apphb.com/installs/marcelo-formentao.digitalocean-tools.svg)](https://marketplace.visualstudio.com/items?itemName=marcelo-formentao.digitalocean-tools) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?color=success)](https://github.com/semantic-release/semantic-release) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com) [![Build Status](https://dev.azure.com/precisaosistemas/VSTSExtensions/_apis/build/status/marceloavf.digitalocean-tools-vsts?branchName=master)](https://dev.azure.com/precisaosistemas/VSTSExtensions/_build/latest?definitionId=264&branchName=master) [![codecov](https://codecov.io/gh/marceloavf/digitalocean-tools-vsts/branch/master/graph/badge.svg)](https://codecov.io/gh/marceloavf/digitalocean-tools-vsts) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=marceloavf_digitalocean-tools-vsts&metric=alert_status)](https://sonarcloud.io/dashboard?id=marceloavf_digitalocean-tools-vsts) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=marceloavf_digitalocean-tools-vsts&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=marceloavf_digitalocean-tools-vsts)[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmarceloavf%2Fdigitalocean-tools-vsts.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmarceloavf%2Fdigitalocean-tools-vsts?ref=badge_shield)<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

</h4>

Expand All @@ -23,6 +24,8 @@ DigitalOcean Tools
- 🔹 &nbsp; [**DigitalOcean Spaces Upload:**](https://github.com/marceloavf/digitalocean-tools-vsts/blob/master/Extension/OVERVIEW.md#digitalocean-spaces-upload) Upload file(s) and folder(s) content to DigitalOcean Spaces Bucket.
- 🔹 &nbsp; [**DigitalOcean Spaces Delete:**](https://github.com/marceloavf/digitalocean-tools-vsts/blob/master/Extension/OVERVIEW.md#digitalocean-spaces-delete) Delete file(s) from DigitalOcean Spaces Bucket.
- 🔹 &nbsp; [**DigitalOcean Spaces Download:**](https://github.com/marceloavf/digitalocean-tools-vsts/blob/master/Extension/OVERVIEW.md#digitalocean-spaces-download) Download file(s) from DigitalOcean Spaces Bucket.
- 🔹 &nbsp; [**DigitalOcean Doctl Installer:**](https://github.com/marceloavf/digitalocean-tools-vsts/blob/master/Extension/OVERVIEW.md#digitalocean-doctl-installer) Download and install Doctl.
- 🔹 &nbsp; [**DigitalOcean Doctl:**](https://github.com/marceloavf/digitalocean-tools-vsts/blob/master/Extension/OVERVIEW.md#digitalocean-doctl) Runs Doctl command(s).

## 📟 &nbsp; Install the extension to your account

Expand All @@ -43,3 +46,25 @@ Please refer to our [wiki page](https://github.com/marceloavf/digitalocean-tools
## 📑 &nbsp; License

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmarceloavf%2Fdigitalocean-tools-vsts.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmarceloavf%2Fdigitalocean-tools-vsts?ref=badge_large)

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://www.linkedin.com/in/marceloavf/"><img src="https://avatars.githubusercontent.com/u/5435657?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Marcelo Formentão</b></sub></a><br /><a href="#question-marceloavf" title="Answering Questions">💬</a> <a href="https://github.com/marceloavf/digitalocean-tools-vsts/commits?author=marceloavf" title="Code">💻</a> <a href="#content-marceloavf" title="Content">🖋</a> <a href="#design-marceloavf" title="Design">🎨</a> <a href="https://github.com/marceloavf/digitalocean-tools-vsts/commits?author=marceloavf" title="Documentation">📖</a> <a href="#ideas-marceloavf" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-marceloavf" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
<td align="center"><a href="https://usrme.xyz/"><img src="https://avatars.githubusercontent.com/u/5902545?v=4?s=100" width="100px;" alt=""/><br /><sub><b>usrme</b></sub></a><br /><a href="https://github.com/marceloavf/digitalocean-tools-vsts/commits?author=usrme" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/TrueBrain"><img src="https://avatars.githubusercontent.com/u/1663690?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Patric Stout</b></sub></a><br /><a href="https://github.com/marceloavf/digitalocean-tools-vsts/commits?author=TrueBrain" title="Code">💻</a> <a href="https://github.com/marceloavf/digitalocean-tools-vsts/commits?author=TrueBrain" title="Documentation">📖</a></td>
</tr>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
10 changes: 10 additions & 0 deletions Tasks/DigitalOceanDoctl/digitalOceanDoctl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tl from './tl'
import { Runner } from './utils/Doctl'

const digitalOceanDoctl = new Runner()

export default () =>
digitalOceanDoctl
.init()
.then((result) => tl.setResult(tl.TaskResult.Succeeded, ''))
.catch((error) => tl.setResult(tl.TaskResult.Failed, error))
Binary file added Tasks/DigitalOceanDoctl/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions Tasks/DigitalOceanDoctl/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import init from './digitalOceanDoctl'

init()
10 changes: 10 additions & 0 deletions Tasks/DigitalOceanDoctl/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "DigitalOceanDoctl",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"azure-pipelines-task-lib": "3.1.10",
"azure-pipelines-tool-lib": "0.13.3"
}
}
53 changes: 53 additions & 0 deletions Tasks/DigitalOceanDoctl/task.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"id": "06f78d7e-c262-47fa-9422-3d4f2d50875e",
"name": "DigitalOceanDoctl",
"friendlyName": "DigitalOcean Doctl",
"instanceNameFormat": "DigitalOcean Doctl $(Arguments)",
"description": "Executes Doctl",
"author": "Marcelo Formentão",
"helpMarkDown": "[More Information](https://github.com/marceloavf/digitalocean-tools-vsts) (Version #{Version}#).",
"category": "Utility",
"visibility": [
"Build",
"Release"
],
"version": {
"Major": 0,
"Minor": 0,
"Patch": 0
},
"runsOn": [
"Agent",
"DeploymentGroup"
],
"demands": ["doctl"],
"minimumAgentVersion": "1.91.0",
"inputs": [
{
"name": "arguments",
"type": "string",
"label": "Arguments",
"defaultValue": "",
"required": false,
"helpMarkDown": "Arguments passed to the doctl script. Either ordinal parameters or named parameters."
},
{
"name": "pathToRun",
"type": "filePath",
"label": "Working Directory",
"required": false
}
],
"execution": {
"Node10": {
"target": "index.js",
"argumentFormat": ""
}
},
"messages": {
"NotFound": "Couldn't locate Doctl",
"ExecutionFailed": "Doctl failed with exit code %d",
"DoctlFailed": "Doctl failed with error %s",
"TaskCompleted": "All specified files deleted from Space completed"
}
}
10 changes: 10 additions & 0 deletions Tasks/DigitalOceanDoctl/tl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as path from 'path'
import * as tl from 'azure-pipelines-task-lib/task'

/**
* Set language loc file
*/
const taskManifestPath = path.join(__dirname, './task.json')
tl.setResourcePath(taskManifestPath)

export default tl
35 changes: 35 additions & 0 deletions Tasks/DigitalOceanDoctl/utils/Doctl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import trm = require('azure-pipelines-task-lib/toolrunner')
import { Doctl } from '@Common/Doctl'
import tl from '../tl'

export class Runner extends Doctl {
public async init(): Promise<void> {
try {
const doctlPath = tl.which('doctl', true)

const doctl = tl.tool(doctlPath)
if (this.accessToken) doctl.arg(`--access-token ${this.accessToken}`)
doctl.line(this.arguments)

const options: trm.IExecOptions = {
cwd: this.pathToRun,
env: process.env,
silent: false,
failOnStdErr: false,
ignoreReturnCode: false,
outStream: undefined,
errStream: undefined,
windowsVerbatimArguments: undefined
}

const result = await doctl.exec(options)
if (result) {
throw new Error(tl.loc('ExecutionFailed', result))
}
} catch (err) {
console.error(tl.loc('DoctlFailed'), err)
throw err
}
}

}

0 comments on commit 3add6cf

Please sign in to comment.