Skip to content

add newline

add newline #21

# Deploy pull requests to surge, so multiple previews can exist at once
# The deployments API is used to make the deployments visible in the pull request
# https://surge.sh/
# to install surge:
# $ npm install --global surge
# to log in to surge or create an account, run
# $ surge
# to publish a folder as a static site, run
# $ surge --project <folder> --domain <example28928.surge.sh>
# or
# $ surge <folder>
# to remove a site, run
# $ surge teardown <example28928.surge.sh>
# to list active sites, run
# $ surge list
# this workflow requires one secret: SURGE_TOKEN, generated with
# $ surge token
# note: the PDFs are not deployed, as they turn a ~60mb site into a ~600mb site.
# workflow modified from https://sanderknape.com/2020/05/deploy-pull-requests-github-actions-deployments/
name: Deploy pull request preview to surge
on:
pull_request_target:
types: [opened, reopened, synchronize]
permissions:
contents: read
deployments: write
pull-requests: write
statuses: write
issues: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: get pull request ref
id: get_pull_request_ref
uses: octokit/[email protected]
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/[email protected]
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/[email protected]
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
uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.head.ref }}"
repository: "${{ github.event.pull_request.head.repo.full_name }}"
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Build with Eleventy
run: npm run build
- 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
- name: set deployment status to success
id: successful_deployment
uses: octokit/[email protected]
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/[email protected]
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
# uses: octokit/[email protected]
# with:
# route: POST /repos/:repository/issues/:issue_id/comments
# repository: ${{ github.repository }}
# issue_id: ${{ github.event.number }}
# body: "deployed to <https://liputenpotest-${{ github.event.number }}.surge.sh>"
# env:
# GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"