-
Notifications
You must be signed in to change notification settings - Fork 10
/
action.yml
259 lines (227 loc) · 11.2 KB
/
action.yml
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
name: "Skyline DataMiner Deploy Action"
description: "The action builds an artifact from your solution and deploys it to your cloud connected DataMiner System."
branding:
icon: "download-cloud"
color: "gray-dark"
inputs:
api-key: # id of input
description: "The API-key generated in the DCP Admin app as authentication for a certain DataMiner System, saved in a GitHub secret"
required: true
github-token:
description: "The secrets.GITHUB_TOKEN. Required for stages: All and Upload."
required: false
solution-path:
description: "The path to the .sln file of the solution. Atm only DataMiner Automation Script solutions are supported. E.g ./Example/AutomationScript.sln. Required for stages: All and Upload."
required: false
artifact-name:
description: "The chosen name of the artifact. E.g. MyPackageName. Required for stages: All and Upload."
required: false
version:
description: "The version number for the artifact. Only required for a release run. Format A.B.C for a stable release or A.B.C-text for a pre-release. Required for stages Upload and All if no build number was provided instead."
required: false
timeout:
description: "[DEPRECATED] The maximum time spent on waiting for the deployment to finish in seconds. E.g. 900."
required: false
default: "900"
stage:
description: "The specific stage to run in this action. Possible values are: All, Upload, and Deploy. All will run all 3 stages consecutively."
required: false
default: "All"
artifact-id:
description: "The artifact Id of the artifact that you would like to deploy"
required: false
build-number:
description: "The build number of a workflow run. Only required for a development run. Required for stages Upload and All if no version was provided instead."
required: false
debug:
description: "[DEPRECATED] Option to enable debug logging. Optional."
required: false
outputs:
artifact-id:
description: "The artifact ID if the artifact has been uploaded"
value: ${{ steps.setArtifactId.outputs.artifact-id }}
runs:
using: "composite"
steps:
- name: Validate Mandatory Inputs
run: |
if [[ -z "${{ inputs.api-key }}" ]]; then
echo "Error: 'api-key' is required but was not provided."
exit 1
fi
if [[ -n "${{ inputs.stage }}" ]]; then
if [[ "${{ inputs.stage }}" != "All" && "${{ inputs.stage }}" != "Upload" && "${{ inputs.stage }}" != "Deploy" ]]; then
echo "Error: 'stage' must be one of 'All', 'Upload', or 'Deploy'."
exit 1
fi
fi
echo "All required inputs are provided."
shell: bash
- name: Validate Mandatory Inputs for Upload/All stage
if: ${{ inputs.stage == 'Upload' || inputs.stage == 'All' }}
run: |
if [[ -z "${{ inputs.github-token }}" ]]; then
echo "Error: 'github-token' is required but was not provided. This is usually secrets.GITHUB_TOKEN."
exit 1
fi
if [[ -z "${{ inputs.version }}" && -z "${{ inputs.build-number }}" ]]; then
echo "Error: 'version' & 'build-number' are both empty."
exit 1
fi
if [[ -z "${{ inputs.artifact-name }}" ]]; then
echo "Error: 'artifact-name' is required but was not provided."
exit 1
fi
echo "All required inputs for the Upload/All stages are provided."
shell: bash
- name: Validate Mandatory Inputs for Deploy stage
if: ${{ inputs.stage == 'Deploy' }}
run: |
if [[ -z "${{ inputs.artifact-id }}" ]]; then
echo "Error: 'artifact-id' is required but was not provided."
exit 1
fi
echo "All required inputs for the Deploy stage are provided."
shell: bash
- name: Validate auto-generated catalog YAML file existence
if: ${{ github.ref_type == 'tag' }}
shell: pwsh
run: |
if (!(Test-Path "${{ github.workspace }}/.githubtocatalog/auto-generated-catalog.yml")) {
Write-Host "Error: The auto-generated catalog YAML file was not found."
Write-Host "Run the workflow on a branch before releasing, and ensure the tag points to the latest commit containing the auto-generated-catalog.yml file."
exit 1
}
- name: Install .NET Tools
run: |
dotnet tool install -g Skyline.DataMiner.CICD.Tools.Packager --version 2.0.*
dotnet tool install -g Skyline.DataMiner.CICD.Tools.CatalogUpload --version 3.0.*
dotnet tool install -g Skyline.DataMiner.CICD.Tools.DataMinerDeploy --version 2.0.*
shell: bash
- name: Find branch
id: findBranch
if: ${{ (inputs.stage == 'Upload' || inputs.stage == 'All') && github.ref_type == 'tag' }}
run: |
# Capture the branches containing the tag and process them
branches="$(git branch --contains tags/${{ github.ref_name }} -r | grep 'origin/')"
# If more than 1 branch is found, filter out the ones that have multiple slashes.
# This is to filter out the developement branches as generally the tags are done on the main branches (e.g. 1.0.0.X)
if [ $(echo "$branches" | wc -l) -gt 1 ]; then
branches="$(echo "$branches" | grep -vE '.*/.*/')"
fi
branches="$(echo "$branches" | sed 's#origin/##' | paste -sd ',')"
# Append to GitHub Actions output
echo "branch=${branches}" >> $GITHUB_OUTPUT
shell: bash
- name: Clean package name
id: packageName
run: |
tempName="${{ inputs.artifact-name }}"
echo name=${tempName//[\"\/\\<>|:*?]/_} >> $GITHUB_OUTPUT
shell: bash
- name: Get folder of the solution path or use default workspace
id: solutionFolder
run: |
if [[ -n "${{ inputs.solution-path }}" ]]; then
folderPath=$(realpath "$(dirname "${{ inputs.solution-path }}")")
else
folderPath="${{ github.workspace }}"
fi
echo path=${folderPath} >> $GITHUB_OUTPUT
shell: bash
# Use version input when filled in
- name: Create dmapp package
if: ${{ (inputs.stage == 'Upload' || inputs.stage == 'All') && inputs.version != '' }}
run: dataminer-package-create dmapp "${{ steps.solutionFolder.outputs.path }}" --type automation --version ${{ inputs.version }} --output "${{ steps.solutionFolder.outputs.path }}" --name "${{ steps.packageName.outputs.name }}"
shell: bash
# Use build number when version is not filled in
- name: Create dmapp package
if: ${{ (inputs.stage == 'Upload' || inputs.stage == 'All') && inputs.version == '' }}
run: dataminer-package-create dmapp "${{ steps.solutionFolder.outputs.path }}" --type automation --build-number ${{ inputs.build-number }} --output "${{ steps.solutionFolder.outputs.path }}" --name "${{ steps.packageName.outputs.name }}"
shell: bash
# Always try to auto-generate a catalog.yml
- name: Auto-Generating Catalog from GitHub
id: autoGenerateCatalogFromGithubTag
if: ${{ (inputs.stage == 'Upload' || inputs.stage == 'All') }}
run: |
dotnet tool install -g Skyline.DataMiner.CICD.Tools.GitHubToCatalogYaml --version 1.0.*
github-to-catalog-yaml --workspace "${{ github.workspace }}" --github-token "${{ inputs.github-token }}" --github-repository "${{ github.repository }}"
shell: bash
- name: Check if catalog.yml or manifest.yml exists
id: check_files
shell: pwsh
run: |
if (Test-Path "${{ github.workspace }}/catalog.yml") {
echo "catalogDetails=catalog.yml" >> $env:GITHUB_ENV
}
elseif (Test-Path "${{ github.workspace }}/manifest.yml") {
echo "catalogDetails=manifest.yml" >> $env:GITHUB_ENV
}
else {
Write-Host "No valid file found!"
exit 1
}
- name: Sanitize Artifact Name
id: sanitize-artifact-name
if: env.catalogDetails != ''
shell: bash
run: |
# Set the sanitized artifact name by replacing invalid characters
CLEANED_NAME=$(echo "${{ inputs.artifact-name }}" | sed 's/[":<>|*?\\\/\r\n]//g')
echo "SANITIZED_NAME=$CLEANED_NAME" >> $GITHUB_ENV
- uses: actions/upload-artifact@v4
if: env.catalogDetails != ''
with:
name: Catalog Details ${{ env.SANITIZED_NAME }}
path: "${{ github.workspace }}/${{ env.catalogDetails }}"
# Only try to commit for non-tag
- name: Commit .githubtocatalog/auto-generated-catalog
if: ${{ (inputs.stage == 'Upload' || inputs.stage == 'All') && github.ref_type != 'tag' }}
shell: pwsh
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add "${{ github.workspace }}/.githubtocatalog/auto-generated-catalog.yml"
# Check if there are any changes to be committed
git diff --staged --quiet
if ($LASTEXITCODE -ne 0) {
git commit -m "auto-generated"
}
else {
Write-Host "No changes to commit."
}
# Only try to push for non-tag
- name: Push .githubtocatalog/auto-generated-catalog
if: ${{ (inputs.stage == 'Upload' || inputs.stage == 'All') && github.ref_type != 'tag' }}
run: |
git push
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
shell: pwsh
# Use branch name from 'findBranch' step for the branch name when a tag
- name: Upload to CatalogUpload
id: uploadToCatalogTag
if: ${{ (inputs.stage == 'Upload' || inputs.stage == 'All') && github.ref_type == 'tag' }}
run: echo "id=$(dataminer-catalog-upload with-registration --path-to-artifact "${{ steps.solutionFolder.outputs.path }}/${{ steps.packageName.outputs.name }}.dmapp" --artifact-version "${{ github.ref_name }}" --branch "${{ steps.findBranch.outputs.branch }}" --dm-catalog-token ${{ inputs.api-key }})" >> $GITHUB_OUTPUT
shell: bash
# Use github.ref_name for the branch name when not a tag
- name: Upload to CatalogUpload
id: uploadToCatalog
if: ${{ (inputs.stage == 'Upload' || inputs.stage == 'All') && github.ref_type != 'tag' }}
run: echo "id=$(dataminer-catalog-upload with-registration --path-to-artifact "${{ steps.solutionFolder.outputs.path }}/${{ steps.packageName.outputs.name }}.dmapp" --artifact-version "${{ github.ref_name }}" --branch "${{ github.ref_name }}" --dm-catalog-token ${{ inputs.api-key }})" >> $GITHUB_OUTPUT
shell: bash
- name: Set artifact Id
id: setArtifactId
if: ${{ inputs.stage == 'Upload' || inputs.stage == 'All' }}
run: echo "artifact-id=${{ steps.uploadToCatalog.outputs.id }}${{ steps.uploadToCatalogTag.outputs.id }}" >> $GITHUB_OUTPUT
shell: bash
# Deploy using the retrieved artifact-id from the CatalogUpload
- name: Deploy to DataMiner
if: ${{ inputs.stage == 'All' }}
run: dataminer-package-deploy from-catalog --artifact-id "${{ steps.setArtifactId.outputs.artifact-id }}" --dm-catalog-token ${{ inputs.api-key }}
shell: bash
# Depoy using the provided artifact-id
- name: Deploy to DataMiner
if: ${{ inputs.stage == 'Deploy' }}
run: dataminer-package-deploy from-catalog --artifact-id "${{ inputs.artifact-id }}" --dm-catalog-token ${{ inputs.api-key }}
shell: bash