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
@@ -44,13 +44,13 @@ The following diagram shows how API registration in your API center can be autom
44
44
45
45
In this section, you set up the GitHub Actions workflow for this scenario:
46
46
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.
48
48
* Add the credentials as a secret in your GitHub repository.
49
49
* 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.
50
50
51
51
### Set up a service principal secret
52
52
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.
54
54
55
55
> [!NOTE]
56
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)
@@ -100,9 +100,15 @@ Copy the JSON output, which should look similar to the following:
100
100
101
101
### Add the service principal as a GitHub secret
102
102
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":::
104
111
105
-
Paste the entire JSON output from the Azure CLI command into the secret's value field. Name the secret `AZURE_CREDENTIALS`.
106
112
107
113
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:
108
114
@@ -119,10 +125,10 @@ A GitHub Actions workflow is represented by a YAML (.yml) definition file. This
119
125
The following is a basic workflow file for this example that you can use or modify.
120
126
121
127
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.
126
132
127
133
To configure the workflow file:
128
134
@@ -132,7 +138,7 @@ To configure the workflow file:
132
138
1. Add this workflow file in the `/.github/workflows/` path in your GitHub repository.
133
139
134
140
> [!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.
136
142
137
143
```yml
138
144
name: Register API Definition to Azure API Center
@@ -212,17 +218,16 @@ Verify that the API is registered in your API center.
212
218
213
219
1. In the [Azure portal](https://portal.azure.com), navigate to your API center.
214
220
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.
217
222
218
223
:::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.":::
219
224
220
225
## Add a new API version
221
226
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:
223
228
224
229
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`.
226
231
1. Commit the changes and push them to the working branch.
227
232
1. Create a pull request to merge the working branch into the main branch.
228
233
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
232
237
233
238
You can extend the GitHub Actions workflow to include other steps, such as adding metadata for the API registration. For example:
234
239
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.
236
241
237
242
For example, if the metadata schema includes properties such as `approver`, `team`, and `cost center`, a metadata JSON file might look like this:
238
243
@@ -243,15 +248,19 @@ You can extend the GitHub Actions workflow to include other steps, such as addin
243
248
"costCenter": "12345"
244
249
}
245
250
```
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:
248
253
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 }}
252
262
```
253
263
254
-
255
264
## Related content
256
265
257
266
* [Using secrets in a GitHub Actions](https://docs.github.com/en/actions/reference/encrypted-secrets)
0 commit comments