Skip to content

Commit e54f598

Browse files
xxwhirlpoolessential-randomness
authored andcommitted
workflows for da org
1 parent 479030d commit e54f598

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "Deploy preview (static version) workflow",
3+
"description": "Deploy a static site",
4+
"iconName": "octicon heart"
5+
}
6+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# prettier-ignore
2+
env:
3+
DEPLOY_PATH: ${{ vars.REMOTE_TARGET }}${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.event_name == 'push' && 'main' || github.event.inputs.destination}}
4+
# this will:
5+
# - start with REMOTE_TARGET, which is usuallly "/var/www/site_name"
6+
# - if this is from a PR, use the PR's number for a subdirectory (/var/www/site_name/12)
7+
# - if it's a regular commit push, use the main branch (/var/www/site_name/main)
8+
# - if there's a "destination" input, meaning it's been manually triggered, use the input value (/var/www/site_name/[value])
9+
10+
on:
11+
push:
12+
branches:
13+
- main # work off main branch
14+
pull_request_target: # this workflow triggers either when there's a push to main OR when a PR is opened/updated
15+
types: [opened, synchronize, reopened]
16+
workflow_dispatch: # it also can be triggered manually, and in that case the destination will be required and called "manual_run"
17+
inputs:
18+
destination:
19+
description: "Define destination base path"
20+
required: true
21+
default: "manual_run"
22+
name: Site deploy preview
23+
24+
jobs:
25+
build:
26+
runs-on: ubuntu-latest # use github runner, not our self-hosted one
27+
if: |
28+
github.event_name != 'pull_request_target' ||
29+
contains('MEMBER OWNER COLLABORATOR', github.event.pull_request.author_association)
30+
permissions: # set permissions
31+
pull-requests: write
32+
contents: read
33+
steps:
34+
- name: update PR
35+
if: ${{ github.event_name == 'pull_request' }} # execute this step only if there is a PR
36+
uses: thollander/actions-comment-pull-request@v2
37+
with:
38+
message: |
39+
Started attempt to build a new deploy preview for PR ${{ github.event.pull_request.number }}.
40+
comment_tag: pr_published
41+
- name: Checkout your repository using git
42+
uses: actions/checkout@v4 # check out the repo
43+
with:
44+
ref:
45+
${{ github.event_name == 'pull_request' &&
46+
github.event.pull_request.head.sha || github.ref }} # if this was triggered by a PR, then match with the commit that the PR uses. otherwise, use the commit that the workflow was triggered from
47+
- name: Install, build, and upload your site output # install dependencies, build the site, then upload the result
48+
uses: withastro/action@v4
49+
- run: ls -la # debugging step: check if the built files uploaded correctly
50+
51+
deploy-website:
52+
runs-on: ubuntu-latest # github runner, not ours
53+
if: |
54+
github.event_name != 'pull_request_target' ||
55+
contains('MEMBER OWNER COLLABORATOR', github.event.pull_request.author_association)
56+
permissions:
57+
pull-requests: write
58+
contents: read
59+
needs: build
60+
steps:
61+
- uses: actions/download-artifact@v4 # download the artifact from the previous step
62+
with:
63+
name: github-pages
64+
- run: ls -la # debugging step: check if built files downloaded fine & in the right place
65+
- run: mkdir dist/
66+
- run: tar -xvf artifact.tar -C dist/
67+
- run: ls -la
68+
- name: Deploy to Server
69+
uses: easingthemes/ssh-deploy@main # deploy via SSH and rsync
70+
with:
71+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
72+
ARGS: "-rlgoDzvc -i --delete" # flags are: recursive, links (recreate symlinks), groups (match groups on target), owner (match owner on target), devices, compress (smaller file size, makes transfer faster), verbose (for debugging), checksum (this is how rsync checks that an update is needed), itemize changes (list all the changes), delete (get rid of files we don't need)
73+
SOURCE: "dist/"
74+
REMOTE_HOST: ${{ vars.REMOTE_HOST }} # the target server to push the deployed site files to
75+
REMOTE_USER: ${{ vars.REMOTE_USER }} # the user that the server will operate as for running the files
76+
TARGET: ${{ env.DEPLOY_PATH}} # see line 4 for step-by-step explanation of this variable
77+
- name: update PR
78+
if: ${{ github.event_name == 'pull_request' }}
79+
uses: thollander/actions-comment-pull-request@v2 # if there's a PR, update it with a comment that a new deploy preview has been created
80+
with:
81+
message: |
82+
Created a new deploy preview for PR ${{ github.event.pull_request.number }}. [See preview](${{ vars.PREVIEW_SITE_URL }}/${{ github.event.pull_request.number }}/).
83+
comment_tag: pr_published

0 commit comments

Comments
 (0)