Skip to content

Commit

Permalink
feat: manage teardown in surge preview with multi stages (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbouffard authored Apr 19, 2024
1 parent 78e2691 commit ad497d2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/surge-pr-fork-01-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Surge PR Preview - Build Stage

on:
pull_request:
# keep in sync with the teardown stage
paths:
- '.github/workflows/surge-pr-fork-01-build.yml'
- '.github/workflows/surge-pr-fork-02-deploy.yml'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/surge-pr-fork-02-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ permissions:
pull-requests: write # surge-preview creates or updates PR comments about the deployment status

jobs:
# MUST be unique across all surge preview deployments for a repository as the job id is used in the deployment URL
# MUST be kept in sync with the job id of the teardown stage (used in the deployment URL)
deploy:
runs-on: ubuntu-22.04
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
Expand Down Expand Up @@ -55,3 +57,4 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
build: echo done
dist: site
failOnError: true
45 changes: 45 additions & 0 deletions .github/workflows/surge-pr-fork-03-teardown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Surge Preview for Pull Request

on:
pull_request_target:
# To manage 'surge-preview' action teardown on PR closed
types: [closed]
branches:
- master
# keep in sync with the build stage
paths:
- '.github/workflows/surge-pr-fork-01-build.yml'
- '.github/workflows/surge-pr-fork-02-deploy.yml'
- 'public/surge/**/*'


permissions:
pull-requests: write # surge-preview creates or updates PR comments about the deployment status

jobs:
deploy: # MUST be kept in sync with the job id of the deploy stage (used in the deployment URL)
runs-on: ${{ vars.RUNNER_UBUNTU }}
steps:
- uses: bonitasoft/actions/packages/surge-preview-tools@v2
id: surge-preview-tools
with:
surge-token: ${{ secrets.SURGE_TOKEN }}

- name: Echo surge preview tools output
run: |
echo "can-run-surge-command: ${{ steps.surge-preview-tools.outputs.can-run-surge-command }}"
echo "domain-exist: ${{ steps.surge-preview-tools.outputs.domain-exist }}"
echo "preview-url: ${{ steps.surge-preview-tools.outputs.preview-url }}"
echo "surge-token-valid: ${{ steps.surge-preview-tools.outputs.surge-token-valid }}"
- name: Teardown demo preview
if: steps.surge-preview-tools.outputs.can-run-surge-command == 'true'
id: publish_demo_preview
uses: afc163/surge-preview@v1
with:
surge_token: ${{ secrets.SURGE_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
failOnError: true
teardown: true
build: |
echo
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ GitHub pages environment generated by this repository
- [Fill github draft releases](.github/workflows/fill-gh-draft-release.yml): experiment the release-drafter configuration (used in bpmn-visualization)
- [Slack send message](.github/workflows/slack-send-message.yml): send a message to a Slack channel or user
- [Surge preview for Pull Request](.github/workflows/surge-preview-for-pr.yml): create/teardown a surge deployment when a new Pull Request is created/closed
- Surge preview for PR in 2 stages. This is the only known way to have a preview for PR created from forks.
- Surge preview for PR in several stages. This is the only known way to have a preview for PR created from forks.
- [Surge preview for PR - stage 1](.github/workflows/surge-pr-fork-01-build.yml): the first stage is to create an artifact of the site.
- [Surge preview for PR - stage 2](.github/workflows/surge-pr-fork-02-deploy.yml): the second stage is to deploy the artifact created in the first stage.
- [Surge preview for PR - stage 3](.github/workflows/surge-pr-fork-03-teardown.yml): the third stage is to teardown the deployment when the PR is closed.
- [Workflow concurrency](.github/workflows/workflow-concurrency.yml): avoid to have more than 1 workflow run at a time
- [Workflow dispatch](.github/workflows/workflow-dispatch.yml): run job depending on if the workflow is triggered from the `master` branch or another branch

Expand Down

0 comments on commit ad497d2

Please sign in to comment.