GitHub action to deploy an app using CLI for Microsoft 365
This GitHub Action (created using typescript) uses CLI for Microsoft 365, specifically the spo app add, spo app deploy commands, to add and deploy.
Create a workflow .yml file in your .github/workflows directory. An example workflow is available below. For more information, reference the GitHub Help Documentation for Creating a workflow file.
- CLI for Microsoft 365 Login – Required . This action is dependant on
action-cli-login. So in the workflow we need to runaction-cli-loginbefore using this action.
Since action-cli-login requires sensitive pieces of information, it would be ideal to store them securely. We can achieve this in a GitHub repo by using secrets. Consult the action-cli-login docs to check which information you need.
The following table lists which versions of the GitHub action are compatible with which versions of the CLI for Microsoft 365.
| Version | CLI for Microsoft 365 version |
|---|---|
| ^v3.0.0 | v6.0.0 |
| v2.0.2 | v5.8.0 |
| v1.0.0 | v2.5.0 |
APP_FILE_PATH: Required Relative path of the app in your repoSCOPE: Scope of the app catalog:tenant,sitecollection. Default istenantSITE_COLLECTION_URL: The URL of the site collection where the solution package will be added. Required if scope is set tositecollectionSKIP_FEATURE_DEPLOYMENT:trueorfalse. If the app supports tenant-wide deployment, deploy it to the whole tenant. Default isfalseOVERWRITE:true,false. Set to overwrite the existing package file. Default isfalse
APP_ID: The id of the app that gets deployed
On every push build the code, then log in to Office 365 and then start deploying.
name: SPFx CICD with CLI for Microsoft 365
on: [push]
jobs:
build:
##
## Build code omitted
##
deploy:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22.x]
steps:
##
## Code to get the package omitted
##
# CLI for Microsoft 365 login action
- name: Log in to tenant
uses: pnp/action-cli-login@v3
with:
TENANT: ${{ secrets.TENANT }}
APP_ID: ${{ secrets.APP_ID }}
# CLI for Microsoft 365 deploy app action
# Use either option 1 or option 2
# Option 1 - Deploy app at tenant level
- name: Option 1 - Deploy app to tenant
id: climicrosoft365deploy # optional - use if output needs to be used
uses: pnp/action-cli-deploy@v5
with:
APP_FILE_PATH: sharepoint/solution/spfx-cli-microsoft365-action.sppkg
SKIP_FEATURE_DEPLOYMENT: true
OVERWRITE: true
# Option 1 - ends
# Option 2 - Deploy app to a site collection
- name: Option 2 - Deploy app to a site collection
uses: pnp/action-cli-deploy@v5
with:
APP_FILE_PATH: sharepoint/solution/spfx-cli-microsoft365-action.sppkg
SCOPE: sitecollection
SITE_COLLECTION_URL: https://contoso.sharepoint.com/sites/teamsite
# Option 2 - ends
# Print the id of the app
- name: Get the id of the app deployed
run: echo "The id of the app deployed is ${{ steps.climicrosoft365deploy.outputs.APP_ID }}"If self-hosted runners are used for running the workflow, then please make sure that they have PowerShell or bash installed on them.