Skip to content

Commit e0ef6f8

Browse files
michaelmaillotJwaegebaert
authored andcommitted
Updated CI / CD workflow page. Closes pnp#4179
1 parent aebb445 commit e0ef6f8

File tree

1 file changed

+132
-33
lines changed

1 file changed

+132
-33
lines changed

docs/docs/user-guide/github-actions.md

Lines changed: 132 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,25 @@ When connecting to any system or service, we need to make sure that the account
3333

3434
First you will need to need to navigate, in your browser, to your repository on GitHub.com and go to the `Settings` tab, from here choose the `Secrets` item on the left hand menu.
3535

36-
Using the `Add new secret` link, enter the `ADMIN_USERNAME` into the `Name` field and the username of the account that you are to use to connect to your Microsoft 365 tenant with, e.g. `[email protected]`. *Note: This account should not be protected with multi factor authentication*
36+
You may have two options when registering secrets in order to log in to your tenant:
37+
38+
* Using username / password (perfect to test your workflow, in a dev context, for personal usage) ==> **delegated secrets**
39+
* *In that case, the CLI commands will run as if it was you (list item updates, site creation...)*
40+
* Using Azure AD (AAD) application id / certificate (perfect in a production context, without creating any dependencies to an account) ==> **application secrets**
41+
* *Here, the CLI commands will run through an app, not a user*
42+
43+
##### Delegated secrets
44+
45+
Using the `Add new secret` link, enter the `ADMIN_USERNAME` into the `Name` field and the username of the account that you are to use to connect to your Microsoft 365 tenant with, e.g. `[email protected]`. *Note: This account should not be protected with multi-factor authentication*
3746

3847
Repeat the above step to also store the account password which should be named `ADMIN_PASSWORD`.
3948

49+
##### Application secrets
50+
51+
Using the `Add new secret` link, enter the `APP_ID` into the `Name` field and the (client) id of the AAD application to connect to your Microsoft 365 tenant with, e.g. `d355e6f0-0aec-4b1f-b458-7040f91bc297`.
52+
53+
Repeat the above step to also store the application's encoded certificate which should be named `CERTIFICATE_ENCODED`. If your certificate is encrypted with a password, then repeat one last time the previous step with a secret called `CERTIFICATE_PASSWORD`.
54+
4055
#### Setup workflow
4156

4257
Now that we have secured the account credentials, we can start to create the workflow.
@@ -73,28 +88,52 @@ The above configuration defines a simple workflow named `CI` that is triggered o
7388

7489
We will update the initial configuration as shown below, replacing the existing steps with the `CLI for Microsoft 365 Login` action instead.
7590

91+
##### Login with delegated secrets
92+
7693
```yaml
77-
name: CI
94+
name: CI
7895
79-
on: [push]
96+
on: [push]
8097
81-
jobs:
82-
build:
98+
jobs:
99+
build:
83100
84-
runs-on: ubuntu-latest
101+
runs-on: ubuntu-latest
85102
86-
steps:
103+
steps:
87104
88-
- name: Login to tenant
89-
90-
with:
91-
ADMIN_USERNAME: ${{ secrets.ADMIN_USERNAME }}
92-
ADMIN_PASSWORD: ${{ secrets.ADMIN_PASSWORD }}
105+
- name: Login to tenant
106+
107+
with:
108+
ADMIN_USERNAME: ${{ secrets.ADMIN_USERNAME }}
109+
ADMIN_PASSWORD: ${{ secrets.ADMIN_PASSWORD }}
110+
```
111+
112+
##### Login with application secrets
113+
114+
```yaml
115+
name: CI
116+
117+
on: [push]
118+
119+
jobs:
120+
build:
121+
122+
runs-on: ubuntu-latest
123+
124+
steps:
125+
126+
- name: Login to tenant
127+
128+
with:
129+
APP_ID: ${{ secrets.APP_ID }}
130+
CERTIFICATE_ENCODED: ${{ secrets.CERTIFICATE_ENCODED }}
131+
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
93132
```
94133

95134
The `uses` property tells the build agent to use the `CLI for Microsoft 365` GitHub Action for the step, this will automatically become available when the workflow is triggered, no installation is required.
96135

97-
The action accepts an admin username and password, which are used to authenticate with your Microsoft 365 tenant, these credentials are provided by an environment variable called `secrets` which contains properties exposing the secured credentials that we saved earlier.
136+
The action accepts an admin username and password (or an application id / encoded certificate), which are used to authenticate with your Microsoft 365 tenant, these credentials are provided by an environment variable called `secrets` which contains properties exposing the secured credentials that we saved earlier.
98137

