Skip to content

Commit 13fc7dd

Browse files
authored
azd Developer Extension - pack, release & publish (#5118)
Adds new commands to the azd Developer Extension
1 parent 8b2ee0c commit 13fc7dd

File tree

16 files changed

+1663
-791
lines changed

16 files changed

+1663
-791
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Get the directory of the script
2+
$EXTENSION_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
3+
4+
# Change to the script directory
5+
Set-Location -Path $EXTENSION_DIR
6+
7+
# Create a safe version of EXTENSION_ID replacing dots with dashes
8+
$EXTENSION_ID_SAFE = $env:EXTENSION_ID -replace '\.', '-'
9+
10+
# Define output directory
11+
$OUTPUT_DIR = if ($env:OUTPUT_DIR) { $env:OUTPUT_DIR } else { Join-Path $EXTENSION_DIR "bin" }
12+
13+
# Create output directory if it doesn't exist
14+
if (-not (Test-Path -Path $OUTPUT_DIR)) {
15+
New-Item -ItemType Directory -Path $OUTPUT_DIR | Out-Null
16+
}
17+
18+
# Get Git commit hash and build date
19+
$COMMIT = git rev-parse HEAD
20+
$BUILD_DATE = (Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ")
21+
22+
# List of OS and architecture combinations
23+
if ($env:EXTENSION_PLATFORM) {
24+
$PLATFORMS = @($env:EXTENSION_PLATFORM)
25+
} else {
26+
$PLATFORMS = @(
27+
"windows/amd64",
28+
"windows/arm64",
29+
"darwin/amd64",
30+
"darwin/arm64",
31+
"linux/amd64",
32+
"linux/arm64"
33+
)
34+
}
35+
36+
$APP_PATH = "github.com/azure/azure-dev/cli/azd/extensions/$env:EXTENSION_ID/internal/cmd"
37+
38+
# Check if the build type is specified
39+
if (-not $env:EXTENSION_LANGUAGE) {
40+
Write-Host "Error: BUILD_TYPE environment variable is required (go or dotnet)"
41+
exit 1
42+
}
43+
44+
# Loop through platforms and build
45+
foreach ($PLATFORM in $PLATFORMS) {
46+
$OS, $ARCH = $PLATFORM -split '/'
47+
48+
$OUTPUT_NAME = Join-Path $OUTPUT_DIR "$EXTENSION_ID_SAFE-$OS-$ARCH"
49+
50+
if ($OS -eq "windows") {
51+
$OUTPUT_NAME += ".exe"
52+
}
53+
54+
Write-Host "Building for $OS/$ARCH..."
55+
56+
# Delete the output file if it already exists
57+
if (Test-Path -Path $OUTPUT_NAME) {
58+
Remove-Item -Path $OUTPUT_NAME -Force
59+
}
60+
61+
if ($env:EXTENSION_LANGUAGE -eq "dotnet") {
62+
# Set runtime identifier for .NET
63+
$RUNTIME = if ($OS -eq "windows") { "win-$ARCH" } elseif ($OS -eq "darwin") { "osx-$ARCH" } else { "linux-$ARCH" }
64+
$PROJECT_FILE = "$EXTENSION_ID_SAFE.csproj"
65+
66+
# Run dotnet publish for single file executable
67+
dotnet publish `
68+
-c Release `
69+
-r $RUNTIME `
70+
-o $OUTPUT_DIR `
71+
/p:PublishTrimmed=true `
72+
$PROJECT_FILE
73+
74+
if ($LASTEXITCODE -ne 0) {
75+
Write-Host "An error occurred while building for $OS/$ARCH"
76+
exit 1
77+
}
78+
79+
$EXPECTED_OUTPUT_NAME = $EXTENSION_ID_SAFE
80+
if ($OS -eq "windows") {
81+
$EXPECTED_OUTPUT_NAME += ".exe"
82+
}
83+
84+
Rename-Item -Path "$OUTPUT_DIR/$EXPECTED_OUTPUT_NAME" -NewName $OUTPUT_NAME
85+
} elseif ($env:EXTENSION_LANGUAGE -eq "go") {
86+
# Set environment variables for Go build
87+
$env:GOOS = $OS
88+
$env:GOARCH = $ARCH
89+
90+
go build `
91+
-ldflags="-X '$APP_PATH.Version=$env:EXTENSION_VERSION' -X '$APP_PATH.Commit=$COMMIT' -X '$APP_PATH.BuildDate=$BUILD_DATE'" `
92+
-o $OUTPUT_NAME
93+
94+
if ($LASTEXITCODE -ne 0) {
95+
Write-Host "An error occurred while building for $OS/$ARCH"
96+
exit 1
97+
}
98+
} else {
99+
Write-Host "Error: Unsupported BUILD_TYPE '$env:BUILD_TYPE'. Use 'go' or 'dotnet'."
100+
exit 1
101+
}
102+
}
103+
104+
Write-Host "Build completed successfully!"
105+
Write-Host "Binaries are located in the $OUTPUT_DIR directory."

cli/azd/extensions/microsoft.azd.demo/extension.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ displayName: Demo Extension
55
description: This extension provides examples of the AZD extension framework.
66
usage: azd demo <command> [options]
77
version: 0.2.0
8+
language: go
89
capabilities:
910
- custom-commands
1011
- lifecycle-events

cli/azd/extensions/microsoft.azd.extensions/extension.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ language: go
55
displayName: AZD Extensions Developer Kit
66
description: This extension provides a set of tools for AZD extension developers to test and debug their extensions.
77
usage: azd x <command> [options]
8-
version: 0.0.3
8+
version: 0.2.0
99
capabilities:
1010
- custom-commands
1111
examples:
@@ -15,9 +15,12 @@ examples:
1515
- name: build
1616
description: Build the AZD extension project.
1717
usage: azd x build
18-
- name: package
18+
- name: pack
1919
description: Package the AZD extension project into a distributable format and add to local registry.
20-
usage: azd x package
20+
usage: azd x pack
21+
- name: release
22+
description: Create an new release of the AZD extension project to a Github repository.
23+
usage: azd x release
2124
- name: watch
2225
description: Watch for changes in the extension project and automatically rebuild and reload the extension.
2326
usage: azd x watch

0 commit comments

Comments
 (0)