Skip to content

Commit 62d063b

Browse files
anooptVelinGeorgiev
authored andcommitted
Added 'Office 365 CLI runscript' GitHub action solving #2
1 parent c9d80b5 commit 62d063b

File tree

10 files changed

+2325
-1
lines changed

10 files changed

+2325
-1
lines changed

.gitignore

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# comment out in distribution branches
2+
node_modules/
3+
4+
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
lerna-debug.log*
12+
13+
# Diagnostic reports (https://nodejs.org/api/report.html)
14+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
15+
16+
# Runtime data
17+
pids
18+
*.pid
19+
*.seed
20+
*.pid.lock
21+
22+
# Directory for instrumented libs generated by jscoverage/JSCover
23+
lib-cov
24+
25+
# Coverage directory used by tools like istanbul
26+
coverage
27+
*.lcov
28+
29+
# nyc test coverage
30+
.nyc_output
31+
32+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
33+
.grunt
34+
35+
# Bower dependency directory (https://bower.io/)
36+
bower_components
37+
38+
# node-waf configuration
39+
.lock-wscript
40+
41+
# Compiled binary addons (https://nodejs.org/api/addons.html)
42+
build/Release
43+
44+
# Dependency directories
45+
jspm_packages/
46+
47+
# TypeScript v1 declaration files
48+
typings/
49+
50+
# TypeScript cache
51+
*.tsbuildinfo
52+
53+
# Optional npm cache directory
54+
.npm
55+
56+
# Optional eslint cache
57+
.eslintcache
58+
59+
# Optional REPL history
60+
.node_repl_history
61+
62+
# Output of 'npm pack'
63+
*.tgz
64+
65+
# Yarn Integrity file
66+
.yarn-integrity
67+
68+
# dotenv environment variables file
69+
.env
70+
.env.test
71+
72+
# parcel-bundler cache (https://parceljs.org/)
73+
.cache
74+
75+
# next.js build output
76+
.next
77+
78+
# nuxt.js build output
79+
.nuxt
80+
81+
# vuepress build output
82+
.vuepress/dist
83+
84+
# Serverless directories
85+
.serverless/
86+
87+
# FuseBox cache
88+
.fusebox/
89+
90+
# DynamoDB Local files
91+
.dynamodb/

README.md

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,74 @@
1-
# action-cli-runscript
1+
# Office 365 CLI runscript GitHub action
22
GitHub action to run a script using the Office 365 CLI
3+
4+
![Office 365 CLI Runscript](./images/cli-runscript.png)
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

action.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: 'Office 365 CLI Run Script'
2+
description: 'Runs an Office 365 CLI script'
3+
inputs:
4+
O365_CLI_SCRIPT_PATH:
5+
description: 'Relative path of the script in your repo.'
6+
O365_CLI_SCRIPT:
7+
description: 'Office 365 CLI Script'
8+
IS_POWERSHELL:
9+
description: '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'
10+
runs:
11+
using: "node12"
12+
main: "dist/index.js"
13+
branding:
14+
icon: 'terminal'
15+
color: 'blue'

0 commit comments

Comments
 (0)