99138
Lastly, we need to commit the `main.yaml` file to the repository, click the `Start Commit` button and click `Commit new file`. You may want enter a custom commit message at this point, however the default will be fine for this tutorial.
100139

@@ -110,6 +149,60 @@ Congratulations! You have just setup your first custom workflow in a GitHub repo
110149

111150
![CI Successful build](../images/github-actions-tutorial-success.png "CI Successful Build")
112151

152+
#### Specify the version of CLI for Microsoft 365
153+
154+
Sometimes, you would like to use the next (beta) version or a previous one of the CLI (because of a bug that is currently being addressed or to leverage a new feature to come).
155+
156+
The `CLI for Microsoft 365 Login` action provides an optional input to specify a version tag which can be `latest` (default if not specified), `next` or a specific one (`5.9.0`).
157+
158+
```yaml
159+
name: CI
160+
161+
on: [push]
162+
163+
jobs:
164+
build:
165+
166+
runs-on: ubuntu-latest
167+
168+
steps:
169+
170+
- name: Login to tenant
171+
172+
with:
173+
APP_ID: ${{ secrets.APP_ID }}
174+
CERTIFICATE_ENCODED: ${{ secrets.CERTIFICATE_ENCODED }}
175+
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
176+
CLI_VERSION: next
177+
```
178+
179+
#### Specify the tenant to connect to
180+
181+
Depending on the context, you could have to specify the tenant id if you have access to multiple tenants.
182+
183+
The `CLI for Microsoft 365 Login` allows you to indicate the targeting tenant (default `common`). It can be `organization` (if using an Azure AD app which is multitenant) or a tenant id.
184+
185+
```yaml
186+
name: CI
187+
188+
on: [push]
189+
190+
jobs:
191+
build:
192+
193+
runs-on: ubuntu-latest
194+
195+
steps:
196+
197+
- name: Login to tenant
198+
199+
with:
200+
APP_ID: ${{ secrets.APP_ID }}
201+
CERTIFICATE_ENCODED: ${{ secrets.CERTIFICATE_ENCODED }}
202+
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
203+
TENANT: 1e0e6964-032a-4e62-a8d7-4c6469d7554b
204+
```
205+
113206
## How-To Guides
114207

115208
These guides presuppose some familiarity with using GitHub Actions and CLI for Microsoft 365.
@@ -143,29 +236,30 @@ jobs:
143236
##
144237
145238
- name: Login to tenant
146-
uses: pnp/action-cli-login@v1.0.0
239+
uses: pnp/action-cli-login@v2.2.1
147240
with:
148-
ADMIN_USERNAME: ${{ secrets.ADMIN_USERNAME }}
149-
ADMIN_PASSWORD: ${{ secrets.ADMIN_PASSWORD }}
241+
APP_ID: ${{ secrets.APP_ID }}
242+
CERTIFICATE_ENCODED: ${{ secrets.CERTIFICATE_ENCODED }}
243+
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
150244
151245
- name: Deploy app to tenant app catalog
152-
id: o365clideploy
153-
uses: pnp/action-cli-deploy@v1.0.0
246+
id: M365clideploy
247+
uses: pnp/action-cli-deploy@v3.0.1
154248
with:
155249
APP_FILE_PATH: sharepoint/solution/spfx-m365-cli-action.sppkg
156250
SKIP_FEATURE_DEPLOYMENT: true
157251
OVERWRITE: true
158252
159253
- name: Get the id of the app deployed
160-
run: echo "The id of the app deployed is ${{ steps.o365clideploy.outputs.APP_ID }}"
254+
run: echo "The id of the app deployed is ${{ steps.M365clideploy.outputs.APP_ID }}"
161255
```
162256

163257
Alternatively, you can deploy the app to a site collection based app catalog by using the below step in replacement of the `Deploy app to tenant app catalog` step.
164258

165259
```yaml
166260
- name: Deploy app to a site collection app catalog
167-
id: o365clideploy
168-
uses: pnp/action-cli-deploy@v1.0.0
261+
id: M365clideploy
262+
uses: pnp/action-cli-deploy@v3.0.1
169263
with:
170264
APP_FILE_PATH: sharepoint/solution/spfx-m365-cli-action.sppkg
171265
SCOPE: sitecollection
@@ -178,9 +272,9 @@ Add this step to a `.yaml` build file contained within the `.github/workflows` f
178272

