You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/api-center/register-apis-github-actions.md
+14-11Lines changed: 14 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,8 +18,7 @@ Using a GitHub Actions workflow to register APIs in your API center provides a c
18
18
19
19
The following diagram shows how API registration in your API center can be automated using a GitHub Actions workflow.
20
20
21
-
:::image type="content" source="media/register-apis-github-actions/scenario-overview.svg" alt-text="Diagram showing steps to trigger a GitHub actions workflow to register an API in an Azure API center.":::
22
-
21
+
:::image type="content" source="media/register-apis-github-actions/scenario-overview.svg" alt-text="Diagram showing steps to trigger a GitHub actions workflow to register an API in an Azure API center." lightbox="media/register-apis-github-actions/scenario-overview.svg":::
23
22
24
23
1. Set up a GitHub Actions workflow in your repository that triggers when a pull request that adds an API definition file is merged.
25
24
1. Create a branch from the main branch in your GitHub repository.
@@ -54,9 +53,11 @@ In this section, you set up the GitHub Actions workflow for this scenario:
54
53
In the following steps, create a Microsoft Entra ID service principal, which will be used in the workflow to authenticate with Azure.
55
54
56
55
> [!NOTE]
57
-
> 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?tabs=openid%2Caspnetcore#1-generate-deployment-credentials)
56
+
> 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)
57
+
58
+
Create a service principal using the [az ad sp create-for-rbac](/cli/azure/ad#az-ad-sp-create-for-rbac) command. The following example first uses the [az apic show](/cli/azure/apic#az-apic-show) command to retrieve the resource ID of the API center. The service principal is then created with the Contributor role for the API center.
58
59
59
-
Create a service principal using the [az ad sp create-for-rbac](/cli/azure/ad#az-ad-sp-create-for-rbac) command. The following example first uses the [az apic show](/cli/azure/az/apic#az-apic-show) command to retrieve the resource ID of the API center. The service principal is then created with the Contributor role for the API center.
az ad sp create-for-rbac --name $spName --role Contributor --scopes $apicResourceId --json-auth
81
84
```
82
-
85
+
---
83
86
84
87
Copy the JSON output, which should look similar to the following:
85
88
@@ -117,16 +120,16 @@ The following is a basic workflow file for this example that you can use or modi
117
120
118
121
In this example:
119
122
* the workflow is triggered when a pull request that adds a JSON definition in the `APIs` path is closed on the main branch
120
-
* The location of the definition is extracted from the pull request using a GitHub script, authenticated with the default GitHub token
123
+
* The location of the definition is extracted from the pull request using a GitHub script, which is authenticated with the default GitHub token
121
124
* The Azure credentials saved in your repo are used to sign into Azure
122
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
123
126
124
127
To configure the workflow file:
125
128
126
129
1. Copy and save the file under a name such as `register-api.yml`.
127
130
1. Update the values for the environment variables to match your API center in Azure.
128
-
1. Update the expected path where you'll add the definition file in the repository.
129
-
1. Add this file in the `/.github/workflows/` path in your GitHub repository.
131
+
1. Confirm or update the name of the repository folder (`APIs`) where you'll add the API definition file.
132
+
1. Add this workflow file in the `/.github/workflows/` path in your GitHub repository.
130
133
131
134
> [!TIP]
132
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.
@@ -219,7 +222,7 @@ Verify that the API is registered in your API center.
219
222
To add a new version to an existing API in your API center, follow the same steps as before, with a slight modification:
220
223
221
224
1. Change to the same working branch in your repo, or create a new working branch.
222
-
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 catfacts-api API definition, add a new version such as `APIs/catfacts-api/07-22-2024.json`.
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`.
223
226
1. Commit the changes and push them to the working branch.
224
227
1. Create a pull request to merge the working branch into the main branch.
225
228
1. After review, merge the pull request. The merge triggers the GitHub Actions workflow that registers the new API version in your API center.
@@ -244,8 +247,8 @@ You can extend the GitHub Actions workflow to include other steps, such as addin
244
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:
245
248
246
249
247
-
```azurecli
248
-
az apic api update -g ${{ env.RESOURCE_GROUP }} -n ${{ env.SERVICE_NAME }} --api-id {{ env.API_ID }} --metadata-file {{ env.METADATA_FILE }}
250
+
```azurecli
251
+
az apic api update -g ${{ env.RESOURCE_GROUP }} -n ${{ env.SERVICE_NAME }} --api-id {{ env.API_ID }} --metadata-file {{ env.METADATA_FILE }}
0 commit comments