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

add devops task to repo #2623

Merged
merged 19 commits into from
Oct 17, 2023
3 changes: 2 additions & 1 deletion .github/workflows/cspell-misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:
- 'eng/**' # Not required
# Standalone projects that have their own cspell
- 'cli/**'
- 'ext/**'
- 'ext/vscode/**'
- 'ext/devcontainer/**'
- 'templates/**'

jobs:
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/devops-ext-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: azureDevOps-ext-ci

on:
pull_request:
paths:
- "ext/azuredevops/**"
- ".github/workflows/devops-ext-ci.yml"
branches: [main]

permissions:
actions: read
contents: read
id-token: write

jobs:
build-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18"
- name: Install dependencies
run: |
npm install -g npm
npm install
working-directory: ./ext/azuredevops/setupAzd

- name: Test
run: npm test
working-directory: ./ext/azuredevops/setupAzd
4 changes: 4 additions & 0 deletions .vscode/cspell-devops-ext.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vsix
tsbuildinfo
codepaths
azuretools
8 changes: 7 additions & 1 deletion .vscode/cspell.global.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,16 @@ dictionaryDefinitions:
path: ./cspell-schemas.txt
description: Custom Schema Dictionary
addWords: true
scope: workspace
scope: workspace
- name: devopsExtension
path: ./cspell-devops-ext.txt
description: Custom DevOps Extension Dictionary
addWords: true
scope: workspace
dictionaries:
- powershell
- go
- gitHubUserAliases
- noticeMd
- schemas
- devopsExtension
3 changes: 2 additions & 1 deletion .vscode/cspell.misc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import: cspell.global.yaml
ignorePaths:
# Project changes here should be kept in-sync workflow cspell-misc.yml
- cli # uses its own cspell config
- ext # uses its own cspell config
- ext/vscode # uses its own cspell config
- ext/devcontainer
- templates # uses its own cspell config

- eng # not required
Expand Down
4 changes: 2 additions & 2 deletions eng/pipelines/release-vscode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ trigger:
- main
paths:
include:
- ext/
- ext/vscode
- eng/pipelines/release-vscode.yml

pr:
paths:
include:
- ext/
- ext/vscode
- eng/pipelines/release-vscode.yml

variables:
Expand Down
1 change: 1 addition & 0 deletions ext/azuredevops/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.vsix
39 changes: 39 additions & 0 deletions ext/azuredevops/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Contributing guide

## Prerequisites

Learn about [Azure devops custom tasks](https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?view=azure-devops).

## Submitting A Change

We use a fork based workflow. Here are simple steps:

1. Fork `azure/azure-dev` on GitHub.
2. Create a branch named `<some-description>` (e.g. `fix-123` for a bug fix or `add-deploy-command`) in your forked Git
repository.
3. Push the branch to your fork on GitHub.
4. Open a pull request in GitHub.

