-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GHA workflow for API registration (#9)
- Loading branch information
Showing
4 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: Register API Definition to Azure API Center | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
resource-id: | ||
description: 'The resource ID of the API Center' | ||
required: false | ||
default: '' | ||
resource-group: | ||
description: 'The resource group name of the API Center' | ||
required: false | ||
default: '' | ||
api-center-service: | ||
description: 'The service name of the API Center' | ||
required: false | ||
default: '' | ||
file-location: | ||
description: 'The file path relative to the repository root' | ||
required: false | ||
default: '' | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
register-api: | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }} | ||
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }} | ||
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }} | ||
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }} | ||
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install APIC extension | ||
shell: bash | ||
run: | | ||
# az extension add --name apic-extension --allow-preview true --yes | ||
az extension add --source ./infra/scripts/apic_extension-1.0.0b4-py3-none-any.whl --allow-preview true --yes | ||
- name: Login to Azure | ||
uses: Azure/login@v2 | ||
with: | ||
client-id: ${{ env.AZURE_CLIENT_ID }} | ||
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }} | ||
tenant-id: ${{ env.AZURE_TENANT_ID }} | ||
|
||
- name: Register API | ||
shell: pwsh | ||
run: | | ||
./infra/scripts/New-ApiRegistration.ps1 ` | ||
-ResourceId "${{ github.event.inputs.resource-id }}" ` | ||
-ResourceGroup "${{ github.event.inputs.resource-group }}" ` | ||
-ApiCenterService "${{ github.event.inputs.api-center-service }}" ` | ||
-FileLocation "${{ github.event.inputs.file-location }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Registers API to API Center. | ||
Param( | ||
[string] | ||
[Parameter(Mandatory=$false)] | ||
$ResourceId = "", | ||
|
||
[string] | ||
[Parameter(Mandatory=$false)] | ||
$ResourceGroup = "", | ||
|
||
[string] | ||
[Parameter(Mandatory=$false)] | ||
$ApiCenterService = "", | ||
|
||
[string] | ||
[Parameter(Mandatory=$false)] | ||
$FileLocation = "", | ||
|
||
[string] | ||
[Parameter(Mandatory=$false)] | ||
$ApiVersion = "2024-03-01", | ||
|
||
[switch] | ||
[Parameter(Mandatory=$false)] | ||
$Help | ||
) | ||
|
||
function Show-Usage { | ||
Write-Output " This registers API to API Center | ||
Usage: $(Split-Path $MyInvocation.ScriptName -Leaf) `` | ||
[-ResourceId <Resource ID>] `` | ||
[-ResourceGroup <Resource group>] `` | ||
[-ApiCenterService <API Center instance name>] `` | ||
[-FileLocation <File location to register>] `` | ||
[-ApiVersion <API version>] `` | ||
[-Help] | ||
Options: | ||
-ResourceId Resource ID. It must be provided unless `ResourceGroup` is provided. | ||
-ResourceGroup Resource group. It must be provided unless `ResourceId` is provided. | ||
-ApiCenterService API Center instance name. It must be provided unless `ResourceId` is provided. | ||
-FileLocation File location to register. | ||
-ApiVersion REST API version. Default is `2024-03-01`. | ||
-Help: Show this message. | ||
" | ||
|
||
Exit 0 | ||
} | ||
|
||
# Show usage | ||
$needHelp = $Help -eq $true | ||
if ($needHelp -eq $true) { | ||
Show-Usage | ||
Exit 0 | ||
} | ||
|
||
if (($ResourceId -eq "") -and ($ResourceGroup -eq "" -or $ApiCenterService)) { | ||
Write-Output "`ResourceId` must be provided, or both `ResourceGroup` and `ApiCenterService` must be provided" | ||
Exit 0 | ||
} | ||
if ($FileLocation -eq "") { | ||
Write-Output "`FileLocation` must be provided" | ||
Exit 0 | ||
} | ||
|
||
$segments = $ResourceId.Split("/", [System.StringSplitOptions]::RemoveEmptyEntries) | ||
if ($ResourceGroup -eq "") { | ||
$ResourceGroup = $segments[3] | ||
} | ||
if ($ApiCenterService -eq "") { | ||
$ApiCenterService = $segments[7] | ||
} | ||
|
||
$REPOSITORY_ROOT = git rev-parse --show-toplevel | ||
|
||
$registered = az apic api register ` | ||
-g $ResourceGroup ` | ||
-s $ApiCenterService ` | ||
--api-location "$REPOSITORY_ROOT/$FileLocation" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.