Files
hls.js/scripts/deploy-cloudflare.sh
T
Tom Jenkinson 489e9419ce Switch from netlify to CloudFlare Pages (#5305)
* add a script that will deploy the `netlify` dir to cloudflare pages

* switch everything from netlify over to cf pages

* fix wrangler version

* add `/` to api-docs url

* fix name of cloudflare dev project
2023-03-17 16:07:30 +00:00

46 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
set -e
# GITHUB_TOKEN and CLOUDFLARE_API_TOKEN required
accountId="8c9d432e3647d63cd0953ca4a26e02ed"
stableProjectName="hlsjs"
latestProjectName="hlsjs-dev"
currentCommit=$(git rev-parse HEAD)
root="./cloudflare-pages"
version="$(jq -r -e '.version' "./package.json")"
idShort="$(echo "$currentCommit" | cut -c 1-8) ($version)"
deploy () {
projectName=$1
echo "Deploying on CloudFlare to '$projectName'."
./node_modules/.bin/wrangler pages publish --project-name "$projectName" --commit-dirty=true --branch=master --commit-hash="$currentCommit" $root
echo "Deployed on CloudFlare to '$projectName'."
}
deploy "$latestProjectName"
if [[ $version != *"-"* ]]; then
echo "Detected new version: $version"
deploy "$stableProjectName"
fi
echo "Finished deploying to CloudFlare."
echo "Fetching deployment urls."
deploymentUrl=`curl -X GET --fail "https://api.cloudflare.com/client/v4/accounts/$accountId/pages/projects/$latestProjectName/deployments" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type:application/json" | jq --raw-output --exit-status '[.result[] | select(.deployment_trigger.metadata.commit_hash == "'"$currentCommit"'")][0].url'`
echo "Updating deployments branch."
git clone --depth 1 "https://${GITHUB_TOKEN}@github.com/video-dev/hls.js.git" -b deployments "$root/deployments"
cd "$root/deployments"
echo "- [\`$idShort\`](https://github.com/video-dev/hls.js/commit/$currentCommit): [$deploymentUrl/]($deploymentUrl/)" >> "README.md"
git add "README.md"
git -c user.name="hlsjs-ci" -c user.email="40664919+hlsjs-ci@users.noreply.github.com" commit -m "update for $id"
git push "https://${GITHUB_TOKEN}@github.com/video-dev/hls.js.git"
cd ..
echo "Updated deployments branch."