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 diff --git a/.github/actions/deploy-solution/action.yml b/.github/actions/deploy-solution/action.yml index 9cfcfde9..a21dae1d 100644 --- a/.github/actions/deploy-solution/action.yml +++ b/.github/actions/deploy-solution/action.yml @@ -22,6 +22,13 @@ inputs: secrets: description: "secrets" required: true + solution_action: + description: "solution_action" + required: true + solution_exists: + description: "solution_exists" + default: "false" + required: false runs: using: "composite" @@ -71,6 +78,8 @@ runs: - name: import-solution-to-environment uses: microsoft/powerplatform-actions/import-solution@latest + env: + import_as_holding: "${{ inputs.solution_action == 'upgrade' && inputs.solution_exists == 'True' }}" with: environment-url: ${{ inputs.environment_url }} tenant-id: ${{ env.TENANT_ID }} @@ -81,3 +90,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@latest + 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' && inputs.solution_exists == 'True' }} \ No newline at end of file diff --git a/.github/workflows/build-deploy-solution.yml b/.github/workflows/build-deploy-solution.yml index b28a356b..cb196d66 100644 --- a/.github/workflows/build-deploy-solution.yml +++ b/.github/workflows/build-deploy-solution.yml @@ -16,10 +16,32 @@ on: environment: required: true description: "environment where the build will be deployed" + solution_action: + description: "update or upgrade the solution" + required: true + 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: @@ -62,6 +84,8 @@ jobs: solution_name: ${{ github.event.inputs.solution_name }} 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