diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0f7c98db..a3ef17a9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,6 +1,9 @@ # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json name: Deploy to GitHub Pages +# Preview PRs via actions/deploy-pages is not available so using JamesIves/github-pages-deploy-action +# https://github.com/orgs/community/discussions/7730 + on: push: tags: @@ -50,20 +53,15 @@ jobs: npm run build touch build/.nojekyll - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@881db5376404c5c8d621010bcbec0310b58d5e29 with: - path: ./build - - # Deployment job - deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: build + folder: build + clean: true + clean-exclude: | + _pr/** + commit-message: Deploy to GitHub Pages - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 + - name: Update Job Summary + run: | + echo "๐Ÿš€ [https://www.frequency.xyz](https://www.frequency.xyz)" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/pr-close.yml b/.github/workflows/pr-close.yml new file mode 100644 index 00000000..4c18118d --- /dev/null +++ b/.github/workflows/pr-close.yml @@ -0,0 +1,42 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json +name: Remove PR Deploy Preview + +on: + pull_request: + types: [closed] + +permissions: + contents: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: 'deploy-pages' + cancel-in-progress: false + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: gh-pages + + - name: Remove PR preview + run: | + PR_NUMBER=${{ github.event.pull_request.number }} + if [ -d "_pr/$PR_NUMBER" ]; then + git config user.name github-actions + git config user.email github-actions@github.com + git rm -rf "_pr/$PR_NUMBER" + git commit -m "Remove PR preview for #$PR_NUMBER" + git push + else + echo "Preview folder for PR #$PR_NUMBER does not exist. Skipping cleanup." + fi + + - name: Update Job Summary + run: | + echo "## Cleanup Summary" >> $GITHUB_STEP_SUMMARY + echo "๐Ÿงน Removed preview for PR #${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/pr-deploy.yml b/.github/workflows/pr-deploy.yml new file mode 100644 index 00000000..6898a68f --- /dev/null +++ b/.github/workflows/pr-deploy.yml @@ -0,0 +1,95 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json +name: PR Deploy Preview + +# Preview PRs via actions/deploy-pages is not available so using JamesIves/github-pages-deploy-action +# https://github.com/orgs/community/discussions/7730 + +on: + pull_request: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pull-requests: write + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: 'deploy-pages' + cancel-in-progress: false + +jobs: + deploy-preview: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - name: Install dependencies + run: npm install + + - name: Build + env: + # Deploying to a root domain + BASE_PATH: _pr/${{ github.event.pull_request.number }} + run: | + npm run build + touch build/.nojekyll + + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@881db5376404c5c8d621010bcbec0310b58d5e29 + with: + folder: build + target-folder: _pr/${{ github.event.pull_request.number }} + + - name: Update Job Summary + run: | + echo "## Preview URL" >> $GITHUB_STEP_SUMMARY + echo "๐Ÿš€ [https://www.frequency.xyz/_pr/${{ github.event.pull_request.number }}](https://www.frequency.xyz/_pr/${{ github.event.pull_request.number }})" >> $GITHUB_STEP_SUMMARY + + - name: Comment PR + uses: actions/github-script@v6 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const prNumber = context.issue.number; + const sha = context.sha; + const deploymentUrl = `https://www.frequency.xyz/_pr/${prNumber}/`; + const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${sha}`; + const body = `๐Ÿš€ Preview deployment for this PR is ready!\n\nPreview URL: [${deploymentUrl}](${deploymentUrl})\nCommit: [${sha.substr(0, 7)}](${commitUrl})`; + + const comments = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + }); + + const existingComment = comments.data.find(comment => + comment.user.login === 'github-actions[bot]' && + comment.body.includes('Preview deployment for this PR is ready!') + ); + + if (existingComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existingComment.id, + body: body, + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: body, + }); + } diff --git a/static/robots.txt b/static/robots.txt new file mode 100644 index 00000000..12595cf5 --- /dev/null +++ b/static/robots.txt @@ -0,0 +1,3 @@ +User-agent: * +Disallow: +Disallow: /_pr/