Skip to content

Commit

Permalink
Adds new command 'spfx project github workflow add'. Closes: #5209
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-it authored and waldekmastykarz committed Aug 25, 2023
1 parent 1b96aef commit a07d8f1
Show file tree
Hide file tree
Showing 11 changed files with 595 additions and 3 deletions.
94 changes: 94 additions & 0 deletions docs/docs/cmd/spfx/project/project-github-workflow-add.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import Global from '/docs/cmd/_global.mdx';

# spfx project github workflow add

Adds a GitHub workflow for a SharePoint Framework project

## Usage

```sh
m365 spfx project github workflow add [options]
```

## Options

```md definition-list
`-n, --name [name]`
: Name of the workflow that will be created. If none is specified a default name will be used 'Deploy Solution ${name of sppkg file}'

`-b, --branchName [branchName]`
: Specify the branch name which should trigger the workflow on push. If none is specified a default will be used which is 'main'

`-m, --manuallyTrigger`
: When specified a manual trigger option will be added to the workflow: `workflow_dispatch`

`-l, --loginMethod [loginMethod]`
: Specify the login method used for the login action. Possible options are: `user`, `application`. Default `application`'

`-s, --scope [scope]`
: Scope of the app catalog: `tenant`, `sitecollection`. Default is `tenant`

`-u, --siteUrl [siteUrl]`
: The URL of the site collection where the solution package will be added. Required if scope is set to `sitecollection`

`--skipFeatureDeployment`
: When specified and the app supports tenant-wide deployment, deploy it to the whole tenant

`--overwrite`
: When specified the workflow will overwrite the existing .sppkg if it is already deployed in the app catalog.
```

<Global />

## Remarks

The `spfx project github workflow add` will create a workflow .yml file in the `.github/workflows` directory in your project. If such directory does not exist the command will automatically create it.

For the `application` login method the command does not register AAD application nor create the required certificate. In order for you to proceed you will need to first obtain (create) a self-signed certificate and register a new AAD application with certificate authentication. After that in GitHub repo settings, you will need to create the following secrets:

- `APP_ID` - client id of the registered AAD application
- `CERTIFICATE_ENCODED` - application's encoded certificate
- `CERTIFICATE_PASSWORD` - certificate password. This applies only if the certificate is encoded which is the recommended approach

This use case is perfect in a production context as it does not create any dependencies on an account

For the `user` login method you will need to create the following secrets in GitHub repo settings:

- `ADMIN_USERNAME` - username
- `ADMIN_PASSWORD` - password

This method is perfect to test your workflow, in a dev context, for personal usage. It will not work for accounts with MFA.

:::info

Run this command in the SPFx solution folder.

:::

## Examples

Adds a GitHub workflow for a SharePoint Framework project with `application` login method triggered on push to main

```sh
m365 spfx project github workflow add
```

Adds a GitHub workflow for a SharePoint Framework project with `user` login method triggered on push to main and when manually triggered.

```sh
m365 spfx project github workflow add --manuallyTrigger --loginMethod "user"
```

Adds a GitHub workflow for a SharePoint Framework project with deployment to a site collection app catalog

```sh
m365 spfx project github workflow add --scope "sitecollection" --siteUrl "https://some.sharepoint.com/sites/someSite"
```

## Response

The command won't return a response on success.

## More information

- Automate your CI/CD workflow using CLI for Microsoft 365 GitHub Actions: [https://pnp.github.io/cli-microsoft365/user-guide/github-actions](https://pnp.github.io/cli-microsoft365/user-guide/github-actions)
5 changes: 5 additions & 0 deletions docs/src/config/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,11 @@ const sidebars = {
label: 'project externalize',
id: 'cmd/spfx/project/project-externalize'
},
{
type: 'doc',
label: 'project github workflow add',
id: 'cmd/spfx/project/project-github-workflow-add'
},
{
type: 'doc',
label: 'project permissions grant',
Expand Down
16 changes: 15 additions & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@
"strip-json-comments": "^3.1.1",
"typescript": "^4.9.5",
"update-notifier": "^5.1.0",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"yaml": "^2.3.1"
},
"devDependencies": {
"@microsoft/microsoft-graph-types": "^2.38.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/copy-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ const spfxPackageGenerateCmdDir = 'dist/m365/spfx/commands/package/package-gener
const spfxPackageGenerateAssetsDir = 'dist/m365/spfx/commands/package/package-generate/assets';
mkdirNotExistsSync(spfxPackageGenerateCmdDir);
mkdirNotExistsSync(spfxPackageGenerateAssetsDir);
getFilePaths(spfxPackageGenerateAssetsSourceDir).forEach(file => copyFile(file, spfxPackageGenerateAssetsSourceDir, spfxPackageGenerateAssetsDir));
getFilePaths(spfxPackageGenerateAssetsSourceDir).forEach(file => copyFile(file, spfxPackageGenerateAssetsSourceDir, spfxPackageGenerateAssetsDir));
1 change: 1 addition & 0 deletions src/m365/spfx/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
PACKAGE_GENERATE: `${prefix} package generate`,
PROJECT_DOCTOR: `${prefix} project doctor`,
PROJECT_EXTERNALIZE: `${prefix} project externalize`,
PROJECT_GITHUB_WORKFLOW_ADD: `${prefix} project github workflow add`,
PROJECT_PERMISSIONS_GRANT: `${prefix} project permissions grant`,
PROJECT_RENAME: `${prefix} project rename`,
PROJECT_UPGRADE: `${prefix} project upgrade`
Expand Down
56 changes: 56 additions & 0 deletions src/m365/spfx/commands/project/DeployWorkflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { gitHubWorkflow } from "./project-github-workflow-model";

export const workflow: gitHubWorkflow = {
name: "Deploy Solution {{ name }}",
on: {
push: {
branches: [
"main"
]
}
},
jobs: {
"build-and-deploy": {
"runs-on": "ubuntu-latest",
steps: [
{
name: "Checkout",
uses: "actions/checkout@v3.5.3"
},
{
name: "Use Node.js 16.x",
uses: "actions/setup-node@v3.7.0",
with: {
"node-version": "16.x"
}
},
{
name: "Run npm ci",
run: "npm ci"
},
{
name: "Bundle & Package",
run: "gulp bundle --ship\ngulp package-solution --ship\n"
},
{
name: "CLI for Microsoft 365 Login",
uses: "pnp/action-cli-login@v2.2.2",
with: {
"CERTIFICATE_ENCODED": "${{ secrets.CERTIFICATE_ENCODED }}",
"CERTIFICATE_PASSWORD": "${{ secrets.CERTIFICATE_PASSWORD }}",
"APP_ID": "${{ secrets.APP_ID }}"
}
},
{
name: "CLI for Microsoft 365 Deploy App",
uses: "pnp/action-cli-deploy@v3.0.1",
with: {
"APP_FILE_PATH": "sharepoint/solution/{{ solutionName }}.sppkg",
"SKIP_FEATURE_DEPLOYMENT": false,
"OVERWRITE": false
}
}
]
}
}
};
Loading

0 comments on commit a07d8f1

Please sign in to comment.