Here is a more [in-depth guide to forks in GitHub](https://guides.github.com/activities/forking/).

As part of CI validation, we run a series of live tests which provision and deprovision Azure resources. For external
contributors, these tests will not run automatically, but someone on the team will be able to run them for your PR on your
behalf.

## Build

- From `setupAzd` folder:
- Run `npm install`
- Run `tsc`
- Run `tfx extension create --manifest-globs vss-extension.json` to create the extension.

## Testing

From `setupAzd` folder, run `npm test`

## Release

- Update `setupAzd/task.json` with the `version` number.
- Update `vss-extension.json` with the `version` to release.
- Run the `build` steps to produce the `vsix` release artifact.
- Follow [publish steps](https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?view=azure-devops#5-publish-your-extension) to update the Marketplace.
21 changes: 21 additions & 0 deletions ext/azuredevops/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
55 changes: 55 additions & 0 deletions ext/azuredevops/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Azure DevOps Task for installing the Azure Developer CLI (`azd`)

This Azure DevOps task allows you to provision resources and deploy your application on Azure with [Azure Developer CLI](https://github.com/azure/setup-azd) commands.

The task installs the Azure Developer CLI on a user-defined Azure Developer CLI version. If the user does not specify a version, latest CLI version is used. Read more about various Azure Developer CLI versions [here](https://github.com/Azure/azure-dev/releases).

- `version` – **Optional** Example: 1.0.1, Default: set to latest azd cli version.

## Sample pipeline install latest `azd` version

```yaml
trigger:
- main
- branch

pool:
vmImage: ubuntu-latest
# vmImage: windows-latest

steps:
- task: setup-azd@0
displayName: Install azd
```

## Sample pipeline install a specific `azd` version

Select a specific `azd` version [here](https://github.com/Azure/azure-dev/releases) and use it in `version`.

```yaml
trigger:
- main
- branch

pool:
vmImage: ubuntu-latest
# vmImage: windows-latest

steps:
- task: setup-azd@0
inputs:
version: '1.0.2'
displayName: Install azd
```

## Getting help for Azure Developer CLI issues

If you encounter an issue related to the Azure Developer CLI commands executed in your script, you can file an issue directly on the [Azure Developer CLI repository](https://github.com/Azure/azure-dev/issues/new/choose).

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
Binary file added ext/azuredevops/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions ext/azuredevops/setupAzd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
index.js
node_modules
.taskkey
index.js
vhvb1989 marked this conversation as resolved.
Show resolved Hide resolved
tests/*.js
38 changes: 38 additions & 0 deletions ext/azuredevops/setupAzd/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/tests"
],
"internalConsoleOptions": "openOnSessionStart",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/tests/_suite.js",
"outFiles": [
"${workspaceFolder}/**/*.js"
]
}
]
}
19 changes: 19 additions & 0 deletions ext/azuredevops/setupAzd/NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
NOTICES AND INFORMATION
Do Not Translate or Localize

This software incorporates material from third parties.
Microsoft makes certain open source code available at https://3rdpartysource.microsoft.com,
or you may send a check or money order for US $5.00, including the product name,
the open source component name, platform, and version number, to:

Source Code Compliance Team
Microsoft Corporation
One Microsoft Way
Redmond, WA 98052
USA

Notwithstanding any other terms, you may reverse engineer this software to the extent
required to debug changes to any libraries licensed under the GNU Lesser General Public License.

---------------------------------------------------------

109 changes: 109 additions & 0 deletions ext/azuredevops/setupAzd/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import * as task from 'azure-pipelines-task-lib/task';
import * as cp from 'child_process'
import path from 'path';
import * as fs from 'fs'
import download from 'download';
import decompress from 'decompress';

export async function runMain(): Promise<void> {
try {
task.setTaskVariable('hasRunMain', 'true');
const version = task.getInput('version') || 'latest'

console.log("using version: " + version)

// get architecture and os
const architecture = process.arch
const os = process.platform

// map for different platform and arch
const extensionMap = {
linux: '.tar.gz',
darwin: '.zip',
win32: '.zip'
}

const exeMap = {
linux: '',
darwin: '',
win32: '.exe'
}

const arm64Map = {
x64: 'amd64',
arm64: 'arm64-beta'
}

const platformMap = {
linux: 'linux',
darwin: 'darwin',
win32: 'windows'
}

// get install url
const installArray = installUrlForOS(
os,
architecture,
platformMap,
arm64Map,
extensionMap,
exeMap
)

const url = `https://azure-dev.azureedge.net/azd/standalone/release/${version}/${installArray[0]}`

console.log(`The Azure Developer CLI collects usage data and sends that usage data to Microsoft in order to help us improve your experience.
You can opt-out of telemetry by setting the AZURE_DEV_COLLECT_TELEMETRY environment variable to 'no' in the shell you use.

Read more about Azure Developer CLI telemetry: https://github.com/Azure/azure-dev#data-collection`)

console.log(`Installing azd from ${url}`)
const buffer = await download(url);
const extractedTo = path.join(task.cwd(), 'azd-install');
await decompress(buffer, extractedTo);

let binName
if (os !== 'win32') {
binName = 'azd';
} else {
binName = 'azd.exe';
}
const binPath = path.join(extractedTo, binName);

fs.symlinkSync(
path.join(extractedTo, installArray[1]),
binPath
)
task.prependPath(extractedTo)
console.log(`azd installed to ${extractedTo}`)

task.exec(binPath, 'version')
} catch (err: any) {
task.setResult(task.TaskResult.Failed, err.message);
}
}

function installUrlForOS(
os: string,
architecture: string,
platformMap: Record<string, string>,
archMap: Record<string, string>,
extensionMap: Record<string, string>,
exeMap: Record<string, string>
): [string, string] {
const platformPart = `${platformMap[os]}`
const archPart = `${archMap[architecture]}`

if (platformPart === `undefined` || archPart === `undefined`) {
throw new Error(
`Unsupported platform and architecture: ${architecture} ${os}`
)
}

const installUrl = `azd-${platformPart}-${archPart}${extensionMap[os]}`
const installUrlForRename = `azd-${platformPart}-${archPart}${exeMap[os]}`

return [installUrl, installUrlForRename]
}

runMain();
Loading