diff --git a/gallery/script/netlify_build_gallery b/gallery/script/netlify_build_gallery new file mode 100755 index 0000000000..a1d5bb09a9 --- /dev/null +++ b/gallery/script/netlify_build_gallery @@ -0,0 +1,35 @@ +#!/bin/bash + +TARGET_LABEL="Needs gallery preview" + +if [[ "$NETLIFY" != "true" ]]; then + echo "This script can only be run on Netlify" + exit 1 +fi + +function createStatus() { + state="$1" + description="$2" + target_url="$3" + curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/home-assistant/frontend/statuses/$COMMIT_REF" \ + -d '{"state": "'"${state}"'", "context": "Netlify/Gallery Preview Build", "description": "'"$description"'", "target_url": "'"$target_url"'"}' +} + + +if [[ "${PULL_REQUEST}" == "false" ]]; then + gulp build-gallery +else + if [[ "$(curl -sSLf -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/home-assistant/frontend/pulls/${REVIEW_ID}" | jq '.labels[].name' -r)" =~ "$TARGET_LABEL" ]]; then + createStatus "pending" "Building gallery preview" "$DEPLOY_URL" + gulp build-gallery + if [ $? -eq 0 ]; then + createStatus "success" "Build complete" "$DEPLOY_URL" + else + createStatus "error" "Build failed" "$DEPLOY_URL" + fi + else + createStatus "success" "Build was not requested by PR label" + fi +fi