Skip to content

Commit

Permalink
upload parsons to cdn on release (#11)
Browse files Browse the repository at this point in the history
* upload parsons to cdn on release

* fixed permissions

* fixed folder path

* fixed folder path
  • Loading branch information
mloginov authored Jan 24, 2024
1 parent 7872edf commit cec2652
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish New Release
on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Upload to s3
run: ./uploadToS3.sh "${{ secrets.ASSETS_UPLOADER_KEY }}" "${{ secrets.ASSETS_UPLOADER_SECRET }}" "${{ github.event.release.tag_name }}"

- name: Slack
uses: codio/codio-slack-action@master
if: always()
with:
slack_hook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
message: "<https://github.com/${{ github.repository }}/actions/runs/${{github.run_id}}|${{ github.workflow }} release> for ${{ github.repository }} by ${{ github.actor }} has ${{ job.status }} on branch ${{ github.ref_name }}"
success: ${{ job.status }}
71 changes: 71 additions & 0 deletions uploadToS3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash
set -xe

joinByChar() {
local IFS="$1"
shift
echo "$*"
}

s3Key=$1
s3Secret=$2
tag=$3
folderArr=("guides" "parsons")
folder=$(joinByChar "/", "${folderArr[@]}")
folderEscaped=$(joinByChar "\/", "${folderArr[@]}")
cdn="\/\/static-assets.codio.com\/${folder}\/${tag}"

echo "$cdn"

readarray -d '' files < <(find ./lib -type f -print0)

getContentType () {
filename=$1
extension=${filename##*.}
contentType="application/octet-stream"

case $extension in
"html" | "css")
contentType="text/${extension}"
;;
"js")
contentType="application/javascript"
;;
"png" | "jpg" | "gif")
contentType="image/${extension}"
;;
"svg")
contentType="image/svg+xml"
;;
"ttf" | "woff" | "woff2")
contentType="font/${extension}"
;;
esac
echo "$contentType"
}

uploadFile () {
file=$1
fName="${file#./}"
contentType=$2
bucket="codio-assets"
resource="/${bucket}/${folder}/${tag}/${fName}"
dateValue=$(date -R)
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
signature=$(echo -en "${stringToSign}" | openssl sha1 -hmac "${s3Secret}" -binary | base64)
curl -X PUT -T "${file}" \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${bucket}.s3.amazonaws.com/"${folder}"/"${tag}"/"${fName}" || exit 1
}

for file in "${files[@]}"
do
contentType=$(getContentType "$file")
uploadFile "$file" "$contentType"
done

uploadFile "parsons.js" "$(getContentType "parsons.js")"
uploadFile "parsons.css" "$(getContentType "parsons.css")"

0 comments on commit cec2652

Please sign in to comment.