-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathrun-extractor.yaml
178 lines (155 loc) · 7.69 KB
/
run-extractor.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Run - Extractor
on:
workflow_dispatch:
inputs:
CONFIGURATION_YAML_PATH:
description: 'Choose Wether to extract all Apis or extract apis listed an extraction configuration file'
required: true
type: choice
options:
- Extract All APIs
- configuration.extractor.yaml
API_SPECIFICATION_FORMAT:
description: 'API Specification Format'
required: true
type: choice
options:
- OpenAPIV3Yaml
- OpenAPIV3Json
- OpenAPIV2Yaml
- OpenAPIV2Json
env:
apiops_release_version: desired-version-goes-here
jobs:
extract:
runs-on: ubuntu-latest
environment: dev # change this to match the dev environment created in settings
steps:
- uses: actions/checkout@v4
- name: Run extractor without Config Yaml
if: ${{ github.event.inputs.CONFIGURATION_YAML_PATH == 'Extract All APIs' }}
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_RESOURCE_GROUP_NAME: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
API_MANAGEMENT_SERVICE_NAME: ${{ secrets.API_MANAGEMENT_SERVICE_NAME }}
API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: ${{ GITHUB.WORKSPACE }}/apimartifacts # change this to the artifacts folder
API_SPECIFICATION_FORMAT: ${{ github.event.inputs.API_SPECIFICATION_FORMAT }}
run: |
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"
$InformationPreference = "Continue"
Write-Information "Setting name variables..."
$releaseFileName = "extractor-linux-x64.zip"
$executableFileName = "extractor"
if ("${{ runner.os }}" -like "*win*") {
$releaseFileName = "extractor-win-x64.zip"
$executableFileName = "extractor.exe"
}
elseif ("${{ runner.os }}" -like "*mac*" -and "${{ runner.arch }}" -like "*arm*") {
$releaseFileName = "extractor-osx-arm64.zip"
}
elseif ("${{ runner.os }}" -like "*mac*" -and "${{ runner.arch }}" -like "*x86_64*") {
$releaseFileName = "extractor-osx-x64.zip"
}
Write-Information "Downloading release..."
$uri = "https://github.com/Azure/apiops/releases/download/${{ env.apiops_release_version }}/$releaseFileName"
$downloadFilePath = Join-Path "${{ runner.temp }}" $releaseFileName
Invoke-WebRequest -Uri "$uri" -OutFile "$downloadFilePath"
Write-Information "Extracting release..."
$executableFolderPath = Join-Path "${{ runner.temp }}" "extractor"
Expand-Archive -Path "$downloadFilePath" -DestinationPath "$executableFolderPath"
$executableFilePath = Join-Path "$executableFolderPath" $executableFileName
Write-Information "Setting file permissions..."
if ("${{ runner.os }}" -like "*linux*")
{
& chmod +x "$executableFilePath"
if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."}
}
Write-Information "Running extractor..."
& "$executableFilePath"
if ($LASTEXITCODE -ne 0) { throw "Running extractor failed."}
Write-Information "Execution complete."
shell: pwsh
- name: Run extractor with Config Yaml
if: ${{ github.event.inputs.CONFIGURATION_YAML_PATH != 'Extract All APIs' }}
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_RESOURCE_GROUP_NAME: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
API_MANAGEMENT_SERVICE_NAME: ${{ secrets.API_MANAGEMENT_SERVICE_NAME }}
API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: ${{ GITHUB.WORKSPACE }}/apimartifacts # change this to the artifacts folder
API_SPECIFICATION_FORMAT: ${{ github.event.inputs.API_SPECIFICATION_FORMAT }}
CONFIGURATION_YAML_PATH: ${{ GITHUB.WORKSPACE }}/${{ github.event.inputs.CONFIGURATION_YAML_PATH }}
run: |
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"
$InformationPreference = "Continue"
Write-Information "Setting name variables..."
$releaseFileName = "extractor-linux-x64.zip"
$executableFileName = "extractor"
if ("${{ runner.os }}" -like "*win*") {
$releaseFileName = "extractor-win-x64.zip"
$executableFileName = "extractor.exe"
}
elseif ("${{ runner.os }}" -like "*mac*" -and "${{ runner.arch }}" -like "*arm*") {
$releaseFileName = "extractor-osx-arm64.zip"
}
elseif ("${{ runner.os }}" -like "*mac*" -and "${{ runner.arch }}" -like "*x86_64*") {
$releaseFileName = "extractor-osx-x64.zip"
}
Write-Information "Downloading release..."
$uri = "https://github.com/Azure/apiops/releases/download/${{ env.apiops_release_version }}/$releaseFileName"
$downloadFilePath = Join-Path "${{ runner.temp }}" $releaseFileName
Invoke-WebRequest -Uri "$uri" -OutFile "$downloadFilePath"
Write-Information "Extracting release..."
$executableFolderPath = Join-Path "${{ runner.temp }}" "extractor"
Expand-Archive -Path "$downloadFilePath" -DestinationPath "$executableFolderPath"
$executableFilePath = Join-Path "$executableFolderPath" $executableFileName
Write-Information "Setting file permissions..."
if ("${{ runner.os }}" -like "*linux*")
{
& chmod +x "$executableFilePath"
if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."}
}
Write-Information "Running extractor..."
& "$executableFilePath"
if ($LASTEXITCODE -ne 0) { throw "Running extractor failed."}
Write-Information "Execution complete."
shell: pwsh
- name: publish artifact
uses: actions/upload-artifact@v4
env:
API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: apimartifacts # change this to the artifacts folder
with:
name: artifacts-from-portal
path: ${{ GITHUB.WORKSPACE }}/${{ env.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}
create-pull-request:
needs: extract
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- name: Download artifacts-from-portal
uses: actions/download-artifact@v4
env:
API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: apimartifacts # change this to the artifacts folder
with:
name: artifacts-from-portal
path: "${{ GITHUB.WORKSPACE }}/${{ env.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}"
- name: Create artifacts pull request
uses: peter-evans/create-pull-request@v6
env:
API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: apimartifacts # change this to the artifacts folder
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "updated extract from apim instance ${{ env.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}"
title: "${{ env.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }} - extract"
body: >
This PR is auto-generated by Github actions workflow
labels: extract, automated pr