Skip to content

New command: spfx project github workflow add #5209

@Adam-it

Description

@Adam-it

Usage

m365 spfx project github workflow add [options]

Description

Adds a GitHub workflow for a SharePoint Framework project.

Options

Option Description
-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] cope of the app catalog: tenant, sitecollection. Default is tenant
--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 set to overwrite the existing package file.

Examples

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

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.

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

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

Default properties

none

Additional Info

Remarks

When loginMethod option is used with user value then the CLI for Microsoft 365 login action will be created with ADMIN_USERNAME and ADMIN_PASSWORD. If the application value will be used then the action will created with CERTIFICATE_ENCODED, CERTIFICATE_PASSWORD, APP_ID.

Example workflow

This is an example workflow that should be generated (without the comments 😉)

name: Deploy Solution # {{SOLUTION_NAME}} # default title of flow with possibility to change it with an option in the command

on:
  push:
    branches:
      - main # optionally specify name of the branch which should trigger the flow by specifying an option in the command. by default it is main
  workflow_dispatch: # specify that the flow can be triggered manually by specifying a flag in the command

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    
    steps:

    - name: Checkout
      uses: actions/[email protected]
      
    - name: Use Node.js 16.x
      uses: actions/[email protected]
      with:
        node-version: 16.x
    
    - name: Run npm ci
      run: npm ci
    
    - name: Bundle & Package
      run: |
        gulp bundle --ship
        gulp package-solution --ship
    
    - name: CLI for Microsoft 365 Login
      uses: pnp/[email protected]
      with:
        #ADMIN_USERNAME:  ${{ secrets.ADMIN_USERNAME }} # this will be used when `user` method is specified
        #ADMIN_PASSWORD:  ${{ secrets.ADMIN_PASSWORD }} # this will be used when `user` method is specified
        CERTIFICATE_ENCODED: ${{ secrets.CERTIFICATE_ENCODED }} # this will be used when `application` method is specified
        CERTIFICATE_PASSWORD: # this will be used when `application` method is specified
        APP_ID: ${{ secrets.APP_ID }} # this will be used when `application` method is specified
    
    - name: CLI for Microsoft 365 Deploy App
      uses: pnp/[email protected]
      with:
        APP_FILE_PATH: sharepoint/solution/{{ solutionName }}.sppkg # should be automatically populated based on the project
        #SCOPE: # Scope of the app catalog: tenant or sitecollection. Default is tenant by specifying an option in the command
        #SITE_COLLECTION_URL: # The URL of the site collection where the solution package will be added. Required if scope is set to sitecollection by specifying an option in the command
        SKIP_FEATURE_DEPLOYMENT: false # If the app supports tenant-wide deployment, deploy it to the whole tenant by specifying an option in the command. Default is false
        OVERWRITE: true # Set to overwrite the existing package file by specifying an option in the command. Default is false
...

Implementation idea

How I would go about it is maybe keep a .yml file as part of the project in the command folder and just adjust it based on the options passed. We could have some markers inside the template .yml file and just use plain replace based on what was specified

File

The command (like other spfx commands) should work within and SPFx project directory. On the root level of the SPFx project (so the same directory where package.json is present) the command should create a file with name deploy.yml and it should be created in .github/workflow/ subdirectories (the command should create those folders if not present).
When a file with the same name already exist the command should present an error message.

Some other ideas

👉 I wasn't sure if it will be useful but CLI for Microsoft 365 actions also support specifying a CLI version that will be used and we may specify latest, next or a specific version tag.
👉 Also not sure if giving the possibility to specify a specific node version that will be used might be helpful. The latest version of SPFx supports v16.x but maybe someone would like to create a workflow for an older version of SPFx 🤔
👉 Another idea for an option would be if the bundle and package should be with --ship o not. Maybe someone would like a workflow that deploys a SPFx app for debugging

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions