diff --git a/.github/workflows/design_preview.yaml b/.github/workflows/design_preview.yaml new file mode 100644 index 0000000000..a209613620 --- /dev/null +++ b/.github/workflows/design_preview.yaml @@ -0,0 +1,52 @@ +name: Design preview + +on: + pull_request: + types: + - opened + - synchronize + - reopened + - labeled + branches: + - dev + +env: + NODE_VERSION: 16 + NODE_OPTIONS: --max_old_space_size=6144 + +jobs: + preview: + runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'needs design preview') + steps: + - name: Check out files from GitHub + uses: actions/checkout@v3 + + - name: Set up Node ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: yarn + + - name: Install dependencies + run: yarn install + env: + CI: true + + - name: Build Gallery + run: ./node_modules/.bin/gulp build-gallery + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Deploy preview to Netlify + id: deploy + uses: netlify/actions/cli@master + with: + args: deploy --dir=gallery/dist --alias "deploy-preview-${{ github.event.number }}" + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_GALLERY_SITE_ID }} + + - name: Generate summary + run: | + echo "${{ steps.deploy.outputs.NETLIFY_LIVE_URL || steps.deploy.outputs.NETLIFY_URL }}" >> "$GITHUB_STEP_SUMMARY" diff --git a/gallery/script/netlify_build_gallery b/gallery/script/netlify_build_gallery deleted file mode 100755 index 97c95ebf2a..0000000000 --- a/gallery/script/netlify_build_gallery +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -TARGET_LABEL="needs design preview" -export SKIP_FETCH_NIGHTLY_TRANSLATIONS="true" - -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/Design Preview Build", "description": "'"$description"'", "target_url": "'"$target_url"'"}' -} - - -if [[ "${PULL_REQUEST}" == "true" ]]; then - 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 design preview" "https://app.netlify.com/sites/home-assistant-gallery/deploys/$BUILD_ID" - gulp build-gallery - if [ $? -eq 0 ]; then - createStatus "success" "Build complete" "$DEPLOY_PRIME_URL" - else - createStatus "error" "Build failed" "https://app.netlify.com/sites/home-assistant-gallery/deploys/$BUILD_ID" - fi - else - createStatus "success" "Build was not requested by PR label" - fi -fi