diff --git a/.github/workflows/build-preview.yml b/.github/workflows/build-preview.yml new file mode 100644 index 00000000..21f2ea66 --- /dev/null +++ b/.github/workflows/build-preview.yml @@ -0,0 +1,32 @@ +name: "Build Preview Deployment" + +on: + pull_request: + types: [opened, synchronize] + +jobs: + build-preview: + runs-on: "ubuntu-latest" + name: "Build Preview Site and Upload Build Artifact" + steps: + - name: "checkout" + uses: "actions/checkout@v4" + with: + fetch-depth: 0 + - name: "setup pnpm" + uses: "pnpm/action-setup@v4" + - name: "setup node" + uses: "actions/setup-node@v4" + with: + cache: "pnpm" + node-version: 20 + - name: "install dependencies" + run: "pnpm install" + - name: "build" + run: "pnpm run build" + # Uploads the build directory as a workflow artifact + - name: "upload build artifact" + uses: "actions/upload-artifact@v4" + with: + name: "preview-build" + path: "build" diff --git a/.github/workflows/deploy-pr.yaml b/.github/workflows/deploy-pr.yaml deleted file mode 100644 index 3803cf77..00000000 --- a/.github/workflows/deploy-pr.yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: "Deploy to Cloudflare Pages (Preview)" - -on: [pull_request_target] - -jobs: - deploy: - runs-on: "ubuntu-latest" - permissions: - contents: read - deployments: write - pull-requests: write - steps: - - name: "checkout" - uses: "actions/checkout@v4" - with: - fetch-depth: 0 - ref: ${{ github.event.pull_request.head.ref }} - repository: ${{ github.event.pull_request.head.repo.full_name }} - - name: "setup pnpm" - uses: "pnpm/action-setup@v4" - - name: "setup node" - uses: "actions/setup-node@v4" - with: - cache: "pnpm" - node-version: 20 - - name: "install dependencies" - run: "pnpm install" - - name: "build" - run: "pnpm run build" - - name: "publish (push)" - id: "cloudflare-publish" - uses: "AdrianGonz97/refined-cf-pages-action@v1" - with: - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - projectName: "papermc-website" - deploymentName: "Preview" - gitHubToken: ${{ secrets.GITHUB_TOKEN }} - directory: "build" diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml new file mode 100644 index 00000000..14b1a7d1 --- /dev/null +++ b/.github/workflows/deploy-preview.yml @@ -0,0 +1,38 @@ +name: "Upload Preview Deployment" +on: + workflow_run: + workflows: ["Build Preview Deployment"] + types: + - completed + +permissions: + actions: read + deployments: write + contents: read + pull-requests: write + +jobs: + deploy-preview: + runs-on: "ubuntu-latest" + if: ${{ github.event.workflow_run.conclusion == 'success' }} + name: "Deploy Preview to Cloudflare Pages" + steps: + # Downloads the build directory from the previous workflow + - name: "download build artifact" + uses: "actions/download-artifact@v4" + id: "preview-build-artifact" + with: + name: "preview-build" + path: "build" + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + + - name: "publish (push)" + uses: "AdrianGonz97/refined-cf-pages-action@v1" + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + githubToken: ${{ secrets.GITHUB_TOKEN }} + projectName: "papermc-website" + deploymentName: "Preview" + directory: ${{ steps.preview-build-artifact.outputs.download-path }}