summaryrefslogtreecommitdiff
path: root/.github/workflows/preview_push.yml
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2020-12-08 13:49:22 +0100
committerPatric Stout <github@truebrain.nl>2020-12-15 15:46:39 +0100
commit93ef759a257a1aebf98b9a54fc6698b4732b05f7 (patch)
treef01d794947768b05b147d6d78d468f50050083de /.github/workflows/preview_push.yml
parent8fbf5bef60568cd4dcd56921c37be64b8234d9bb (diff)
downloadopenttd-93ef759a257a1aebf98b9a54fc6698b4732b05f7.tar.xz
Add: [Actions] preview workflow, where PRs can be reviewed in the browser
When a developer attaches the "preview" label, a build is created and published on https://preview.openttd.org/. After that, new pushes to the PR are automatically build (as long as the "preview" label exists). If a non-developer attaches the "preview" label, it will be removed.
Diffstat (limited to '.github/workflows/preview_push.yml')
-rw-r--r--.github/workflows/preview_push.yml66
1 files changed, 66 insertions, 0 deletions
diff --git a/.github/workflows/preview_push.yml b/.github/workflows/preview_push.yml
new file mode 100644
index 000000000..cb68c8f6c
--- /dev/null
+++ b/.github/workflows/preview_push.yml
@@ -0,0 +1,66 @@
+name: Preview push
+
+on:
+ pull_request_target:
+ types:
+ - synchronize
+
+jobs:
+ check_new_preview:
+ name: Check preview needs update
+
+ runs-on: ubuntu-20.04
+
+ steps:
+ - name: Check if earlier preview exists
+ id: earlier_preview
+ uses: octokit/request-action@v2.x
+ with:
+ route: GET /repos/{owner}/{repo}/deployments
+ owner: ${{ github.event.repository.owner.login }}
+ repo: ${{ github.event.repository.name }}
+ environment: preview-pr-${{ github.event.number }}
+ per_page: 1
+ env:
+ GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
+
+ - if: toJson(fromJson(steps.earlier_preview.outputs.data)) != '[]'
+ name: Check for preview label
+ id: preview_label
+ uses: octokit/request-action@v2.x
+ with:
+ route: GET /repos/{owner}/{repo}/issues/{issue_number}/labels
+ owner: ${{ github.event.repository.owner.login }}
+ repo: ${{ github.event.repository.name }}
+ issue_number: ${{ github.event.number }}
+ env:
+ GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
+
+ - if: toJson(fromJson(steps.earlier_preview.outputs.data)) != '[]' && contains(fromJson(steps.preview_label.outputs.data).*.name, 'preview')
+ name: Create deployment
+ id: deployment
+ uses: octokit/request-action@v2.x
+ with:
+ route: POST /repos/{owner}/{repo}/deployments
+ mediaType: |
+ previews:
+ - ant-man
+ - flash
+ owner: ${{ github.event.repository.owner.login }}
+ repo: ${{ github.event.repository.name }}
+ ref: ${{ github.event.pull_request.head.sha }}
+ task: deploy:preview
+ auto_merge: false
+ required_contexts: "[]"
+ environment: preview-pr-${{ github.event.number }}
+ description: "Preview for Pull Request #${{ github.event.number }}"
+ env:
+ GITHUB_TOKEN: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
+
+ - if: toJson(fromJson(steps.earlier_preview.outputs.data)) != '[]' && contains(fromJson(steps.preview_label.outputs.data).*.name, 'preview')
+ name: Trigger 'preview build'
+ uses: peter-evans/repository-dispatch@v1
+ with:
+ token: ${{ secrets.PREVIEW_GITHUB_TOKEN }}
+ event-type: "Preview build #${{ github.event.number }}"
+ client-payload: '{"folder": "pr${{ github.event.number }}", "sha": "${{ github.event.pull_request.head.sha }}", "deployment_id": "${{ fromJson(steps.deployment.outputs.data).id }}"}'