Skip to content

Commit 5c9bec4

Browse files
committed
review feedback
1 parent a98370b commit 5c9bec4

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

articles/api-center/TOC.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
href: manage-apis-azure-cli.md
3939
- name: Import APIs from API Management
4040
href: import-api-management-apis.md
41-
- name: Build and register APIs - VS Code extension
41+
- name: Register APIs - VS Code extension
4242
href: use-vscode-extension.md
43-
- name: Register APIs using GitHub Actions
43+
- name: Register APIs - GitHub Actions
4444
href: register-apis-github-actions.md
4545
- name: API governance
4646
items:
140 KB
Loading
147 KB
Loading

articles/api-center/register-apis-github-actions.md

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Register APIs using GitHub Actions - Azure API Center
33
description: Learn how to automate the registration of APIs in your API center using a CI/CD workflow based on GitHub Actions.
44
ms.service: api-center
55
ms.topic: how-to
6-
ms.date: 07/22/2024
6+
ms.date: 07/24/2024
77
ms.author: danlep
88
author: dlepow
99
ms.custom: devx-track-azurecli
@@ -30,7 +30,7 @@ The following diagram shows how API registration in your API center can be autom
3030
## Prerequisites
3131

3232
* An API center in your Azure subscription. If you haven't created one already, see [Quickstart: Create your API center](set-up-api-center.md).
33-
* Permissions to create a service principal in the Microsoft Entra tenant
33+
* Permissions to create a service principal in the Microsoft Entra ID tenant
3434
* A GitHub account and a GitHub repo in which you can configure secrets and GitHub Actions workflows
3535
* For Azure CLI:
3636
[!INCLUDE [include](~/reusable-content/azure-cli/azure-cli-prepare-your-environment-no-header.md)]
@@ -44,13 +44,13 @@ The following diagram shows how API registration in your API center can be autom
4444

4545
In this section, you set up the GitHub Actions workflow for this scenario:
4646

47-
* Create an Azure service principal to use for configuring credentials for the workflow.
47+
* Create a service principal to use for Azure credentials in the workflow.
4848
* Add the credentials as a secret in your GitHub repository.
4949
* Configure a GitHub Actions workflow that triggers when a pull request that adds an API definition file is merged. The workflow YAML file includes a step that uses the Azure CLI to register the API in your API center from the definition file.
5050

5151
### Set up a service principal secret
5252

53-
In the following steps, create a Microsoft Entra ID service principal, which will be used in the workflow to authenticate with Azure.
53+
In the following steps, create a Microsoft Entra ID service principal, which will be used to add credentials to the workflow to authenticate with Azure.
5454

