Skip to content

Commit b49604c

Browse files
michaelmaillotgarrytrinder
authored andcommitted
Adds CLI_VERSION option. Closes #19
1 parent e8d8be7 commit b49604c

File tree

13 files changed

+193
-39
lines changed

13 files changed

+193
-39
lines changed

.github/workflows/test_version.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
on: [workflow_dispatch]
2+
3+
jobs:
4+
cli_login_version_job:
5+
runs-on: ubuntu-latest
6+
name: CLI Login Job
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v3
10+
- name: CLI for Microsoft 365 Login
11+
uses: ./
12+
id: login
13+
with:
14+
ADMIN_USERNAME: ${{secrets.ADMIN_USERNAME}}
15+
ADMIN_PASSWORD: ${{secrets.ADMIN_PASSWORD}}
16+
CLI_VERSION: 5.7.0-beta.9e8cf99

README.md

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Create a workflow `.yml` file in your `.github/workflows` directory. An [example
1919
- `CERTIFICATE_PASSWORD` : Password for the certificate
2020
- `APP_ID` : App ID of the Azure AD application to use for certificate authentication. If not specified, use the app specified in the 'CLIMICROSOFT365_AADAPPID' environment variable. If the environment variable is not defined, use the multitenant PnP Management Shell app
2121
- `TENANT` : ID of the tenant from which accounts should be able to authenticate. Use `common` or `organization` if the app is multitenant. If not specified, use the tenant specified in the `CLIMICROSOFT365_TENANT` environment variable. If the environment variable is not defined, it will use `common` as the tenant identifier
22+
- `CLI_VERSION` : Accepts `latest`, `next` or a specific version tag. Otherwise, installs the `latest` version when omitted
2223

2324
All inputs are optional. But depending of the authentication type chosen, following pair of inputs will be necessary:
2425

@@ -41,8 +42,8 @@ Since this action requires sensitive information such as user name, password and
4142
- 2 new secrets if using a custom Azure AD identity:
4243
- `APP_ID` - store App ID of the Azure AD application to use for authentication
4344
- `TENANT` - store the ID of the tenant from which accounts should be able to authenticate
44-
45-
These secrets are encrypted and can only be used by GitHub actions.
45+
46+
These secrets are encrypted and can only be used by GitHub actions.
4647

4748
### Example workflow - CLI for Microsoft 365 Login (user name / password authentication)
4849

@@ -58,16 +59,16 @@ jobs:
5859
##
5960
## Build code omitted
6061
##
61-
62+
6263
deploy:
6364
needs: build
6465
runs-on: ubuntu-latest
6566
strategy:
6667
matrix:
6768
node-version: [16.x]
68-
69+
6970
steps:
70-
71+
7172
##
7273
## Code to get the package omitted
7374
##
@@ -78,7 +79,7 @@ jobs:
7879
with:
7980
ADMIN_USERNAME: ${{ secrets.ADMIN_USERNAME }}
8081
ADMIN_PASSWORD: ${{ secrets.ADMIN_PASSWORD }}
81-
82+
8283
##
8384
## Code to deploy the package to tenant omitted
8485
##
@@ -98,16 +99,16 @@ jobs:
9899
##
99100
## Build code omitted
100101
##
101-
102+
102103
deploy:
103104
needs: build
104105
runs-on: ubuntu-latest
105106
strategy:
106107
matrix:
107108
node-version: [16.x]
108-
109+
109110
steps:
110-
111+
111112
##
112113
## Code to get the package omitted
113114
##
@@ -120,18 +121,65 @@ jobs:
120121
APP_ID: ${{ secrets.APP_ID }}
121122
CERTIFICATE_ENCODED: ${{ secrets.CERTIFICATE_ENCODED }}
122123
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
123-
124+
125+
##
126+
## Code to deploy the package to tenant omitted
127+
##
128+
```
129+
130+
### Example workflow - CLI for Microsoft 365 Login (beta version of the CLI)
131+
132+
On every `push` build the code and then login to Microsoft 365 before deploying, using beta version of the CLI.
133+
134+
```yaml
135+
name: SPFx CICD with Cli for Microsoft 365
136+
137+
on: [push]
138+
139+
jobs:
140+
build:
141+
##
142+
## Build code omitted
143+
##
144+
145+
deploy:
146+
needs: build
147+
runs-on: ubuntu-latest
148+
strategy:
149+
matrix:
150+
node-version: [16.x]
151+
152+
steps:
153+
154+
##
155+
## Code to get the package omitted
156+
##
157+
158+
# CLI for Microsoft 365 login action
159+
- name: Login to tenant
160+
uses: pnp/action-cli-login@v2.1.0
161+
with:
162+
TENANT: ${{ secrets.TENANT }}
163+
APP_ID: ${{ secrets.APP_ID }}
164+
CERTIFICATE_ENCODED: ${{ secrets.CERTIFICATE_ENCODED }}
165+
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
166+
CLI_VERSION: next
167+
124168
##
125169
## Code to deploy the package to tenant omitted
126170
##
127171
```
128172

129173
#### Self-hosted runners
130174

131-
If self-hosted runners are used for running the workflow, then please make sure that they have `PowerShell` or `bash` installed on them.
175+
If self-hosted runners are used for running the workflow, then please make sure that they have `PowerShell` or `bash` installed on them.
132176

133177
## Release notes
134178

179+
### v2.2.0
180+
181+
- Adds CLI_VERSION option. Closes #19
182+
135183
### v2.1.0
136184

137185
- Adds certificate login. Closes #12
@@ -142,4 +190,4 @@ If self-hosted runners are used for running the workflow, then please make sure
142190

143191
### v1.0.0
144192

145-
- Added inital 'Office 365 CLI login' GitHub action solving #2
193+
- Added inital 'Office 365 CLI login' GitHub action solving #2

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ inputs:
1919
TENANT:
2020
description: "ID of the tenant from which accounts should be able to authenticate. Use common or organization if the app is multitenant. If not specified, use the tenant specified in the 'CLIMICROSOFT365_TENANT' environment variable. If the environment variable is not defined, use 'common' as the tenant identifier"
2121
required: false
22+
CLI_VERSION:
23+
description: "When specified, installs the requested version or tag of the CLI"
24+
required: false
2225
runs:
2326
using: "node16"
2427
main: "dist/index.js"

dist/index.js

Lines changed: 24 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pnp/action-cli-login",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "GitHub Action to Login to a tenant using CLI for Microsoft 365",
55
"license": "MIT",
66
"main": "lib/main.js",

src/commands.spec.ts

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as assert from 'assert';
2-
import { getLoginCommand, } from './commands';
2+
import { getInstallCommand, getLoginCommand, } from './commands';
3+
import { constants } from './constants';
34
import { Options } from './validate';
45

56
describe('commands', () => {
@@ -13,7 +14,8 @@ describe('commands', () => {
1314
CERTIFICATE_ENCODED: '',
1415
CERTIFICATE_PASSWORD: '',
1516
APP_ID: '',
16-
TENANT: ''
17+
TENANT: '',
18+
CLI_VERSION: ''
1719
};
1820
const expected = 'login --authType password --userName adminUsername --password adminPassword';
1921
const actual = getLoginCommand(options);
@@ -27,7 +29,8 @@ describe('commands', () => {
2729
CERTIFICATE_ENCODED: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
2830
CERTIFICATE_PASSWORD: '',
2931
APP_ID: '36e3a540-6f25-4483-9542-9f5fa00bb633',
30-
TENANT: '187d6ed4-5c94-40eb-87c7-d311ec5f647a'
32+
TENANT: '187d6ed4-5c94-40eb-87c7-d311ec5f647a',
33+
CLI_VERSION: ''
3134
};
3235
const expected = 'login --authType certificate --certificateBase64Encoded ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 --appId 36e3a540-6f25-4483-9542-9f5fa00bb633 --tenant 187d6ed4-5c94-40eb-87c7-d311ec5f647a';
3336
const actual = getLoginCommand(options);
@@ -41,7 +44,8 @@ describe('commands', () => {
4144
CERTIFICATE_ENCODED: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
4245
CERTIFICATE_PASSWORD: 'Pass@w0rd!',
4346
APP_ID: '36e3a540-6f25-4483-9542-9f5fa00bb633',
44-
TENANT: '187d6ed4-5c94-40eb-87c7-d311ec5f647a'
47+
TENANT: '187d6ed4-5c94-40eb-87c7-d311ec5f647a',
48+
CLI_VERSION: ''
4549
};
4650
const expected = 'login --authType certificate --certificateBase64Encoded ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 --password Pass@w0rd! --appId 36e3a540-6f25-4483-9542-9f5fa00bb633 --tenant 187d6ed4-5c94-40eb-87c7-d311ec5f647a';
4751
const actual = getLoginCommand(options);
@@ -55,7 +59,8 @@ describe('commands', () => {
5559
CERTIFICATE_ENCODED: '',
5660
CERTIFICATE_PASSWORD: '',
5761
APP_ID: '',
58-
TENANT: ''
62+
TENANT: '',
63+
CLI_VERSION: ''
5964
};
6065
assert.throws(() => getLoginCommand(options), Error, 'ADMIN_USERNAME is required');
6166
});
@@ -67,7 +72,8 @@ describe('commands', () => {
6772
CERTIFICATE_ENCODED: '',
6873
CERTIFICATE_PASSWORD: '',
6974
APP_ID: '',
70-
TENANT: ''
75+
TENANT: '',
76+
CLI_VERSION: ''
7177
};
7278
assert.throws(() => getLoginCommand(options), Error, 'ADMIN_PASSWORD is required');
7379
});
@@ -79,7 +85,8 @@ describe('commands', () => {
7985
CERTIFICATE_ENCODED: '',
8086
CERTIFICATE_PASSWORD: '',
8187
APP_ID: '',
82-
TENANT: ''
88+
TENANT: '',
89+
CLI_VERSION: ''
8390
};
8491
assert.doesNotThrow(() => getLoginCommand(options), Error);
8592
});
@@ -91,7 +98,8 @@ describe('commands', () => {
9198
CERTIFICATE_ENCODED: '',
9299
CERTIFICATE_PASSWORD: '',
93100
APP_ID: '',
94-
TENANT: ''
101+
TENANT: '',
102+
CLI_VERSION: ''
95103
};
96104
assert.throws(() => getLoginCommand(options), Error, 'CERTIFICATE_ENCODED is required if ADMIN_USERNAME and ADMIN_PASSWORD are not provided');
97105
});
@@ -103,10 +111,42 @@ describe('commands', () => {
103111
CERTIFICATE_ENCODED: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
104112
CERTIFICATE_PASSWORD: '',
105113
APP_ID: '',
106-
TENANT: ''
114+
TENANT: '',
115+
CLI_VERSION: ''
107116
};
108117
assert.doesNotThrow(() => getLoginCommand(options), Error);
109118
});
110119
});
111120

121+
describe('getInstallCommand', () => {
122+
it('returns correct install command (latest version of the CLI)', () => {
123+
const options: Options = {
124+
ADMIN_USERNAME: 'adminUsername',
125+
ADMIN_PASSWORD: 'adminPassword',
126+
CERTIFICATE_ENCODED: '',
127+
CERTIFICATE_PASSWORD: '',
128+
APP_ID: '',
129+
TENANT: '',
130+
CLI_VERSION: ''
131+
};
132+
const expected = constants.CLI_NPMINSTALL_COMMAND;
133+
const actual = getInstallCommand(options);
134+
assert.equal(actual, expected);
135+
});
136+
137+
it('returns correct install command (specific version of the CLI)', () => {
138+
const options: Options = {
139+
ADMIN_USERNAME: 'adminUsername',
140+
ADMIN_PASSWORD: 'adminPassword',
141+
CERTIFICATE_ENCODED: '',
142+
CERTIFICATE_PASSWORD: '',
143+
APP_ID: '',
144+
TENANT: '',
145+
CLI_VERSION: '5.4.0'
146+
};
147+
const expected = `${constants.CLI_NPMINSTALL_COMMAND}@${options.CLI_VERSION}`;
148+
const actual = getInstallCommand(options);
149+
assert.equal(actual, expected);
150+
});
151+
});
112152
});

src/commands.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { constants } from './constants';
12
import { isNullOrEmpty } from './utils';
23
import { Options } from './validate';
34

@@ -29,4 +30,17 @@ export function getLoginCommand(options: Options): string {
2930
}
3031

3132
return authCommand;
33+
}
34+
35+
export function getInstallCommand(options: Options): string {
36+
let installCommand: string;
37+
38+
if (options.CLI_VERSION) {
39+
installCommand = `${constants.CLI_NPMINSTALL_COMMAND}@${options.CLI_VERSION}`;
40+
}
41+
else {
42+
installCommand = constants.CLI_NPMINSTALL_COMMAND;
43+
}
44+
45+
return installCommand;
3246
}

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export const constants = {
77
ACTION_CERTIFICATE_PASSWORD: 'CERTIFICATE_PASSWORD',
88
ACTION_APP_ID: 'APP_ID',
99
ACTION_TENANT: 'TENANT',
10+
ACTION_CLI_VERSION: 'CLI_VERSION',
1011
}

0 commit comments

Comments
 (0)