From cde0159e9f2510eb59b2843745e3765a2f22b509 Mon Sep 17 00:00:00 2001 From: alifeee Date: Mon, 26 Aug 2024 22:43:35 +0100 Subject: [PATCH] remove deployments (notify with comments again) --- .../pull-request-preview-cleanup.yml | 30 ++++ .github/workflows/pull-request-preview.yml | 154 +++++++++++------- 2 files changed, 122 insertions(+), 62 deletions(-) diff --git a/.github/workflows/pull-request-preview-cleanup.yml b/.github/workflows/pull-request-preview-cleanup.yml index 22a7b95..ee8228e 100644 --- a/.github/workflows/pull-request-preview-cleanup.yml +++ b/.github/workflows/pull-request-preview-cleanup.yml @@ -81,3 +81,33 @@ jobs: # body: "removed the deployment on " # env: # GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + + - name: Find Comment + uses: peter-evans/find-comment@v1 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: "github-actions[bot]" + body-includes: "surge: " + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + + - name: Create comment + if: steps.fc.outputs.comment-id == '' + uses: peter-evans/create-or-update-comment@v1 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + surge: removed the deployment on + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + + - name: Update comment + if: steps.fc.outputs.comment-id != '' + uses: peter-evans/create-or-update-comment@v1 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + body: | + surge: removed the deployment on + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/pull-request-preview.yml b/.github/workflows/pull-request-preview.yml index 3483aed..bffa486 100644 --- a/.github/workflows/pull-request-preview.yml +++ b/.github/workflows/pull-request-preview.yml @@ -26,7 +26,7 @@ on: permissions: contents: read - deployments: write + # deployments: write pull-requests: write statuses: write issues: write @@ -35,41 +35,41 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - name: get pull request ref - id: get_pull_request_ref - uses: octokit/request-action@v2.x - with: - route: GET /repos/:repository/pulls/:issue_id - repository: ${{ github.repository }} - issue_id: ${{ github.event.number }} - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + # - name: get pull request ref + # id: get_pull_request_ref + # uses: octokit/request-action@v2.x + # with: + # route: GET /repos/:repository/pulls/:issue_id + # repository: ${{ github.repository }} + # issue_id: ${{ github.event.number }} + # env: + # GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - - name: create deployment - id: create_deployment - uses: octokit/request-action@v2.x - with: - route: POST /repos/:repository/deployments - repository: ${{ github.repository }} - ref: ${{ github.event.pull_request.base.ref }} - environment: dev - auto_merge: false - required_contexts: "[]" - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + # - name: create deployment + # id: create_deployment + # uses: octokit/request-action@v2.x + # with: + # route: POST /repos/:repository/deployments + # repository: ${{ github.repository }} + # ref: ${{ github.event.pull_request.base.ref }} + # environment: dev + # auto_merge: false + # required_contexts: "[]" + # env: + # GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - - name: set deployment status to in progress - id: start_deployment - uses: octokit/request-action@v2.x - with: - route: POST /repos/:repository/deployments/:deployment/statuses - repository: ${{ github.repository }} - deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} - environment: dev - log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} - state: in_progress - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + # - name: set deployment status to in progress + # id: start_deployment + # uses: octokit/request-action@v2.x + # with: + # route: POST /repos/:repository/deployments/:deployment/statuses + # repository: ${{ github.repository }} + # deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} + # environment: dev + # log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + # state: in_progress + # env: + # GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # deployment goes here - name: Checkout @@ -87,35 +87,35 @@ jobs: - name: Remove pdfs (filesize restraints) run: rm _site/pdfs/*.pdf - name: deploy to surge - run: npm run surge -- --token "${{ secrets.SURGE_TOKEN }}" --domain liputenpotest-${{ github.event.number }}.surge.sh + run: npm run surge -- --token "${{ secrets.SURGE_TOKEN }}" --domain liputenpotest-${{ github.event.number }}.surge.sh - - name: set deployment status to success - id: successful_deployment - uses: octokit/request-action@v2.x - with: - route: POST /repos/:repository/deployments/:deployment/statuses - repository: ${{ github.repository }} - deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} - environment: dev - environment_url: https://liputenpotest-${{ github.event.number }}.surge.sh - log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} - state: success - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + # - name: set deployment status to success + # id: successful_deployment + # uses: octokit/request-action@v2.x + # with: + # route: POST /repos/:repository/deployments/:deployment/statuses + # repository: ${{ github.repository }} + # deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} + # environment: dev + # environment_url: https://liputenpotest-${{ github.event.number }}.surge.sh + # log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + # state: success + # env: + # GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - - name: set deployment status to failure - id: failed_deployment - uses: octokit/request-action@v2.x - if: failure() - with: - route: POST /repos/:repository/deployments/:deployment/statuses - repository: ${{ github.repository }} - deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} - environment: dev - log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} - state: failure - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + # - name: set deployment status to failure + # id: failed_deployment + # uses: octokit/request-action@v2.x + # if: failure() + # with: + # route: POST /repos/:repository/deployments/:deployment/statuses + # repository: ${{ github.repository }} + # deployment: ${{ fromJson(steps.create_deployment.outputs.data).id }} + # environment: dev + # log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + # state: failure + # env: + # GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # - name: Send confirmation # id: send_confirmation @@ -124,6 +124,36 @@ jobs: # route: POST /repos/:repository/issues/:issue_id/comments # repository: ${{ github.repository }} # issue_id: ${{ github.event.number }} - # body: "deployed to " + # body: "surge: deployed to " # env: # GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + + - name: Find Comment + uses: peter-evans/find-comment@v1 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: "github-actions[bot]" + body-includes: "surge: " + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + + - name: Create comment + if: steps.fc.outputs.comment-id == '' + uses: peter-evans/create-or-update-comment@v1 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + surge: deployed to + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + + - name: Update comment + if: steps.fc.outputs.comment-id != '' + uses: peter-evans/create-or-update-comment@v1 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + body: | + surge: deployed to + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"