-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for hosting a static site at different places.
- Loading branch information
1 parent
91be308
commit d1c41c5
Showing
18 changed files
with
204 additions
and
101 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
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
src/generators/d2ldev/templates/.github/workflows/publish.yml
This file was deleted.
Oops, something went wrong.
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,84 @@ | ||
import { | ||
copyAndProcessDir, | ||
getDestinationPath, | ||
movePlugin, | ||
replaceTextPlugin | ||
} from '../../helper.js'; | ||
import path from 'path'; | ||
|
||
function genD2ldevReleaseTargetMessage(subdomain) { | ||
return ` to [${subdomain}.d2l.dev](https://${subdomain}.d2l.dev/)`; | ||
} | ||
|
||
function genS3PublishTemplate(roleToAssume, awsRegion, bucketPath) { | ||
// NOTE: Indentation levels in yml files are important and the publish.yml file uses 2 spaces. | ||
return ` | ||
- name: Assume role | ||
if: github.ref == 'refs/heads/main' | ||
uses: Brightspace/third-party-actions@aws-actions/configure-aws-credentials | ||
with: | ||
aws-access-key-id: \${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: \${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-session-token: \${{ secrets.AWS_SESSION_TOKEN }} | ||
role-to-assume: ${roleToAssume} | ||
role-duration-seconds: 3600 | ||
aws-region: ${awsRegion} | ||
- name: Publish | ||
uses: BrightspaceUI/actions/publish-to-s3@main | ||
with: | ||
bucket-path: ${bucketPath} | ||
publish-directory: ./dist/ | ||
`; | ||
} | ||
|
||
export function run(templateData) { | ||
const { | ||
hyphenatedName, | ||
hostingTarget, | ||
roleToAssume, | ||
awsRegion, | ||
bucketPath, | ||
d2ldevSubdomain | ||
} = templateData; | ||
|
||
const templateRoot = path.join(__dirname, 'templates'); | ||
const destinationRoot = getDestinationPath(hyphenatedName); | ||
|
||
const releaseTargetMessage = d2ldevSubdomain | ||
? genD2ldevReleaseTargetMessage(d2ldevSubdomain) | ||
: ''; | ||
const publishStep = hostingTarget === 'other' | ||
? '' | ||
: genS3PublishTemplate(roleToAssume, awsRegion, bucketPath); | ||
const elementFile = `${hyphenatedName}.js`; | ||
|
||
copyAndProcessDir(templateRoot, destinationRoot, [ | ||
movePlugin({ | ||
'_package.json': 'package.json', | ||
'_gitignore': '.gitignore', | ||
'_browserslistrc': '.browserslistrc', | ||
'_CODEOWNERS': 'CODEOWNERS', | ||
'_README.md': 'README.md', | ||
'src/components/_element.js': `src/components/${elementFile}` | ||
}), | ||
replaceTextPlugin({ | ||
'_package.json': templateData, | ||
'_CODEOWNERS': templateData, | ||
'_README.md': { | ||
...templateData, | ||
releaseTargetMessage | ||
}, | ||
'.github/workflows/publish.yml': { | ||
...templateData, | ||
publishStep | ||
}, | ||
'src/index.html': templateData, | ||
'src/index.js': { | ||
...templateData, | ||
elementFile | ||
}, | ||
'src/components/_element.js': templateData, | ||
}) | ||
]); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/generators/static-site/templates/.github/workflows/publish.yml
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,24 @@ | ||
name: Publish | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- '[0-9]+.x' | ||
- '[0-9]+.[0-9]+.x' | ||
jobs: | ||
publish: | ||
name: Publish | ||
runs-on: [self-hosted, AWS, Linux] | ||
timeout-minutes: 10 | ||
steps: | ||
- name: Checkout | ||
uses: Brightspace/third-party-actions@actions/checkout | ||
- name: Setup Node | ||
uses: Brightspace/third-party-actions@actions/setup-node | ||
with: | ||
node-version-file: .nvmrc | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Build | ||
run: npm run build | ||
<%= publishStep %> |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.