5555
> [!NOTE]
5656
> Configuring a service principal is shown for demonstration purposes. The recommended way to authenticate with Azure for GitHub Actions is with OpenID Connect, an authentication method that uses short-lived tokens. Setting up OpenID Connect with GitHub Actions is more complex but offers hardened security. [Learn more](../app-service/deploy-github-actions.md?tabs=openid%2Caspnetcore#1-generate-deployment-credentials)
@@ -100,9 +100,15 @@ Copy the JSON output, which should look similar to the following:
100100

101101
### Add the service principal as a GitHub secret
102102

103-
In [GitHub](https://github.com/), browse your repository. Select **Settings > Security > Secrets and variables > Actions > New repository secret**.
103+
1. In [GitHub](https://github.com/), browse your repository. Select **Settings**.
104+
1. Under **Security**, select **Secrets and variables** > **Actions**
105+
1. Select **New repository secret**.
106+
1. Paste the entire JSON output from the Azure CLI command into the secret's value field. Name the secret `AZURE_CREDENTIALS`. Select **Add secret**.
107+
108+
The secret is listed under **Repository secrets**.
109+
110+
:::image type="content" source="media/register-apis-github-actions/repository-secrets-github-small.png" alt-text="Screenshot of secrets for Actions in a GitHub repository." lightbox="media/register-apis-github-actions/repository-secrets-github.png":::
104111

105-
Paste the entire JSON output from the Azure CLI command into the secret's value field. Name the secret `AZURE_CREDENTIALS`.
106112

107113
When you configure the GitHub workflow file later, you use the secret for the input `creds` of the [Azure/login](https://github.com/marketplace/actions/azure-login) action. For example:
108114

@@ -119,10 +125,10 @@ A GitHub Actions workflow is represented by a YAML (.yml) definition file. This
119125
The following is a basic workflow file for this example that you can use or modify.
120126
121127
In this example:
122-
* the workflow is triggered when a pull request that adds a JSON definition in the `APIs` path is closed on the main branch
123-
* The location of the definition is extracted from the pull request using a GitHub script, which is authenticated with the default GitHub token
124-
* The Azure credentials saved in your repo are used to sign into Azure
125-
* The [az apic register](/cli/azure/apic/api#az-apic-api-register) command registers the API in the API center specified in the environment variables
128+
* The workflow is triggered when a pull request that adds a JSON definition in the `APIs` path is closed on the main branch.
129+
* The location of the definition is extracted from the pull request using a GitHub script, which is authenticated with the default GitHub token.
130+
* The Azure credentials saved in your repo are used to sign into Azure.
131+
* The [az apic register](/cli/azure/apic/api#az-apic-api-register) command registers the API in the API center specified in the environment variables.
126132

127133
To configure the workflow file:
128134

@@ -132,7 +138,7 @@ To configure the workflow file:
132138
1. Add this workflow file in the `/.github/workflows/` path in your GitHub repository.
133139

134140
> [!TIP]
135-
> If you use the [Visual Studio Code extension](use-vscode-extension.md) for Azure API Center, you can generate a starting workflow file using an extension command. In the Command Palette, select **Azure API Center: Register APIs**. Select **CI/CD** > **GitHub**. You can then modify the file for your scenario.
141+
> Using the [Visual Studio Code extension](use-vscode-extension.md) for Azure API Center, you can generate a starting workflow file by running an extension command. In the Command Palette, select **Azure API Center: Register APIs**. Select **CI/CD** > **GitHub**. You can then modify the file for your scenario.
136142

137143
```yml
138144
name: Register API Definition to Azure API Center
@@ -212,17 +218,16 @@ Verify that the API is registered in your API center.
212218

213219
1. In the [Azure portal](https://portal.azure.com), navigate to your API center.
214220
1. In the left menu, under **Assets**, select **APIs**.
215-
1. The newly registered API should appear in the list of APIs.
216-
221+
1. Verify that the newly registered API appears in the list of APIs.
217222

218223
:::image type="content" source="media/register-apis-github-actions/api-registered-api-center.png" alt-text="Screenshot of API registered in API Center after workflow.":::
219224

220225
## Add a new API version
221226

222-
To add a new version to an existing API in your API center, follow the same steps as before, with a slight modification:
227+
To add a new version to an existing API in your API center, follow the preceding steps, with a slight modification:
223228

224229
1. Change to the same working branch in your repo, or create a new working branch.
225-
1. Add a new API definition file to the repository in the `APIs` path, in the folder for an existing API. for example, if you previously added a Cat Facts API definition, add a new version such as `APIs/catfacts-api/07-22-2024.json`.
230+
1. Add a new API definition file to the repository in the `APIs` path, in the folder for an existing API. For example, if you previously added a Cat Facts API definition, add a new version such as `APIs/catfacts-api/07-22-2024.json`.
226231
1. Commit the changes and push them to the working branch.
227232
1. Create a pull request to merge the working branch into the main branch.
228233
1. After review, merge the pull request. The merge triggers the GitHub Actions workflow that registers the new API version in your API center.
@@ -232,7 +237,7 @@ To add a new version to an existing API in your API center, follow the same step
232237

233238
You can extend the GitHub Actions workflow to include other steps, such as adding metadata for the API registration. For example:
234239

235-
* Using the [metadata schema](metadata.md) in your API center, create a metadata JSON file to apply metadata values to your API registration.
240+
1. Using the [metadata schema](metadata.md) in your API center, create a metadata JSON file to apply metadata values to your API registration.
236241

237242
For example, if the metadata schema includes properties such as `approver`, `team`, and `cost center`, a metadata JSON file might look like this:
238243

@@ -243,15 +248,19 @@ You can extend the GitHub Actions workflow to include other steps, such as addin
243248
"costCenter": "12345"
244249
}
245250
```
246-
* Upload a metadata JSON file in the folder for each API in the repository.
247-
* Apply the metadata to the API registration using the [az apic api update](/cli/azure/apic/api#az-apic-api-update) command. In the following example, the API ID and metadata file are passed in environment variables:
251+
1. Upload a metadata JSON file in the folder for each API in the repository.
252+
1. Add a workflow step to apply the metadata to the API registration using the [az apic api update](/cli/azure/apic/api#az-apic-api-update) command. In the following example, the API ID and metadata file are passed in environment variables:
248253

249-
250-
```azurecli
251-
az apic api update -g ${{ env.RESOURCE_GROUP }} -n ${{ env.SERVICE_NAME }} --api-id {{ env.API_ID }} --custom-properties {{ env.METADATA_FILE }}
254+
```yml
255+
[...]
256+
- name: Apply metadata to API in API Center
257+
uses: azure/CLI@v2
258+
with:
259+
azcliversion: latest
260+
inlineScript: |
261+
az apic api update -g ${{ env.RESOURCE_GROUP }} -n ${{ env.SERVICE_NAME }} --api-id {{ env.API_ID }} --custom-properties {{ env.METADATA_FILE }}
252262
```
253263

254-
255264
## Related content
256265

257266
* [Using secrets in a GitHub Actions](https://docs.github.com/en/actions/reference/encrypted-secrets)

0 commit comments

Comments
 (0)