samhstn/website

Simpler and better reference to CodeBuild badge

Closed this issue · 0 comments

We currently have this file: https://s3.amazonaws.com/codefactory-us-east-1-prod-default-build-badges/unknown.svg in our source code as static/repo/samhstn/badge.svg and added it to s3 - it isn't clear where this file came from and we have cluttered our static directory.

We should instead not include this svg in our source code and download it using curl if required.

The buildspec should instead run something like the following:

aws s3 sync static s3://samhstn.com --delete --exclude badge
CODEBUILD_BADGE_URL=$(\
  aws codebuild batch-get-projects \
    --name CodeBuild \
    --query "projects[0].badge.badgeRequestUrl" \
    --output text \
)
if aws s3 ls s3://samhstn.com/badge.svg || \
  [ $(\
    aws s3api head-object \
      --bucket samhstn.com \
      --key repo/samhstn/badge.svga \
      --query "Metadata.\"website-redirect-location\"" \
      --output text\
    ) != $CODEBUILD_BADGE ];then

  curl https://s3.amazonaws.com/codefactory-us-east-1-prod-default-build-badges/unknown.svg > ./badge.svg
  aws s3 cp ./badge.svg s3://samhstn.com/badge.svg --metadata "Website-Redirect-Location=$CODEBUILD_BADGE"