PCF Components CI #23
This file contains 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
# This is a GitHub Actions workflow for Continuous Integration (CI) of PCF components. | |
# The workflow is triggered on every push only under the "resources/06-CodeItAndShipIt/frontend-development/pcf-components" folder to the main branch. | |
# The workflow runs on a Windows runner and uses the "Sandbox" environment. | |
# | |
# The workflow performs the following steps: | |
# 0. Enable git long paths: It enables long paths in git to avoid the "Filename too long" error. | |
# 1. Setup: It sets up the required environment with the necessary versions of Node.js and npm. | |
# 3. List the changed files under the "resources/06-CodeItAndShipIt/frontend-development/pcf-components" folder in the latest commit and identify the parent folder of the changed files to get the name of changed PCF component and put it in the environment variable. | |
# 3. Install Dependencies: It installs all the dependencies defined in the package.json file. | |
# 4. Build: It builds the PCF components located under the "resources/06-CodeItAndShipIt/frontend-development/pcf-components" folder using the 'npm run build' command - we can have multiple PCF components implemented there. | |
# 5. Test: It runs unit tests using the 'npm test' command. | |
# 6. Setup msbuild: Using the microsoft/setup-msbuild@v2 GitHub action to install msbuild on the runner. | |
# 7. Pack solution: Run msbuild after installing it on the "resources/06-CodeItAndShipIt/frontend-development/solutions/PCFComponents" folder to create the solution zip file. | |
# 8. Store the packed solution zip file as an artifact. | |
# 9. Install the Power Platform CLI using the "microsoft/powerplatform-actions/actions-install@main" GitHub action. | |
# 10. Deploy: It deploys the solution zip file to the Dataverse environment using the "microsoft/powerplatform-actions/import-solution@main" GitHub action leveraging the "TENANT_ID", "CLIENT_ID" and "CLIENT_SECRET" GitHub environment secrets and the "DATAVERSE_ENVIRONMENT_URL" environment variable. | |
name: PCF Components CI | |
on: | |
workflow_dispatch: | |
push: | |
paths: | |
- 'resources/06-CodeItAndShipIt/frontend-development/pcf-components/**' | |
branches: | |
- main | |
jobs: | |
build-and-deploy: | |
runs-on: windows-latest | |
environment: | |
name: 'Sandbox' | |
steps: | |
- name: Enable git long paths | |
run: git config --system core.longpaths true | |
shell: bash | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Fetch commits | |
run: | | |
git fetch origin ${{ github.event.before }}:refs/remotes/origin/${{ github.event.before }} | |
git fetch origin ${{ github.sha }}:refs/remotes/origin/${{ github.sha }} | |
shell: bash | |
- name: List changed files | |
run: | | |
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep "^resources/06-CodeItAndShipIt/frontend-development/pcf-components/.*") | |
echo "List of changed files: $CHANGED_FILES" | |
echo "changed_files=$CHANGED_FILES" >> $GITHUB_ENV | |
shell: bash | |
- name: Set updated PCF component | |
run: | | |
echo "List of changed files:" | |
echo ${{ env.changed_files }} | |
UPDATED_PCF_COMPONENT=$(echo "${{ env.changed_files }}" | cut -d'/' -f3) | |
echo "Updated PCF component: $UPDATED_PCF_COMPONENT" | |
echo "UPDATED_PCF_COMPONENT=$UPDATED_PCF_COMPONENT" >> $GITHUB_ENV | |
shell: bash | |
- name: Install Dependencies | |
run: npm install | |
working-directory: resources/06-CodeItAndShipIt/frontend-development/pcf-components/${{ env.UPDATED_PCF_COMPONENT }} | |
- name: Build | |
run: npm run build | |
working-directory: resources/06-CodeItAndShipIt/frontend-development/pcf-components/${{ env.UPDATED_PCF_COMPONENT }} | |
- name: Test | |
run: npm test | |
working-directory: resources/06-CodeItAndShipIt/frontend-development/pcf-components/${{ env.UPDATED_PCF_COMPONENT }} | |
- name: Setup msbuild | |
uses: microsoft/setup-msbuild@v2 | |
- name: Pack solution | |
run: msbuild /t:build /restore /p:configuration=Release | |
working-directory: resources/06-CodeItAndShipIt/frontend-development/solutions/PCFComponents | |
- name: Store packed solution as artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: PCFComponents | |
path: resources/06-CodeItAndShipIt/frontend-development/solutions/PCFComponents/bin/Debug/PCFComponents.zip | |
- name: Install Power Platform CLI | |
uses: microsoft/powerplatform-actions/actions-install@main | |
- name: Deploy | |
uses: microsoft/powerplatform-actions/import-solution@main | |
with: | |
app-id: ${{ secrets.CLIENT_ID }} | |
client-secret: ${{ secrets.CLIENT_SECRET }} | |
tenant-id: ${{ secrets.TENANT_ID }} | |
environment-url: ${{ vars.DATAVERSE_ENVIRONMENT_URL }} | |
solution-file: resources/06-CodeItAndShipIt/frontend-development/solutions/PCFComponents/bin/Debug/PCFComponents.zip | |
force-overwrite: true | |
publish-changes: true | |
skip-dependency-check: false | |
stage-and-upgrade: false | |
run-asynchronously: true | |
use-deployment-settings-file: false | |
skip-lower-version: false |