|
1 | | -# action-cli-deploy |
| 1 | +# Office 365 CLI deploy GitHub action |
2 | 2 | GitHub action to deploy an app using Office 365 CLI |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +This GitHub Action (created using typescript) uses [Office 365 CLI](https://pnp.github.io/office365-cli/), specifically the [spo app add](https://pnp.github.io/office365-cli/cmd/spo/app/app-add/), [spo app deploy](https://pnp.github.io/office365-cli/cmd/spo/app/app-deploy/) and [spo app install](https://pnp.github.io/office365-cli/cmd/spo/app/app-install/) commands, to add, deploy and (if site collection) install an app. |
| 7 | + |
| 8 | +## Usage |
| 9 | +### Pre-requisites |
| 10 | +Create a workflow `.yml` file in your `.github/workflows` directory. An [example workflow](#example-workflow---office-365-cli-deploy) is available below. For more information, reference the GitHub Help Documentation for [Creating a workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file). |
| 11 | + |
| 12 | +## Dependencies on other GitHub Actions |
| 13 | + |
| 14 | +- [Office 365 CLI Login](https://github.com/pnp/action-cli-login) – **Required** . This action is dependant on `action-cli-login`. So in the workflow we need to run `action-cli-login` before using this action. |
| 15 | + |
| 16 | +#### Optional requirement |
| 17 | +Since `action-cli-login` requires user name and password which are sensitive pieces of information, it would be ideal to store them securely. We can achieve this in a GitHub repo by using [secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets). So, click on `settings` tab in your repo and add 2 new secrets: |
| 18 | +- `adminUsername` - store the admin user name in this (e.g. user@contoso.onmicrosoft.com) |
| 19 | +- `adminPassword` - store the password of that user in this. |
| 20 | +These secrets are encrypted and can only be used by GitHub actions. |
| 21 | + |
| 22 | +### Inputs |
| 23 | +- `APP_FILE_PATH` : **Required** Relative path of the app in your repo |
| 24 | +- `SCOPE` : Scope of the app catalog: `tenant|sitecollection`. Default is `tenant` |
| 25 | +- `SITE_COLLECTION_URL` : The URL of the site collection where the solution package will be added and installed. Required if scope is set to `sitecollection` |
| 26 | +- `SKIP_FEATURE_DEPLOYMENT` : `true|false` If the app supports tenant-wide deployment, deploy it to the whole tenant. Default is `false` |
| 27 | +- `OVERWRITE` : `true|false` Set to overwrite the existing package file. Default is `false` |
| 28 | + |
| 29 | +### Output |
| 30 | +- `APP_ID` : The id of the app that gets deployed |
| 31 | + |
| 32 | +### Example workflow - Office 365 CLI Deploy |
| 33 | +On every `push` build the code, then login to Office 365 and then start deploying. |
| 34 | + |
| 35 | +```yaml |
| 36 | +name: SPFx CICD with O365 CLI |
| 37 | + |
| 38 | +on: [push] |
| 39 | + |
| 40 | +jobs: |
| 41 | + build: |
| 42 | + ## |
| 43 | + ## Build code omitted |
| 44 | + ## |
| 45 | + |
| 46 | + deploy: |
| 47 | + needs: build |
| 48 | + runs-on: ubuntu-latest |
| 49 | + strategy: |
| 50 | + matrix: |
| 51 | + node-version: [10.x] |
| 52 | + |
| 53 | + steps: |
| 54 | + |
| 55 | + ## |
| 56 | + ## Code to get the package omitted |
| 57 | + ## |
| 58 | + |
| 59 | + # Office 365 cli login action |
| 60 | + - name: Login to tenant |
| 61 | + uses: pnp/action-cli-login@v1.0.0 |
| 62 | + with: |
| 63 | + ADMIN_USERNAME: ${{ secrets.adminUsername }} |
| 64 | + ADMIN_PASSWORD: ${{ secrets.adminPassword }} |
| 65 | + |
| 66 | + # Office 365 cli deploy app action |
| 67 | + # Use either option 1 or option 2 |
| 68 | + |
| 69 | + # Option 1 - Deploy app at tenant level |
| 70 | + - name: Option 1 - Deploy app to tenant |
| 71 | + id: o365clideploy # optional - use if output needs to be used |
| 72 | + uses: pnp/action-cli-deploy@v1.0.0 |
| 73 | + with: |
| 74 | + APP_FILE_PATH: sharepoint/solution/spfx-o365-cli-action.sppkg |
| 75 | + SKIP_FEATURE_DEPLOYMENT: true |
| 76 | + OVERWRITE: true |
| 77 | + # Option 1 - ends |
| 78 | + |
| 79 | + # Option 2 - Deploy app to a site collection |
| 80 | + - name: Option 2 - Deploy app to a site collection |
| 81 | + uses: pnp/action-cli-deploy@v1.0.0 |
| 82 | + with: |
| 83 | + APP_FILE_PATH: sharepoint/solution/spfx-o365-cli-action.sppkg |
| 84 | + SCOPE: sitecollection |
| 85 | + SITE_COLLECTION_URL: https://contoso.sharepoint.com/sites/teamsite |
| 86 | + # Option 2 - ends |
| 87 | + |
| 88 | + # Print the id of the app |
| 89 | + - name: Get the id of the app deployed |
| 90 | + run: echo "The id of the app deployed is ${{ steps.o365clideploy.outputs.APP_ID }}" |
| 91 | +``` |
| 92 | +
|
| 93 | +
|
| 94 | +#### Self-hosted runners |
| 95 | +If self-hosted runners are used for running the workflow, then please make sure that they have `PowerShell` or `bash` installed on them. |
| 96 | + |
| 97 | +## Release notes |
| 98 | + |
| 99 | +### v1.0.0 |
| 100 | +- Added inital 'Office 365 CLI deploy' GitHub action solving #2 |
0 commit comments