From cfbb0671b4e3b75b1916ed6676f374e1087ecf57 Mon Sep 17 00:00:00 2001 From: Matias Lera <62261539+luislera@users.noreply.github.com> Date: Mon, 2 May 2022 11:20:33 -0300 Subject: [PATCH 1/6] Added support to solution upgrade --- .github/actions/deploy-solution/action.yml | 17 +++++++++++++++++ .github/workflows/build-deploy-solution.yml | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/.github/actions/deploy-solution/action.yml b/.github/actions/deploy-solution/action.yml index 9cfcfde9..fbe13339 100644 --- a/.github/actions/deploy-solution/action.yml +++ b/.github/actions/deploy-solution/action.yml @@ -22,6 +22,9 @@ inputs: secrets: description: "secrets" required: true + solution_action: + description: "solution_action" + required: true runs: using: "composite" @@ -71,6 +74,8 @@ runs: - name: import-solution-to-environment uses: microsoft/powerplatform-actions/import-solution@latest + env: + import_as_holding: "${{ inputs.solution_action == 'upgrade' && 'true' || 'false' }}" with: environment-url: ${{ inputs.environment_url }} tenant-id: ${{ env.TENANT_ID }} @@ -81,3 +86,15 @@ runs: use-deployment-settings-file: true deployment-settings-file: src/${{ inputs.solution_name }}/config/deploymentSettings.json run-asynchronously: true + import-as-holding: ${{ env.import_as_holding }} + + - name: upgrade-solution + uses: microsoft/powerplatform-actions/upgrade-solution@main + with: + environment-url: ${{ inputs.environment_url }} + tenant-id: ${{ env.TENANT_ID }} + app-id: ${{ env.CLIENT_ID }} + client-secret: ${{ env.CLIENT_SECRET }} + solution-name: ${{ inputs.solution_name }} + async: true + if: ${{ inputs.solution_action == 'upgrade'}} \ No newline at end of file diff --git a/.github/workflows/build-deploy-solution.yml b/.github/workflows/build-deploy-solution.yml index e10ccd4a..00c0a3b1 100644 --- a/.github/workflows/build-deploy-solution.yml +++ b/.github/workflows/build-deploy-solution.yml @@ -16,6 +16,10 @@ on: environment: required: true description: "environment where the build will be deployed" + solution_action: + description: "update or upgrade the solution" + required: true + default: "update" jobs: build-deploy-solution: @@ -62,6 +66,7 @@ jobs: solution_name: ${{ github.event.inputs.solution_name }} environment: ${{ needs.get-subdomain.outputs.subdomain }} secrets: ${{ toJSON(secrets) }} + solution_action: ${{ github.event.inputs.solution_action }} import-data-and-turn-on-flows: runs-on: windows-2022 From 9ca75b5ae541a21474d857f74515c0cd9819342e Mon Sep 17 00:00:00 2001 From: Matias Lera <62261539+luislera@users.noreply.github.com> Date: Mon, 2 May 2022 11:29:51 -0300 Subject: [PATCH 2/6] Updated actions/github-script version --- .github/workflows/build-deploy-solution.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-deploy-solution.yml b/.github/workflows/build-deploy-solution.yml index 00c0a3b1..d60eb7df 100644 --- a/.github/workflows/build-deploy-solution.yml +++ b/.github/workflows/build-deploy-solution.yml @@ -30,7 +30,7 @@ jobs: - if: contains(github.event.inputs.ref, 'refs/pull') name: update-commit-status id: update-commit-status - uses: actions/github-script@v5 + uses: actions/github-script@v6 env: CONTEXT_TO_USE: build-deploy-${{ github.event.inputs.solution_name }} SHA: ${{ github.event.inputs.sha }} @@ -98,7 +98,7 @@ jobs: - if: contains(github.event.inputs.ref, 'refs/pull') name: update-commit-status id: update-commit-status - uses: actions/github-script@v5 + uses: actions/github-script@v6 env: CONTEXT_TO_USE: build-deploy-${{ github.event.inputs.solution_name }} SHA: ${{ github.event.inputs.sha }} From 91878950cde164fc76622eb7233bdb087da0d9a6 Mon Sep 17 00:00:00 2001 From: Matias Lera <62261539+luislera@users.noreply.github.com> Date: Tue, 28 Jun 2022 16:56:42 -0300 Subject: [PATCH 3/6] Updated latest tag --- .github/actions/deploy-solution/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/deploy-solution/action.yml b/.github/actions/deploy-solution/action.yml index fbe13339..f4ca5b2f 100644 --- a/.github/actions/deploy-solution/action.yml +++ b/.github/actions/deploy-solution/action.yml @@ -75,7 +75,7 @@ runs: - name: import-solution-to-environment uses: microsoft/powerplatform-actions/import-solution@latest env: - import_as_holding: "${{ inputs.solution_action == 'upgrade' && 'true' || 'false' }}" + import_as_holding: "${{ inputs.solution_action == 'upgrade' }}" with: environment-url: ${{ inputs.environment_url }} tenant-id: ${{ env.TENANT_ID }} @@ -89,7 +89,7 @@ runs: import-as-holding: ${{ env.import_as_holding }} - name: upgrade-solution - uses: microsoft/powerplatform-actions/upgrade-solution@main + uses: microsoft/powerplatform-actions/upgrade-solution@latest with: environment-url: ${{ inputs.environment_url }} tenant-id: ${{ env.TENANT_ID }} @@ -97,4 +97,4 @@ runs: client-secret: ${{ env.CLIENT_SECRET }} solution-name: ${{ inputs.solution_name }} async: true - if: ${{ inputs.solution_action == 'upgrade'}} \ No newline at end of file + if: ${{ inputs.solution_action == 'upgrade' }} \ No newline at end of file From 2ac9cc3e160effb4012dfb6b9e5431b8de6a3384 Mon Sep 17 00:00:00 2001 From: Matias Lera <62261539+luislera@users.noreply.github.com> Date: Fri, 15 Jul 2022 09:55:29 -0300 Subject: [PATCH 4/6] Added an action to check if a solution exists --- .../check-solution-existence/action.yml | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/actions/check-solution-existence/action.yml diff --git a/.github/actions/check-solution-existence/action.yml b/.github/actions/check-solution-existence/action.yml new file mode 100644 index 00000000..fb81bf53 --- /dev/null +++ b/.github/actions/check-solution-existence/action.yml @@ -0,0 +1,72 @@ +name: check-solution-existence + +description: check-solution-existence + +inputs: + solution_name: + description: solution_name + required: true + environment_url: + description: environment_url + required: true + tenant_id: + description: tenant_id + required: true + client_id: + description: client_id + required: true + client_secret: + description: client_secret + required: true + secrets: + description: "environment secrets" + required: true + +outputs: + solution_exists: + description: "solution existence flag" + value: ${{ steps.get-solutions-from-env.outputs.solution_exists }} + +runs: + using: "composite" + steps: + - uses: Firenza/secrets-to-env@v1.1.0 + with: + secrets: ${{ inputs.secrets }} + + - name: set-pac-path + uses: ./.github/actions/set-pac-path + + # Use pac cli command to get the solutions list. + # This action is not implemented in GitHub Actions for Power Platform + - name: get-solutions-from-env + id: get-solutions-from-env + run: | + # Create a connection to the environment + $environment_url = "${{ inputs.environment_url }}" + $tenant_id = "${{ inputs.tenant_id }}" + $client_id = "${{ inputs.client_id }}" + $client_secret = "${{ inputs.client_secret }}" + pac auth create --url $environment_url --tenant $tenant_id --applicationId $client_id --clientSecret $client_secret + + # List all the solutions on the environment + $result = pac solution list + $lines = $result | where{$_ -ne ""} | Select-Object -Skip 3 + $solution_exists = $false + + # Check if the solution unique name exists in the solution list + for ($i=0; $i -lt $lines.Length; $i++) { + while($lines[$i].Contains(" ")) { + $lines[$i] = $lines[$i].Replace(" ", " ") + } + + $columns = $lines[$i] -split " " + if ($columns[2] -eq "${{ inputs.solution_name }}") { + $solution_exists = $true + break + } + } + + # Return the flag + echo "::set-output name=solution_exists::$solution_exists" + shell: pwsh From a48efa57eff955145d3fc646296f303b77d55cf0 Mon Sep 17 00:00:00 2001 From: Matias Lera <62261539+luislera@users.noreply.github.com> Date: Fri, 15 Jul 2022 09:56:41 -0300 Subject: [PATCH 5/6] Updated the deploy-solution action to force an upgrade --- .github/actions/deploy-solution/action.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/actions/deploy-solution/action.yml b/.github/actions/deploy-solution/action.yml index f4ca5b2f..a21dae1d 100644 --- a/.github/actions/deploy-solution/action.yml +++ b/.github/actions/deploy-solution/action.yml @@ -25,6 +25,10 @@ inputs: solution_action: description: "solution_action" required: true + solution_exists: + description: "solution_exists" + default: "false" + required: false runs: using: "composite" @@ -75,7 +79,7 @@ runs: - name: import-solution-to-environment uses: microsoft/powerplatform-actions/import-solution@latest env: - import_as_holding: "${{ inputs.solution_action == 'upgrade' }}" + import_as_holding: "${{ inputs.solution_action == 'upgrade' && inputs.solution_exists == 'True' }}" with: environment-url: ${{ inputs.environment_url }} tenant-id: ${{ env.TENANT_ID }} @@ -97,4 +101,4 @@ runs: client-secret: ${{ env.CLIENT_SECRET }} solution-name: ${{ inputs.solution_name }} async: true - if: ${{ inputs.solution_action == 'upgrade' }} \ No newline at end of file + if: ${{ inputs.solution_action == 'upgrade' && inputs.solution_exists == 'True' }} \ No newline at end of file From 6e8029146dbdd9c302380be10193924e3f603ead Mon Sep 17 00:00:00 2001 From: Matias Lera <62261539+luislera@users.noreply.github.com> Date: Fri, 15 Jul 2022 09:57:09 -0300 Subject: [PATCH 6/6] Added a step to check if the solution exists in the environment --- .github/workflows/build-deploy-solution.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-deploy-solution.yml b/.github/workflows/build-deploy-solution.yml index d60eb7df..cb196d66 100644 --- a/.github/workflows/build-deploy-solution.yml +++ b/.github/workflows/build-deploy-solution.yml @@ -19,11 +19,29 @@ on: solution_action: description: "update or upgrade the solution" required: true - default: "update" + default: "upgrade" jobs: + check-solution-existence: + runs-on: windows-2022 + environment: ${{ github.event.inputs.environment }} + steps: + - uses: actions/checkout@v2 + - id: check-solution + uses: ./.github/actions/check-solution-existence + with: + solution_name: ${{ secrets.SOLUTION_NAME }} + environment_url: ${{ secrets.ENVIRONMENT_URL }} + tenant_id: ${{ secrets.TENANT_ID }} + client_id: ${{ secrets.CLIENT_ID }} + client_secret: ${{ secrets.CLIENT_SECRET }} + secrets: ${{ toJSON(secrets) }} + outputs: + solution_exists: ${{ steps.check-solution.outputs.solution_exists }} + build-deploy-solution: runs-on: ubuntu-latest + needs: check-solution-existence name: deploy solution to ${{ github.event.inputs.environment }} environment environment: ${{ github.event.inputs.environment }} steps: @@ -67,6 +85,7 @@ jobs: environment: ${{ needs.get-subdomain.outputs.subdomain }} secrets: ${{ toJSON(secrets) }} solution_action: ${{ github.event.inputs.solution_action }} + solution_exists: ${{ needs.check-solution-existence.outputs.solution_exists }} import-data-and-turn-on-flows: runs-on: windows-2022