diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e3fa041..4c3ca00 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,10 +1,17 @@ name: "build" on: - pull_request: push: + pull_request_target: + branches: [ "main" ] +env: + cloudflare_project: noogle jobs: deploy: runs-on: ubuntu-latest + permissions: + contents: read + deployments: write + pull-requests: write steps: - uses: actions/checkout@v3 - uses: cachix/install-nix-action@v18 @@ -12,9 +19,40 @@ jobs: extra_nix_config: | access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} - run: nix build - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - if: ${{ github.ref == 'refs/heads/main' }} + - name: Publish to Cloudflare Pages + if: github.event_name == 'push' + uses: cloudflare/pages-action@1 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./result/static + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + projectName: ${{ env.cloudflare_project }} + directory: ./result/static + gitHubToken: ${{ secrets.GITHUB_TOKEN }} + - name: Publish to Cloudflare Pages + id: publish + if: github.event_name == 'pull_request_target' + uses: cloudflare/pages-action@1 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + projectName: noogle + directory: ./result/static + gitHubToken: ${{ secrets.GITHUB_TOKEN }} + branch: pr-${{ github.event.pull_request.number }} + - uses: peter-evans/create-or-update-comment@v2 + if: github.event_name == 'pull_request_target' + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + + + + +
Latest commit: + ${{ github.event.pull_request.head.sha }} +
Preview URL: + ${{ steps.publish.outputs.url }} +
Branch Preview URL: + https://pr-${{ github.event.pull_request.number }}.${{ env.cloudflare_project }}.pages.dev +
+ edit-mode: replace