Skip to content

Commit

Permalink
Merge pull request #1 from cncsc/feature/sharepoint-deployment
Browse files Browse the repository at this point in the history
Add SharePoint deployment workflow
  • Loading branch information
lukiffer authored Feb 20, 2023
2 parents e68b71b + dbd024c commit 5a8d414
Show file tree
Hide file tree
Showing 6 changed files with 2,165 additions and 2 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/deploy-to-sharepoint.yaml
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 }}
2 changes: 1 addition & 1 deletion .github/workflows/semantic-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
token: ${{ secrets.GIT_TOKEN_BASIC || github.token }}
- uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: lts/*
- name: Install node dependencies
run: npm ci
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: lts/*

- name: Install node dependencies
run: npm ci
Expand Down
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 5a8d414

Please sign in to comment.