-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from cncsc/feature/sharepoint-deployment
Add SharePoint deployment workflow
- Loading branch information
Showing
6 changed files
with
2,165 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Deploy to SharePoint | ||
on: | ||
workflow_call: | ||
inputs: | ||
siteUrl: | ||
description: The URL of the site to which the files will be deployed. | ||
required: true | ||
type: string | ||
documentLibraryName: | ||
description: The name of the document library to which the files will be deployed. | ||
required: true | ||
type: string | ||
basePath: | ||
description: The base path within the document library where files will be deployed. | ||
required: true | ||
type: string | ||
default: '/' | ||
distPath: | ||
description: The path to the build output. | ||
required: true | ||
type: string | ||
default: './dist/' | ||
runDefaultBuild: | ||
description: Whether or not to run the build script from the project's package.json file. | ||
required: false | ||
type: boolean | ||
default: true | ||
secrets: | ||
SHAREPOINT_CLIENT_ID: | ||
required: true | ||
SHAREPOINT_CLIENT_SECRET: | ||
required: false | ||
GIT_TOKEN_BASIC: | ||
required: false | ||
jobs: | ||
deploy-to-sharepoint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
token: ${{ secrets.GIT_TOKEN_BASIC || github.token }} | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: lts/* | ||
- name: Install node dependencies | ||
run: npm ci | ||
shell: bash | ||
- name: Run default build | ||
if: inputs.runDefaultBuild == true | ||
run: npm run build | ||
shell: bash | ||
- uses: actions/checkout@v3 | ||
with: | ||
repository: cncsc/actions | ||
path: ./.actions/ | ||
- name: Install Node dependencies | ||
working-directory: ./.actions/scripts/deployment/deploy-files-to-sharepoint/ | ||
run: npm ci | ||
shell: bash | ||
- name: Deploy files to SharePoint | ||
run: node ./.actions/scripts/deployment/deploy-files-to-sharepoint/deploy-files-to-sharepoint.js "${{ inputs.siteUrl }}" "${{ inputs.documentLibraryName }}" "${{ inputs.distPath }}" "${{ inputs.basePath }}" | ||
shell: bash | ||
env: | ||
SHAREPOINT_CLIENT_ID: ${{ secrets.SHAREPOINT_CLIENT_ID }} | ||
SHAREPOINT_CLIENT_SECRET: ${{ secrets.SHAREPOINT_CLIENT_SECRET }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
scripts/deployment/deploy-files-to-sharepoint/deploy-files-to-sharepoint.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env node | ||
|
||
const path = require('path'); | ||
const fs = require('fs').promises; | ||
const { spsave } = require('spsave'); | ||
|
||
async function main() { | ||
const coreOptions = { | ||
siteUrl: process.argv[2], | ||
}; | ||
|
||
const credentialOptions = { | ||
clientId: process.env.SHAREPOINT_CLIENT_ID, | ||
clientSecret: process.env.SHAREPOINT_CLIENT_SECRET, | ||
}; | ||
|
||
const basePath = process.argv[4]; | ||
|
||
async function pushFile(filePath, fileName, fileContent) { | ||
await spsave(coreOptions, credentialOptions, { | ||
filePath: filePath.replace(new RegExp(`^${ basePath }/`), ''), | ||
fileName, | ||
fileContent | ||
}); | ||
} | ||
|
||
async function processDir(dirPath) { | ||
const entities = await fs.readdir(dirPath); | ||
for (const entity of entities) { | ||
const entityFullPath = path.join(dirPath, entity); | ||
const stat = await fs.stat(entityFullPath); | ||
|
||
if (stat.isDirectory()) { | ||
await processDir(entityFullPath); | ||
continue; | ||
} | ||
|
||
const fileContent = await fs.readFile(entityFullPath); | ||
await pushFile(dirPath, entity, fileContent); | ||
} | ||
} | ||
|
||
await processDir(basePath); | ||
} | ||
|
||
main().then(() => { | ||
console.log('Successfully uploaded files to SharePoint.'); | ||
process.exit(0); | ||
}, (e) => { | ||
console.error('An error occurred while uploading files to SharePoint:'); | ||
console.error(e); | ||
process.exit(-1); | ||
}); |
Oops, something went wrong.