diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 0000000000..c79d5ab318 --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,64 @@ +name: Surge.sh Preview + +on: + workflow_run: + workflows: [ "Publish website" ] + types: + - completed + +defaults: + run: + shell: bash + +jobs: + preview: + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' + permissions: + pull-requests: write # Required to update PR status comment + steps: + - name: Download PR Artifact + uses: actions/download-artifact@v4 + with: + name: site + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Download PR ID Artifact + uses: actions/download-artifact@v4 + with: + name: pr-id + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Store PR id as variable + id: pr + run: | + echo "id=$(> $GITHUB_OUTPUT + rm -f pr-id.txt + + - name: Publishing to surge for preview + id: deploy + run: npx surge ./ --domain https://quarkiverse-docs-pr-${{ steps.pr.outputs.id }}-preview.surge.sh --token ${{ secrets.SURGE_TOKEN }} + + - name: Update PR status comment on success + uses: actions-cool/maintain-one-comment@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + body: | + 🚀 PR Preview ${{ github.sha }} has been successfully built and deployed to https://quarkiverse-docs-pr-${{ steps.pr.outputs.id }}-preview.surge.sh + + body-include: '' + number: ${{ steps.pr.outputs.id }} + + - name: Update PR status comment on failure + if: ${{ failure() }} + uses: actions-cool/maintain-one-comment@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + body: | + 😭 Deploy PR Preview failed. + + + body-include: '' + number: ${{ steps.pr.outputs.id }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 943baa5f1e..d2e37a86fd 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,9 +9,6 @@ on: pull_request: types: [ opened, synchronize, reopened ] -env: - SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} - defaults: run: shell: bash @@ -39,14 +36,12 @@ jobs: run: npm run build - name: Store PR id - if: github.event_name == 'pull_request' run: | mkdir pr echo ${{ github.event.number }} > ./pr/pr-id.txt - name: Upload PR id as artifact uses: actions/upload-artifact@v4 - if: github.event_name == 'pull_request' with: name: pr-id path: pr @@ -59,57 +54,6 @@ jobs: path: build/site retention-days: 1 - preview: - runs-on: ubuntu-latest - needs: [ build ] - if: github.event_name == 'pull_request' - permissions: - pull-requests: write # Required to update PR status comment - steps: - - name: Download PR Artifact - uses: actions/download-artifact@v4 - with: - name: site - github-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Download PR ID Artifact - uses: actions/download-artifact@v4 - with: - name: pr-id - github-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Store PR id as variable - id: pr - run: | - echo "id=$(> $GITHUB_OUTPUT - rm -f pr-id.txt - - - name: Publishing to surge for preview - id: deploy - run: npx surge ./ --domain https://quarkiverse-docs-pr-${{ steps.pr.outputs.id }}-preview.surge.sh --token $SURGE_TOKEN - - - name: Update PR status comment on success - uses: actions-cool/maintain-one-comment@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - body: | - 🚀 PR Preview ${{ github.sha }} has been successfully built and deployed to https://quarkiverse-docs-pr-${{ steps.pr.outputs.id }}-preview.surge.sh - - body-include: '' - number: ${{ steps.pr.outputs.id }} - - - name: Update PR status comment on failure - if: ${{ failure() }} - uses: actions-cool/maintain-one-comment@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - body: | - 😭 Deploy PR Preview failed. - - - body-include: '' - number: ${{ steps.pr.outputs.id }} - deploy: # Only try and deploy on merged code if: "github.repository == 'quarkiverse/quarkiverse-docs' && github.ref_name == 'main' && (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')"