-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathexport-unpack-commit-solution.yml
More file actions
191 lines (174 loc) · 7.97 KB
/
export-unpack-commit-solution.yml
File metadata and controls
191 lines (174 loc) · 7.97 KB
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
name: export-unpack-commit-solution
# Export solution from DEV environment
# unpack it, commit and push the changes
on:
workflow_dispatch:
inputs:
solution_name:
description: "name of the Solution in Dataverse environment"
required: true
default: yoursolutionname
environment_url:
description: "http endpoint of your Dataverse environment"
required: true
default: "https://[your-env].crm.dynamics.com"
source_branch:
description: "source branch"
required: true
default: main
branch_to_create:
description: "branch to create"
required: false
commit_message:
description: "message to provide for the commit"
required: true
allow_empty_commit:
description: "allow an empty commit"
required: true
default: 'false'
force_file_change:
description: "FOR_TESTING_ONLY"
required: true
default: 'false'
jobs:
# Needs it's own job in order for build-deploy-solution->environment value to be used.
get-environment-from-domain:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- id: get-subdomain
uses: ./.github/actions/get-subdomain
with:
url: ${{ github.event.inputs.environment_url }}
outputs:
subdomain: ${{ steps.get-subdomain.outputs.subdomain }}
export-from-dev:
runs-on: ubuntu-latest
needs: get-environment-from-domain
environment: ${{ needs.get-environment-from-domain.outputs.subdomain }}
env:
solution_export_folder: solution-export-temp
solution_package_source: "src/${{ github.event.inputs.solution_name }}/SolutionPackage"
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.source_branch }}
# Workflows cannot cause another workflow event to fire with the standard GITHUB_TOKEN.
# By default, any event that would fire as a reult of logic in a GitHub workflow
# will not fire. Since this workflow pushes code to the remote repo, we use a token that can
token: ${{ secrets.WORKFLOW_DISPATCH_TOKEN }}
- name: create new git branch
if: github.event.inputs.branch_to_create != ''
run: |
git checkout -b ${{ github.event.inputs.branch_to_create }} ${{ github.event.inputs.source_branch }}
# Some Dataverse calls in this workflow cannot run async. Therefore, they will fail
# If someone runs more than one workflow against the environment at the same time.
# To prevent this, wait for other workflows queued up to finish before continuing
- name: queue-environment
id: queue-environment
uses: devkeydet/action-environment-queue@v1
with:
environment: ${{ needs.get-environment-from-domain.outputs.subdomain }}
- name: publish-customizations
uses: microsoft/powerplatform-actions/publish-solution@latest
with:
environment-url: ${{ github.event.inputs.environment_url}}
app-id: ${{ secrets.CLIENT_ID }}
client-secret: ${{ secrets.CLIENT_SECRET }}
tenant-id: ${{ secrets.TENANT_ID }}
- name: export-unmanaged-solution
uses: microsoft/powerplatform-actions/export-solution@latest
with:
environment-url: ${{ github.event.inputs.environment_url}}
app-id: ${{ secrets.CLIENT_ID }}
client-secret: ${{ secrets.CLIENT_SECRET }}
tenant-id: ${{ secrets.TENANT_ID }}
solution-name: ${{ github.event.inputs.solution_name }}
solution-output-file: ${{ runner.temp }}/${{ env.solution_export_folder }}/${{ github.event.inputs.solution_name }}.zip
managed: false
run-asynchronously: true
- name: export-managed-solution
uses: microsoft/powerplatform-actions/export-solution@latest
with:
environment-url: ${{ github.event.inputs.environment_url}}
app-id: ${{ secrets.CLIENT_ID }}
client-secret: ${{ secrets.CLIENT_SECRET }}
tenant-id: ${{ secrets.TENANT_ID }}
solution-name: ${{ github.event.inputs.solution_name }}
solution-output-file: ${{ runner.temp }}/${{ env.solution_export_folder }}/${{ github.event.inputs.solution_name }}_managed.zip
managed: true
run-asynchronously: true
- name: unpack-solution action
uses: microsoft/powerplatform-actions/unpack-solution@latest
with:
solution-file: ${{ runner.temp }}/${{ env.solution_export_folder }}/${{ github.event.inputs.solution_name }}.zip
solution-folder: ${{ env.solution_package_source }}
solution-type: "Both"
overwrite-files: true
# A solution’s version has the following format: major.minor.build.revision
# We don't want to keep build or revision from dev enironment. Only major.minor
# The build process will automate setting the major.minor version
- name: clear out solution build.revision number
shell: pwsh
run: |
$versionXmlMatch = '<Version>[\s\S]*?<\/Version>'
Get-ChildItem -Path "${{ env.solution_package_source }}/**/Solution.xml" |
ForEach-Object {
$solutionXml = Get-Content $_.FullName
$versionArray = ($solutionXml -match $versionXmlMatch).Trim().Replace('<Version>','').Replace('</Version>','').Split('.')
$major = $versionArray[0]
$minor = $versionArray[1]
$solutionXml -replace $versionXmlMatch,"<Version>$major.$minor.0.0</Version>" |
Out-File $_.FullName
}
# Until canvas unpack is supported through GitHub Actions for Power Platform we need to use pac directly.
# So we set the path to pac that ships with the Actions
- name: set-pac-path
uses: ./.github/actions/set-pac-path
- name: unpack msapp files
shell: pwsh
run: |
Get-ChildItem -Path "${{ env.solution_package_source }}/CanvasApps" -Recurse -Filter *.msapp |
ForEach-Object {
$unpackedPath = $_.FullName.Replace(".msapp", "_msapp_src")
pac canvas unpack --msapp $_.FullName --sources $unpackedPath
del $_.FullName
}
# TEMPORARY until platform/tools support formatted json files on unpack we
# update the Power Automate json files to be pretty-print / formatted so they are easier to read in source control.
# This also makes it easier to read changes from one commit to another
- name: format json files
shell: pwsh
run: |
Get-ChildItem -Path "${{ env.solution_package_source }}/Workflows" -Recurse -Filter *.json |
ForEach-Object {
Write-Host $_.FullName
$formatted = jq . $_.FullName --sort-keys
$formatted | Out-File $_.FullName -Encoding UTF8
}
- name: force-file-change
shell: pwsh
if: github.event.inputs.force_file_change == 'true'
run: |
$guid = New-Guid
New-Item -Path "src/${{ github.event.inputs.solution_name }}/SolutionPackage" -Name "for-test-automation.txt" -ItemType File -Value $guid -Force
- name: commit changes
shell: pwsh
run: |
git config --global user.name ${{ github.actor }}
git add --all
$allowEmptyCommit = [System.Convert]::ToBoolean("${{ github.event.inputs.allow_empty_commit }}")
if ($allowEmptyCommit) {
git commit -am "${{ github.event.inputs.commit_message }}" --allow-empty
}
else {
git commit -am "${{ github.event.inputs.commit_message }}"
}
- name: push to ${{ github.event.inputs.source_branch }}
if: github.event.inputs.branch_to_create == ''
run: |
git push
- name: push to ${{ github.event.inputs.branch_to_create }}
if: github.event.inputs.branch_to_create != ''
run: |
git push --set-upstream origin ${{ github.event.inputs.branch_to_create }}