Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions .github/workflows/release.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 23 additions & 14 deletions projenrc/s3-docs-publishing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,32 @@ export class S3DocsPublishing extends Component {
BUCKET_NAME: this.props.bucketName,
DOCS_STREAM: this.props.docsStream,
},
run: [
'echo ::add-mask::$BUCKET_NAME', // always hide bucket name
run: `echo "Uploading docs to S3"
echo "::add-mask::$BUCKET_NAME"
S3_PATH="$DOCS_STREAM/${safeName}-v$(cat dist/version.txt).zip"
LATEST="latest-${this.props.docsStream}"

// 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"`,
# Capture both stdout and stderr
if OUTPUT=$(aws s3api put-object \\
--bucket "$BUCKET_NAME" \\
--key "$S3_PATH" \\
--body dist/${this.props.artifactPath} \\
--if-none-match "*" 2>&1); then

# File was uploaded successfully, update the latest pointer
echo "New docs artifact uploaded successfully, updating latest pointer"
echo "$S3_PATH" | aws s3 cp - "s3://$BUCKET_NAME/$LATEST"

// create the latest marker
'echo "$S3_PATH" > "$LATEST"',
elif echo "$OUTPUT" | grep -q "PreconditionFailed"; then
# Check specifically for PreconditionFailed in the error output
echo "::warning::File already exists in S3. Skipping upload."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only reason for PreconditionFailed? Is it possible to be even more specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my understanding this is the only possible precondition because the precondition is only created by the --if-none-match option. So that's what we want.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, cool :)

exit 0

// 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'),
else
# Any other error (permissions, etc)
echo "::error::Failed to upload docs artifact"
exit 1
fi`,
},
],
});
Expand Down
Loading