@@ -142,29 +142,28 @@ To configure the workflow file:
142
142
143
143
` ` ` yml
144
144
name: Register API Definition to Azure API Center
145
- 'on' :
145
+ on :
146
146
pull_request:
147
- types:
148
- - closed
147
+ types: [closed]
149
148
branches:
150
149
- main
151
150
paths:
152
- - APIs/**/*.json
151
+ - " APIs/**/*.json"
153
152
permissions:
154
153
contents: read
155
154
pull-requests: read
156
- env:
157
- TOKEN: '${{ secrets.GITHUB_TOKEN }}'
158
155
jobs:
159
156
register:
160
157
runs-on: ubuntu-latest
161
158
environment: production
162
159
steps:
163
160
- uses: actions/checkout@v2
161
+
164
162
- name: Get specification file path in the PR
165
163
id: get-file-location
166
164
uses: actions/github-script@v5
167
165
with:
166
+ github-token: ${{ secrets.GITHUB_TOKEN }}
168
167
script: |
169
168
const pull_number = context.payload.pull_request.number;
170
169
const owner = context.repo.owner;
@@ -176,37 +175,24 @@ jobs:
176
175
});
177
176
if (files.data.length === 1) {
178
177
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 {
197
182
console.log('The PR does not add exactly one specification file.');
198
183
}
184
+
199
185
- name : Azure login
200
186
uses : azure/login@v1
201
187
with :
202
- creds : ' ${{ secrets.AZURE_CREDENTIALS }}'
188
+ creds : ${{ secrets.AZURE_CREDENTIALS }}
189
+
203
190
- name : Register to API Center
204
191
uses : azure/CLI@v2
205
192
with :
206
193
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 }}
210
196
` ` `
211
197
212
198
@@ -268,7 +254,7 @@ You can extend the GitHub Actions workflow to include other steps, such as addin
268
254
with:
269
255
azcliversion: latest
270
256
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 }}
272
258
` ` `
273
259
274
260
# # Related content
0 commit comments