179273
```yaml
180274
- name: Send email
181-
uses: pnp/action-cli-runscript@v1.0.0
275+
uses: pnp/action-cli-runscript@v2.0.1
182276
with:
183-
O365_CLI_SCRIPT: m365 spo mail send --webUrl https://contoso.sharepoint.com/sites/teamsite --to '[email protected]' --subject 'Deployment done' --body '<h2>CLI for Microsoft 365</h2> <p>The deployment is complete.</p> <br/> Email sent via CLI for Microsoft 365 GitHub Action.'
277+
M365_CLI_SCRIPT: m365 spo mail send --webUrl https://contoso.sharepoint.com/sites/teamsite --to '[email protected]' --subject 'Deployment done' --body '<h2>CLI for Microsoft 365</h2> <p>The deployment is complete.</p> <br/> Email sent via CLI for Microsoft 365 GitHub Action.'
184278
```
185279

186280
### Execute a script file using the CLI for Microsoft 365 Run Script action
@@ -189,9 +283,9 @@ Add the respective script file to your repository and this step to a `.yaml` bui
189283

190284
```yaml
191285
- name: Create lists
192-
uses: pnp/action-cli-runscript@v1.0.0
286+
uses: pnp/action-cli-runscript@v2.0.1
193287
with:
194-
O365_CLI_SCRIPT_PATH: ./script/lists.ps1
288+
M365_CLI_SCRIPT_PATH: ./script/lists.ps1
195289
```
196290

197291
## Reference
@@ -202,10 +296,15 @@ View on [GitHub Marketplace](https://github.com/marketplace/actions/cli-for-micr
202296

203297
#### Inputs
204298

205-
| Name | Description | |
206-
| ------------------|--------------------------------------------| ---------|
207-
| `ADMIN_USERNAME` | The username of the account used to login | Required |
208-
| `ADMIN_PASSWORD` | The password of the account used to login | Required |
299+
| Name | Description | |
300+
| ------------------------|---------------------------------------------------------------------------| -------------------------------------------------------|
301+
| `ADMIN_USERNAME` | The username of the account used to login | Optional (but required if `authType` is `password`) |
302+
| `ADMIN_PASSWORD` | The password of the account used to login | Optional (but required if `authType` is `password`) |
303+
| `APP_ID` | App ID of the Azure AD application to use for certificate authentication | Optional (but required if `authType` is `certificate`) |
304+
| `CERTIFICATE_ENCODED` | Base64-encoded string with certificate private key | Optional (but required if `authType` is `certificate`) |
305+
| `CERTIFICATE_PASSWORD` | Password for the certificate | Optional |
306+
| `TENANT` | ID of the tenant from which accounts should be able to authenticate | Optional |
307+
| `CLI_VERSION` | Accepts `latest`, `next` or a specific version tag | Optional |
209308

210309
### Microsoft 365 Deploy App
211310

@@ -233,12 +332,12 @@ View on [GitHub Marketplace](https://github.com/marketplace/actions/cli-for-micr
233332

234333
| Name | Description | |
235334
| -----------------------|------------------------------| ---------|
236-
| `O365_CLI_SCRIPT_PATH` | Relative path to the script | Required |
237-
| `O365_CLI_SCRIPT` | The script to run | Required |
238-
| `IS_POWERSHELL` | Used only with `O365_CLI_SCRIPT`. If `true`, `O365_CLI_SCRIPT` will be passed as a PowerShell script, otherwise the assumption is `bash` script. Default is `false` | Optional |
335+
| `M365_CLI_SCRIPT_PATH` | Relative path to the script | Required |
336+
| `M365_CLI_SCRIPT` | The script to run | Required |
337+
| `IS_POWERSHELL` | Used only with `M365_CLI_SCRIPT`. If `true`, `M365_CLI_SCRIPT` will be passed as a PowerShell script, otherwise the assumption is `bash` script. Default is `false` | Optional |
239338

240339
!!! attention
241-
One of `O365_CLI_SCRIPT_PATH` / `O365_CLI_SCRIPT` is mandatory, in case both are defined `O365_CLI_SCRIPT_PATH` gets preference.
340+
One of `M365_CLI_SCRIPT_PATH` / `M365_CLI_SCRIPT` is mandatory, in case both are defined `M365_CLI_SCRIPT_PATH` gets preference.
242341

243342
## Contributions and Issues
244343

0 commit comments

Comments
 (0)