Update README #37
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Manage site previews | |
on: | |
pull_request: | |
types: | |
- closed | |
- opened | |
- reopened | |
- synchronize | |
concurrency: | |
group: ${{ github.workflow }} | |
jobs: | |
preview: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create deployment | |
uses: octokit/request-action@v2.x | |
if: contains('opened reopened', github.event.action) | |
with: | |
route: POST /repos/{repo}/deployments | |
repo: ${{ github.repository }} | |
ref: ${{ github.event.pull_request.head.ref }} | |
environment: preview | |
auto_merge: false | |
required_contexts: "[]" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get deployments | |
uses: octokit/request-action@v2.x | |
id: get_deployments | |
with: | |
route: GET /repos/{repo}/deployments | |
repo: ${{ github.repository }} | |
ref: ${{ github.event.pull_request.head.ref }} | |
environment: preview | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Mark deployment as inactive | |
uses: octokit/request-action@v2.x | |
if: contains('closed', github.event.action) | |
with: | |
route: POST /repos/{repo}/deployments/{deployment}/statuses | |
repo: ${{ github.repository }} | |
deployment: ${{ fromJson(steps.get_deployments.outputs.data)[0].id }} | |
state: inactive | |
log_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
headers: | | |
Accept: application/vnd.github.ant-man-preview+json | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Clean up deployment artifacts | |
if: contains('closed', github.event.action) # leave untouched when commits are pushed | |
run: aws s3 rm --recursive s3://preview.nicholas.cloud/${{ github.event.pull_request.number }}/ | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY_SECRET }} | |
AWS_DEFAULT_REGION: ap-southeast-2 | |
- name: Check out source code | |
uses: actions/checkout@v2 | |
if: contains('opened reopened synchronize', github.event.action) | |
with: | |
submodules: recursive | |
- name: Build | |
uses: docker://registry.gitlab.com/pages/hugo:latest | |
with: | |
args: hugo --baseURL https://preview.nicholas.cloud/${{ github.event.pull_request.number }}/ | |
if: contains('opened reopened synchronize', github.event.action) | |
- name: Deploy build artifacts | |
if: contains('opened reopened synchronize', github.event.action) | |
run: aws s3 sync --size-only public/ s3://preview.nicholas.cloud/${{ github.event.pull_request.number }}/ | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY_SECRET }} | |
AWS_DEFAULT_REGION: ap-southeast-2 | |
- name: Create successful status for deployment | |
uses: octokit/request-action@v2.x | |
if: contains('opened reopened synchronize', github.event.action) | |
with: | |
route: POST /repos/{repo}/deployments/{deployment}/statuses | |
repo: ${{ github.repository }} | |
deployment: ${{ fromJson(steps.get_deployments.outputs.data)[0].id }} | |
state: success | |
environment_url: https://preview.nicholas.cloud/${{ github.event.pull_request.number }}/ | |
log_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Created errored status for deployment | |
uses: octokit/request-action@v2.x | |
if: contains('opened reopened synchronize', github.event.action) && failure() | |
with: | |
route: POST /repos/{repo}/deployments/{deployment}/statuses | |
repo: ${{ github.repository }} | |
deployment: ${{ fromJson(steps.get_deployments.outputs.data)[0].id }} | |
state: error | |
log_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |