-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(toolkit-lib): publish toolkit-lib docs to s3 (in dryrun) #114
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,118 @@ | ||
import { Monorepo, TypeScriptWorkspace } from 'cdklabs-projen-project-types/lib/yarn'; | ||
import { Component, github } from 'projen'; | ||
|
||
export interface S3DocsPublishingProps { | ||
/** | ||
* The docs stream to publish to. | ||
*/ | ||
readonly docsStream: string; | ||
|
||
/** | ||
* The path to the artifact in the dist folder | ||
*/ | ||
readonly artifactPath: string; | ||
|
||
/** | ||
* The role arn (or github expression) for OIDC to assume to do the actual publishing. | ||
*/ | ||
readonly roleToAssume: string; | ||
|
||
/** | ||
* The bucket name (or github expression) to publish to. | ||
*/ | ||
readonly bucketName: string; | ||
} | ||
|
||
export class S3DocsPublishing extends Component { | ||
private readonly github: github.GitHub; | ||
private readonly props: S3DocsPublishingProps; | ||
|
||
constructor(project: TypeScriptWorkspace, props: S3DocsPublishingProps) { | ||
super(project); | ||
|
||
const gh = (project.parent! as Monorepo).github; | ||
if (!gh) { | ||
throw new Error('This workspace does not have a GitHub instance'); | ||
} | ||
this.github = gh; | ||
|
||
this.props = props; | ||
} | ||
|
||
public preSynthesize() { | ||
const releaseWf = this.github.tryFindWorkflow('release'); | ||
if (!releaseWf) { | ||
throw new Error('Could not find release workflow'); | ||
} | ||
|
||
const safeName = this.project.name.replace('@', '').replace('/', '-'); | ||
|
||
releaseWf.addJob(`${safeName}_release_docs`, { | ||
name: `${this.project.name}: Publish docs to S3`, | ||
environment: 'releasing', // <-- this has the configuration | ||
needs: [`${safeName}_release_npm`], | ||
runsOn: ['ubuntu-latest'], | ||
permissions: { | ||
idToken: github.workflows.JobPermission.WRITE, | ||
contents: github.workflows.JobPermission.READ, | ||
}, | ||
steps: [ | ||
{ | ||
name: 'Download build artifacts', | ||
uses: 'actions/download-artifact@v4', | ||
with: { | ||
name: `${this.project.name}_build-artifact`, | ||
path: 'dist', | ||
}, | ||
}, | ||
{ | ||
name: 'Authenticate Via OIDC Role', | ||
id: 'creds', | ||
uses: 'aws-actions/configure-aws-credentials@v4', | ||
with: { | ||
'aws-region': 'us-east-1', | ||
'role-duration-seconds': 14400, | ||
'role-to-assume': '${{ vars.AWS_ROLE_TO_ASSUME_FOR_ACCOUNT }}', | ||
'role-session-name': 'releasing@aws-cdk-cli', | ||
}, | ||
}, | ||
{ | ||
name: 'Assume the publishing role', | ||
id: 'publishing-creds', | ||
uses: 'aws-actions/configure-aws-credentials@v4', | ||
with: { | ||
'aws-region': 'us-east-1', | ||
'role-duration-seconds': 14400, | ||
'role-to-assume': this.props.roleToAssume, | ||
'role-session-name': 's3publishing@aws-cdk-cli', | ||
'role-chaining': true, | ||
}, | ||
}, | ||
{ | ||
name: 'Publish docs', | ||
env: { | ||
BUCKET_NAME: this.props.bucketName, | ||
DOCS_STREAM: this.props.docsStream, | ||
}, | ||
run: [ | ||
'::add-mask::$BUCKET_NAME', // always hide bucket name | ||
|
||
// setup paths | ||
`echo "S3_PATH=$DOCS_STREAM/${safeName}-v$(cat dist/version.txt).zip" >> "$GITHUB_ENV"`, | ||
'echo "S3_URI=s3://$BUCKET_NAME/$S3_PATH" >> "$GITHUB_ENV"', | ||
`echo "LATEST=latest-${this.props.docsStream}" >> "$GITHUB_ENV"`, | ||
|
||
// create the latest marker | ||
'echo $S3_PATH > $LATEST', | ||
|
||
// check if the target file already exists and upload | ||
'(! aws s3 ls --human-readable $S3_URI \\', | ||
`&& aws s3 cp --dryrun dist/${this.props.artifactPath} $S3_URI \\`, | ||
'&& aws s3 cp --dryrun $LATEST s3://$BUCKET_NAME/$LATEST) \\', | ||
'|| (echo "Docs artifact already published, skipping upload")', | ||
].join('\n'), | ||
}, | ||
], | ||
}); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--dryrun
for now to check everything is working