Created
January 6, 2025 00:30
-
-
Save melamriD365/1fb25852d4a6c49d5764bc89d556daad to your computer and use it in GitHub Desktop.
Automatic Configuration Data Deployment in Dataverse Solutions Using GitHub Actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: migrate-configuration-data | |
on: | |
workflow_dispatch: | |
inputs: | |
sourceEnvironmentUrl: | |
description: "Source environment URL (e.g., https://source.crm.dynamics.com)" | |
required: true | |
targetEnvironmentUrl: | |
description: "Target environment URL (e.g., https://target.crm.dynamics.com)" | |
required: true | |
schemaFile: | |
description: "Schema file name (e.g., schema.xml)" | |
required: true | |
outputPath: | |
description: "Path to store the unzipped configuration data (e.g., ConfigurationData)" | |
required: true | |
permissions: | |
contents: write | |
jobs: | |
migrate-configuration-data: | |
runs-on: windows-latest | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: true | |
- name: Install Powerplatform Actions | |
uses: microsoft/powerplatform-actions/[email protected] | |
- name: Export Data from Source Environment | |
uses: microsoft/powerplatform-actions/export-data@v1 | |
with: | |
environment-url: ${{ github.event.inputs.sourceEnvironmentUrl }} | |
app-id: ${{ secrets.APP_USER_ID }} | |
client-secret: ${{ secrets.APP_USER_SECRET }} | |
tenant-id: ${{ secrets.TENANT_ID }} | |
schema-file: ${{ github.event.inputs.schemaFile }} | |
data-file: "data.zip" | |
overwrite: true | |
verbose: true | |
- name: Verify Data Export | |
run: | | |
if (Test-Path "data.zip") { | |
Write-Output "Data exported successfully." | |
} else { | |
Write-Error "Data export failed." | |
exit 1 | |
} | |
shell: pwsh | |
- name: Unzip Exported Data | |
run: | | |
$zipPath = "data.zip" | |
$extractPath = "${{ github.event.inputs.outputPath }}" | |
# Remove existing directory if it exists to avoid residual files | |
if (Test-Path $extractPath) { | |
Remove-Item -Recurse -Force $extractPath | |
} | |
# Create extraction directory | |
New-Item -ItemType Directory -Path $extractPath | |
# Expand the archive | |
Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force | |
Write-Output "Data unzipped to $extractPath successfully." | |
shell: pwsh | |
- name: Import Data to Target Environment | |
uses: microsoft/powerplatform-actions/import-data@v1 | |
with: | |
environment-url: ${{ github.event.inputs.targetEnvironmentUrl }} | |
app-id: ${{ secrets.APP_USER_ID }} | |
client-secret: ${{ secrets.APP_USER_SECRET }} | |
tenant-id: ${{ secrets.TENANT_ID }} | |
data-file: "data.zip" | |
connection-count: 5 | |
verbose: true | |
- name: Verify Data Import | |
run: | | |
Write-Output "Data import initiated. Please verify the import in the target environment." | |
shell: pwsh | |
- name: Configure Git | |
run: | | |
git config --global user.email "meelamri@...." | |
git config --global user.name "melamri..." | |
shell: pwsh | |
- name: Add Schema and Configuration Files to Git | |
run: | | |
git add "${{ github.event.inputs.outputPath }}/" | |
shell: pwsh | |
- name: Commit Changes | |
run: | | |
git commit -m "Data migration" || echo "No changes to commit." | |
shell: pwsh | |
- name: Push Changes to Main | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git push origin main | |
shell: pwsh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment