Skip to content

Commit d97d630

Browse files
author
gitName
committed
use vars
1 parent ac61c39 commit d97d630

File tree

1 file changed

+15
-29
lines changed

1 file changed

+15
-29
lines changed

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

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -142,29 +142,28 @@ To configure the workflow file:
142142

143143
```yml
144144
name: Register API Definition to Azure API Center
145-
'on':
145+
on:
146146
pull_request:
147-
types:
148-
- closed
147+
types: [closed]
149148
branches:
150149
- main
151150
paths:
152-
- APIs/**/*.json
151+
- "APIs/**/*.json"
153152
permissions:
154153
contents: read
155154
pull-requests: read
156-
env:
157-
TOKEN: '${{ secrets.GITHUB_TOKEN }}'
158155
jobs:
159156
register:
160157
runs-on: ubuntu-latest
161158
environment: production
162159
steps:
163160
- uses: actions/checkout@v2
161+
164162
- name: Get specification file path in the PR
165163
id: get-file-location
166164
uses: actions/github-script@v5
167165
with:
166+
github-token: ${{ secrets.GITHUB_TOKEN }}
168167
script: |
169168
const pull_number = context.payload.pull_request.number;
170169
const owner = context.repo.owner;
@@ -176,37 +175,24 @@ jobs:
176175
});
177176
if (files.data.length === 1) {
178177
const filename = files.data[0].filename;
179-
const variableName = 'API_FILE_LOCATION';
180-
const variableValue = filename;
181-
182-
# Set the repository-level variable using the GitHub API
183-
# const octokit = github.getOctokit(core.getInput('GITHUB_TOKEN'));
184-
import { Octokit } from "octokit";
185-
const octokit = new Octokit({
186-
auth: process.env.TOKEN,
187-
});
188-
await octokit.request('PUT /repos/{owner}/{repo}/actions/variables/{name}', {
189-
owner: owner,
190-
repo: repo,
191-
name: variableName,
192-
value: variableValue
193-
});
194-
195-
console.log(`Set repository variable ${variableName} to ${variableValue}`);
196-
} else {
178+
core.exportVariable('API_FILE_LOCATION', filename);
179+
console.log(`API_FILE_LOCATION: ${{ env.API_FILE_LOCATION }}`);
180+
}
181+
else {
197182
console.log('The PR does not add exactly one specification file.');
198183
}
184+
199185
- name: Azure login
200186
uses: azure/login@v1
201187
with:
202-
creds: '${{ secrets.AZURE_CREDENTIALS }}'
188+
creds: ${{ secrets.AZURE_CREDENTIALS }}
189+
203190
- name: Register to API Center
204191
uses: azure/CLI@v2
205192
with:
206193
azcliversion: latest
207-
inlineScript: >
208-
az apic api register -g ${{ vars.RESOURCE_GROUP }} -n ${{
209-
vars.SERVICE_NAME }} --api-location ${{ vars.API_FILE_LOCATION }}
194+
inlineScript: |
195+
az apic api register -g ${{ vars.RESOURCE_GROUP }} -n ${{ vars.SERVICE_NAME }} --api-location ${{ env.API_FILE_LOCATION }}
210196
```
211197
212198
@@ -268,7 +254,7 @@ You can extend the GitHub Actions workflow to include other steps, such as addin
268254
with:
269255
azcliversion: latest
270256
inlineScript: |
271-
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 }}
272258
```
273259

274260
## Related content

0 commit comments

Comments
 (0)