-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (169 loc) · 9.09 KB
/
run-publisher-with-env.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Run Publisher with Environment
on:
workflow_call:
inputs:
API_MANAGEMENT_ENVIRONMENT:
required: true
type: string
CONFIGURATION_YAML_PATH:
required: false
type: string
COMMIT_ID:
required: false
type: string
API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH:
required: true
type: string
env:
apiops_release_version: v4.1.0
jobs:
build:
runs-on: ubuntu-latest
environment: ${{ inputs.API_MANAGEMENT_ENVIRONMENT }}
steps:
# Run Spectral
- uses: actions/setup-node@v3
with:
node-version: "14"
- run: npm install -g @stoplight/spectral
- run: spectral lint "${{ GITHUB.WORKSPACE }}/${{ inputs.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}\apis\*.{json,yml,yaml}" --ruleset https://raw.githubusercontent.com/connectedcircuits/devops-api-linter/main/rules.yaml
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
with:
fetch-depth: 2
# Add this step for each APIM environment and pass specific set of secrets that you want replaced in the env section below
- name: "Perform namevalue secret substitution in configuration.${{ inputs.API_MANAGEMENT_ENVIRONMENT}}.yaml"
if: (inputs.API_MANAGEMENT_ENVIRONMENT == 'prod' )
uses: cschleiden/[email protected]
with:
tokenPrefix: "{#"
tokenSuffix: "#}"
files: ${{ format('["**/configuration.{0}.yaml"]', inputs.API_MANAGEMENT_ENVIRONMENT) }}
# specify environment specific secrets to be replaced. For example the QA environment could have a different set sercrets to
# replace within the configuration.[environment].yaml file
env:
testSecretValue: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
- name: Run publisher without Config Yaml but with Commit ID
if: ( inputs.CONFIGURATION_YAML_PATH == '' && inputs.COMMIT_ID != '')
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 }}/${{ inputs.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}
COMMIT_ID: ${{ inputs.COMMIT_ID }}
run: |
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"
$InformationPreference = "Continue"
Write-Information "Downloading publisher..."
$publisherFileName = "${{ runner.os }}" -like "*win*" ? "publisher.win-x64.exe" : "publisher.linux-x64.exe"
$uri = "https://github.com/Azure/apiops/releases/download/${{ env.apiops_release_version }}/$publisherFileName"
$destinationFilePath = Join-Path "${{ runner.temp }}" "publisher.exe"
Invoke-WebRequest -Uri "$uri" -OutFile "$destinationFilePath"
if ("${{ runner.os }}" -like "*linux*")
{
Write-Information "Setting file permissions..."
& chmod +x "$destinationFilePath"
if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."}
}
& "$destinationFilePath"
if ($LASTEXITCODE -ne 0) { throw "Running publisher failed."}
Write-Information "Execution complete."
shell: pwsh
- name: Run publisher without Config Yaml or Commit ID
if: ( inputs.CONFIGURATION_YAML_PATH == '' && inputs.COMMIT_ID == '')
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 }}/${{ inputs.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}
run: |
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"
$InformationPreference = "Continue"
Write-Information "Downloading publisher..."
$publisherFileName = "${{ runner.os }}" -like "*win*" ? "publisher.win-x64.exe" : "publisher.linux-x64.exe"
$uri = "https://github.com/Azure/apiops/releases/download/${{ env.apiops_release_version }}/$publisherFileName"
$destinationFilePath = Join-Path "${{ runner.temp }}" "publisher.exe"
Invoke-WebRequest -Uri "$uri" -OutFile "$destinationFilePath"
if ("${{ runner.os }}" -like "*linux*")
{
Write-Information "Setting file permissions..."
& chmod +x "$destinationFilePath"
if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."}
}
& "$destinationFilePath"
if ($LASTEXITCODE -ne 0) { throw "Running publisher failed."}
Write-Information "Execution complete."
shell: pwsh
- name: Run publisher with Config Yaml and Commit id
if: ( inputs.CONFIGURATION_YAML_PATH != '' && inputs.COMMIT_ID != '')
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 }}/${{ inputs.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}
CONFIGURATION_YAML_PATH: ${{ GITHUB.WORKSPACE }}/${{ inputs.CONFIGURATION_YAML_PATH }}
COMMIT_ID: ${{ inputs.COMMIT_ID }}
run: |
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"
$InformationPreference = "Continue"
Write-Information "Downloading publisher..."
$publisherFileName = "${{ runner.os }}" -like "*win*" ? "publisher.win-x64.exe" : "publisher.linux-x64.exe"
$uri = "https://github.com/Azure/apiops/releases/download/${{ env.apiops_release_version }}/$publisherFileName"
$destinationFilePath = Join-Path "${{ runner.temp }}" "publisher.exe"
Invoke-WebRequest -Uri "$uri" -OutFile "$destinationFilePath"
if ("${{ runner.os }}" -like "*linux*")
{
Write-Information "Setting file permissions..."
& chmod +x "$destinationFilePath"
if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."}
}
& "$destinationFilePath"
if ($LASTEXITCODE -ne 0) { throw "Running publisher failed."}
Write-Information "Execution complete."
shell: pwsh
- name: Run publisher with Config Yaml but without Commit id
if: ( inputs.CONFIGURATION_YAML_PATH != '' && inputs.COMMIT_ID == '')
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 }}/${{ inputs.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}
CONFIGURATION_YAML_PATH: ${{ GITHUB.WORKSPACE }}/${{ inputs.CONFIGURATION_YAML_PATH }}
run: |
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"
$InformationPreference = "Continue"
Write-Information "Downloading publisher..."
$publisherFileName = "${{ runner.os }}" -like "*win*" ? "publisher.win-x64.exe" : "publisher.linux-x64.exe"
$uri = "https://github.com/Azure/apiops/releases/download/${{ env.apiops_release_version }}/$publisherFileName"
$destinationFilePath = Join-Path "${{ runner.temp }}" "publisher.exe"
Invoke-WebRequest -Uri "$uri" -OutFile "$destinationFilePath"
if ("${{ runner.os }}" -like "*linux*")
{
Write-Information "Setting file permissions..."
& chmod +x "$destinationFilePath"
if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."}
}
& "$destinationFilePath"
if ($LASTEXITCODE -ne 0) { throw "Running publisher failed."}
Write-Information "Execution complete."
shell: pwsh