|
1 | | -# action-cli-runscript |
| 1 | +# Office 365 CLI runscript GitHub action |
2 | 2 | GitHub action to run a script using the Office 365 CLI |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +This GitHub Action (created using typescript) uses [Office 365 CLI](https://pnp.github.io/office365-cli/), to run a line of script supplied to it or run code in a script file supplied to it. |
| 7 | + |
| 8 | +## Usage |
| 9 | +### Pre-requisites |
| 10 | +Create a workflow `.yml` file in `.github/workflows` directory of your repo. An [example workflow](#example-workflow---office-365-cli-runscript) 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 | +- `O365_CLI_SCRIPT_PATH` : Relative path of the script in your repo. |
| 24 | +- `O365_CLI_SCRIPT` : The script to run |
| 25 | +- `IS_POWERSHELL` : `true|false` Used only with O365_CLI_SCRIPT. If true the assumption is the script passed in O365_CLI_SCRIPT will be a PowerShell script, otherwise the assumption is bash script. Default is false |
| 26 | + |
| 27 | +One of `O365_CLI_SCRIPT_PATH` / `O365_CLI_SCRIPT` is mandatory, in case both are defined `O365_CLI_SCRIPT_PATH` gets preference. |
| 28 | + |
| 29 | +### Example workflow - Office 365 CLI Runscript |
| 30 | +On every `push` build the code, then deploy and then send an email using Office 365 CLI Runscript action. |
| 31 | + |
| 32 | +```yaml |
| 33 | +name: SPFx CICD with O365 CLI |
| 34 | + |
| 35 | +on: [push] |
| 36 | + |
| 37 | +jobs: |
| 38 | + |
| 39 | + runscript: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + strategy: |
| 42 | + matrix: |
| 43 | + node-version: [10.x] |
| 44 | + |
| 45 | + steps: |
| 46 | + |
| 47 | + # Office 365 cli login action |
| 48 | + - name: Login to tenant |
| 49 | + uses: pnp/action-cli-login@v1.0.0 |
| 50 | + with: |
| 51 | + ADMIN_USERNAME: ${{ secrets.adminUsername }} |
| 52 | + ADMIN_PASSWORD: ${{ secrets.adminPassword }} |
| 53 | + |
| 54 | + # Office 365 CLI runscript action option 1 (single line of script as input) |
| 55 | + - name: Send email |
| 56 | + uses: pnp/action-cli-runscript@v1.0.0 |
| 57 | + with: |
| 58 | + O365_CLI_SCRIPT: o365 spo mail send --webUrl https://contoso.sharepoint.com/sites/teamsite --to 'user@contoso.onmicrosoft.com' --subject 'Deployment done' --body '<h2>Office 365 CLI</h2> <p>The deployment is complete.</p> <br/> Email sent via Office 365 CLI GitHub Action.' |
| 59 | + |
| 60 | + # Office 365 CLI runscript action option 2 (script file as input) |
| 61 | + - name: Create lists |
| 62 | + uses: pnp/action-cli-runscript@v1.0.0 |
| 63 | + with: |
| 64 | + O365_CLI_SCRIPT_PATH: ./script/lists.ps1 |
| 65 | + #lists.ps1 will have all the required Office 365 CLI commands |
| 66 | +``` |
| 67 | + |
| 68 | +#### Self-hosted runners |
| 69 | +If self-hosted runners are used for running the workflow, then please make sure that they have `PowerShell` or `bash` installed on them. |
| 70 | + |
| 71 | +## Release notes |
| 72 | + |
| 73 | +### v1.0.0 |
| 74 | +- Added inital 'Office 365 CLI runscript' GitHub action solving #2 |
0 commit comments