Skip to content

Commit 4cb9692

Browse files
Merge pull request #292386 from dlepow/ghapic
[APIC] GH Actions update
2 parents ee3f2e3 + a1bc03e commit 4cb9692

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

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

Lines changed: 13 additions & 17 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: azure-api-center
55
ms.topic: how-to
6-
ms.date: 07/24/2024
6+
ms.date: 12/23/2024
77
ms.author: danlep
88
author: dlepow
99
ms.custom: devx-track-azurecli
@@ -20,9 +20,9 @@ The following diagram shows how API registration in your API center can be autom
2020

2121
:::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":::
2222

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.
23+
1. Set up a GitHub Actions workflow in your repository that triggers when a pull request adding an API definition file is merged.
2424
1. Create a branch from the main branch in your GitHub repository.
25-
1. Add an API definition file, commit the changes, and push them to the new branch.
25+
1. Add an API definition file, commit the changes, and push to the new branch.
2626
1. Create a pull request to merge the new branch into the main branch.
2727
1. Merge the pull request.
2828
1. The merge triggers a GitHub Actions workflow that registers the API in your API center.
@@ -133,37 +133,32 @@ In this example:
133133
To configure the workflow file:
134134

135135
1. Copy and save the file under a name such as `register-api.yml`.
136-
1. Update the values for the environment variables to match your API center in Azure.
137136
1. Confirm or update the name of the repository folder (`APIs`) where you'll add the API definition file.
138137
1. Add this workflow file in the `/.github/workflows/` path in your GitHub repository.
138+
1. Set the [Actions variables](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables) `SERVICE_NAME` and `RESOURCE_GROUP` in your repo for your API center name and resource group name in Azure.
139139

140140
> [!TIP]
141-
> Using the [Visual Studio Code extension](build-register-apis-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.
141+
> Using the [Visual Studio Code extension](build-register-apis-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 or extend the file for your scenario.
142142

143143
```yml
144144
name: Register API Definition to Azure API Center
145145
on:
146146
pull_request:
147-
types: [closed]
147+
types: [ closed ]
148148
branches:
149-
- main
149+
- [ "main" ]
150150
paths:
151151
- "APIs/**/*.json"
152152
permissions:
153153
contents: read
154154
pull-requests: read
155-
env:
156-
# set this to your Azure API Center resource group name
157-
RESOURCE_GROUP: <YOUR_RESOURCE_GROUP>
158-
# set this to your Azure API Center service name
159-
SERVICE_NAME: <YOUR_API_CENTER>
160155
jobs:
161156
register:
162157
runs-on: ubuntu-latest
163158
environment: production
164159
steps:
165160
- uses: actions/checkout@v2
166-
161+
167162
- name: Get specification file path in the PR
168163
id: get-file-location
169164
uses: actions/github-script@v5
@@ -180,23 +175,24 @@ jobs:
180175
});
181176
if (files.data.length === 1) {
182177
const filename = files.data[0].filename;
183-
core.exportVariable('API_FILE_LOCATION', hfilename);
178+
core.exportVariable('API_FILE_LOCATION', filename);
184179
console.log(`API_FILE_LOCATION: ${{ env.API_FILE_LOCATION }}`);
185180
}
186181
else {
187182
console.log('The PR does not add exactly one specification file.');
188183
}
184+
189185
- name: Azure login
190186
uses: azure/login@v1
191187
with:
192188
creds: ${{ secrets.AZURE_CREDENTIALS }}
193-
189+
194190
- name: Register to API Center
195191
uses: azure/CLI@v2
196192
with:
197193
azcliversion: latest
198194
inlineScript: |
199-
az apic api register -g ${{ env.RESOURCE_GROUP }} -n ${{ env.SERVICE_NAME }} --api-location ${{ env.API_FILE_LOCATION }}
195+
az apic api register -g ${{ vars.RESOURCE_GROUP }} -n ${{ vars.SERVICE_NAME }} --api-location ${{ env.API_FILE_LOCATION }}
200196
```
201197
202198
@@ -258,7 +254,7 @@ You can extend the GitHub Actions workflow to include other steps, such as addin
258254
with:
259255
azcliversion: latest
260256
inlineScript: |
261-
az apic api update -g ${{ env.RESOURCE_GROUP }} -n ${{ env.SERVICE_NAME }} --api-id {{ env.API_ID }} --custom-properties {{ env.METADATA_FILE }}
257+
az apic api update -g ${{ vars.RESOURCE_GROUP }} -n ${{ vars.SERVICE_NAME }} --api-id {{ env.API_ID }} --custom-properties {{ env.METADATA_FILE }}
262258
```
263259

264260
## Related content

0 commit comments

Comments
 (0)