From cec265263893b0e4e8d3aa7dfe8fbc498635ee49 Mon Sep 17 00:00:00 2001 From: mloginov Date: Wed, 24 Jan 2024 11:03:03 +0000 Subject: [PATCH] upload parsons to cdn on release (#11) * upload parsons to cdn on release * fixed permissions * fixed folder path * fixed folder path --- .github/workflows/release.yaml | 22 +++++++++++ uploadToS3.sh | 71 ++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 .github/workflows/release.yaml create mode 100755 uploadToS3.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..f78fc72 --- /dev/null +++ b/.github/workflows/release.yaml @@ -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: " for ${{ github.repository }} by ${{ github.actor }} has ${{ job.status }} on branch ${{ github.ref_name }}" + success: ${{ job.status }} diff --git a/uploadToS3.sh b/uploadToS3.sh new file mode 100755 index 0000000..8c068bf --- /dev/null +++ b/uploadToS3.sh @@ -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")"