GitHub Actions to assist with Power Apps Solutions
Tags: actionshackathon, powerapps
Published: 2020-08-30 04:26:56

### My Workflow
In Power Apps we package assets into Solution. Solutions are how customisations move from one environment into another. We use Solution Packager to unpack and repack the Solutions. 

It is easy to do this in Azure DevOps, as there are Microsoft, aswell as third-party tools to help with this. Since there is no Action currently in GitHub Marketplace to help with this, I thought it would be a fun project to do this using only PowerShell, so I have developed these two Actions.

1. [Power Apps Extract Solution](https://github.com/rajyraman/powerapps-solution-extract) - This Action unpacks the Solution files into assets using Solution Packager and commits them into your repo
2. [Power Apps Deploy Solution](https://github.com/rajyraman/powerapps-deploy-solution) - This Action deploys the Solution file into the Power Apps environment.

Since I wanted to do this just using PowerShell, I found it relatively easy to do this using open-source commandlets in PowerShell Gallery and [composite run steps](https://docs.github.com/en/actions/creating-actions/creating-a-composite-run-steps-action)

### Sample Workflow

Here is a sample Workflow on how you can use these two Actions in your GitHub Workflow.

```yaml
# This workflow is run only manually, as it uses a workflow_dispatch. It is recommended to use cron or push into main branch to trigger this. Since this workflow also commits into the repo, use ignore tags to prevent infinite loop. Refer https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-ignoring-branches-and-tags

name: extract-and-deploy
on:
  workflow_dispatch:
    inputs:
      solutionName:
        description: "Solution Name"
        required: true
        default: "GitHubSolution"
      sourceEnvironmentUrl:
        description: "Source Environment URL"
        required: true
        default: "https://xxxx.crm.dynamics.com"
      targetEnvironmentUrl:
        description: "Target Environment URL"
        required: true
        default: "https://xxxx.crm.dynamics.com"
      release:
        description: "Release?"
        required: true
        default: true
      managed:
        description: "Managed?"
        required: true
        default: true
      debug:
        description: "Debug?"
        required: true
        default: "true"

jobs:
  build:
    # The type of runner that the job will run on. This needs to be Windows runner.
    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v2

      - name: Dump GitHub context
        if: github.event.inputs.debug == 'true'
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"

      - name: Extract Solution
        id: extract-solution
        uses: rajyraman/powerapps-solution-extract@v1.1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          solutionName: ${{ github.event.inputs.solutionName }}
          sourceEnvironmentUrl: ${{ github.event.inputs.sourceEnvironmentUrl }}
          applicationId: ${{ secrets.APPLICATION_ID }}
          applicationSecret: ${{ secrets.APPLICATION_SECRET }}
          releaseSolution: ${{ github.event.inputs.release }}

      - name: Deploy Solution
        id: deploy-solution
        uses: rajyraman/powerapps-deploy-solution@v1.1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          solutionName: ${{ github.event.inputs.solutionName }}
          targetEnvironmentUrl: ${{ github.event.inputs.targetEnvironmentUrl }}
          applicationId: ${{ secrets.APPLICATION_ID }}
          applicationSecret: ${{ secrets.APPLICATION_SECRET }}
          tag: ${{ steps.extract-solution.outputs.solutionVersion }}
          managed: ${{ github.event.inputs.managed }}


        # This step below can be removed, if you do not want to send a notification to Teams about this solution deployment.
      - name: Notify Teams
        uses: fjogeleit/http-request-action@v1.4.1
        with:
          # Url to Power Automate Flow to notify about Solution Deployment
          url: "${{ secrets.FLOW_HTTP_URL }}"
          # Request body to be sent the Flow with HTTP Trigger
          data: >-
            {
                "solutionFile": "${{ steps.deploy-solution.outputs.solution }}",
                "tag": "${{ steps.deploy-solution.outputs.solutionVersion }}",
                "environmentUrl": "${{ github.event.inputs.targetEnvironmentUrl }}",
                "repoUrl": "https://github.com/${{ github.repository }}",
                "runId": "${{ github.run_id }}",
                "sha": "${{ github.sha }}"
            }
```
### Sample Workflow Run
![GitHub Workflow Log](https://dev-to-uploads.s3.amazonaws.com/i/5egm188ghj631rhf1rts.png)

### Release and Assets created by Power Apps Extract Solution Action
![Release Assets](https://dev-to-uploads.s3.amazonaws.com/i/vtv9q31qs5l1jb5j1qwc.png)

### Teams Notifications using Power Automate
![Team Notification using Power Automate](https://dev-to-uploads.s3.amazonaws.com/i/npzohexl47vznd5nbnsd.png)


### Submission Category: 

Wacky Wildcards


### Yaml File or Link to Code

{% github rajyraman/powerapps-deploy-solution %}
{% github rajyraman/powerapps-solution-extract %}