Skip to content

Commit

Permalink
Add SharePoint deployment workflow (patch)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukiffer committed Feb 20, 2023
1 parent 95ba71f commit dbd024c
Show file tree
Hide file tree
Showing 5 changed files with 2,102 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/deploy-to-sharepoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ jobs:
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.js
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 }}
Expand Down
Empty file.
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);
});
Loading

0 comments on commit dbd024c

Please sign in to comment.