Skip to content

Commit d20ac97

Browse files
authored
Merge pull request #101 from OpenRailAssociation/web-deployment-action
2 parents e32063b + ba91de7 commit d20ac97

File tree

1 file changed

+29
-155
lines changed

1 file changed

+29
-155
lines changed

.github/workflows/hugo.yaml

Lines changed: 29 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,30 @@ on:
1515
# Allows to run this workflow manually from the Actions tab
1616
workflow_dispatch:
1717

18-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
19-
permissions:
20-
contents: read
21-
pages: write
22-
id-token: write
23-
pull-requests: write
24-
25-
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
26-
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
18+
# Allow only one concurrent deployment. However, do NOT cancel in-progress runs as we want to allow
19+
# especially production deployments to complete.
2720
concurrency:
2821
group: "pages"
2922
cancel-in-progress: false
3023

31-
# Set environment variables
24+
# Set environment variables which will be used multiple times in the workflow
3225
env:
3326
hugo_version: "0.147.9"
3427
source_dir: "."
35-
preview_domain: web-preview.openrailassociation.org
36-
preview_segment: main-pr-${{ github.event.number }}
37-
uberspace_host: uberspace1.openrailassociation.org
38-
uberspace_user: openrail
39-
uberspace_virtual_base: /var/www/virtual
40-
uberspace_prod_dir: html
28+
artifact_name: "website"
29+
condition_production: ${{ github.ref == 'refs/heads/main' }}
30+
domain_production: https://openrailassociation.org
31+
domain_preview: https://web-preview.openrailassociation.org
32+
dir_preview_subdir: main-pr-${{ github.event.number }}
4133

4234
jobs:
43-
# Set vars
44-
vars:
45-
runs-on: ubuntu-24.04
46-
outputs:
47-
pr_closed_merged: ${{ steps.pr_status.outputs.pr_closed_merged }}
48-
datetime: ${{ steps.datetime.outputs.datetime }}
49-
steps:
50-
- id: pr_status
51-
run: echo "pr_closed_merged=${{ github.event.pull_request.closed_at || github.event.pull_request.merged }}" >> "$GITHUB_OUTPUT"
52-
- id: datetime
53-
run: echo "datetime=$(date '+%Y-%m-%d %H:%M:%S %Z')" >> "$GITHUB_OUTPUT"
54-
5535
# Build job
5636
build:
5737
runs-on: ubuntu-24.04
58-
needs: vars
59-
# Only if PR not closed or merged
60-
if: needs.vars.outputs.pr_closed_merged == 'false' || needs.vars.outputs.pr_closed_merged == ''
6138
steps:
6239
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
6340
with:
64-
submodules: recursive # Get submdules
41+
submodules: recursive # Get submodules
6542
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
6643

6744
- name: Setup Hugo
@@ -72,139 +49,36 @@ jobs:
7249

7350
- name: Build production site
7451
run: hugo -s ${{ env.source_dir }}
75-
if: github.ref == 'refs/heads/main'
52+
if: env.condition_production == true
7653

7754
- name: Build preview site
78-
run: hugo -s ${{ env.source_dir }} -e staging --buildFuture --buildDrafts -b https://${{ env.preview_domain }}/${{ env.preview_segment }}/
79-
if: ${{ github.event.pull_request }}
55+
run: hugo -s ${{ env.source_dir }} -e staging --buildFuture --buildDrafts -b ${{ env.domain_preview }}/${{ env.dir_preview_subdir }}/
56+
if: github.event.pull_request
8057

8158
- name: Upload artifact
8259
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
8360
with:
84-
name: public
61+
name: ${{ env.artifact_name }}
8562
path: ${{ env.source_dir }}/public
8663
include-hidden-files: true
8764
retention-days: 1
8865

89-
# Checking links using lychee
90-
linkchecker:
91-
runs-on: ubuntu-24.04
92-
needs:
93-
- vars
94-
- build
95-
if: needs.vars.outputs.pr_closed_merged == 'false' || needs.vars.outputs.pr_closed_merged == ''
96-
steps:
97-
- name: Download artifact
98-
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
99-
with:
100-
name: public
101-
path: .
102-
103-
- name: Link Checker
104-
id: lychee
105-
uses: lycheeverse/lychee-action@82202e5e9c2f4ef1a55a3d02563e1cb6041e5332 # v2
106-
with:
107-
args: '-r 5 -u "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Apple WebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" --include-fragments --exclude sncf.com --exclude nge.flatland.cloud --max-concurrency 1 .'
108-
# Fail on errors
109-
fail: false
110-
# TODO: Implement https://github.com/lycheeverse/lychee/issues/989 once it's done. Will help with LinkedIn rate limits
111-
112-
# Deployment jobs
113-
deploy-production:
66+
deploy:
67+
name: Deploy website
68+
needs: build
11469
runs-on: ubuntu-24.04
115-
needs:
116-
- vars
117-
- build
118-
# Only deploy if on main branch
119-
if: github.ref == 'refs/heads/main'
12070
steps:
121-
- name: Download artifact
122-
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
123-
with:
124-
name: public
125-
path: ./public
126-
127-
- name: Copy website to host
128-
uses: appleboy/scp-action@ff85246acaad7bdce478db94a363cd2bf7c90345 # v1.0.0
129-
with:
130-
host: ${{ env.uberspace_host }}
131-
username: ${{ env.uberspace_user }}
132-
key: ${{ secrets.SSH_KEY }}
133-
port: 22
134-
timeout: 1m
135-
command_timeout: 2m
136-
target: ${{ env.uberspace_virtual_base }}/${{ env.uberspace_user }}/${{ env.uberspace_prod_dir }}/
137-
source: "public/*"
138-
rm: true
139-
strip_components: 1
140-
141-
deploy-preview:
142-
runs-on: ubuntu-24.04
143-
needs:
144-
- vars
145-
- build
146-
# Only deploy if non-closed/non-merged pull request
147-
if: github.event.pull_request && needs.vars.outputs.pr_closed_merged == 'false'
148-
steps:
149-
- name: Download artifact
150-
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
151-
with:
152-
name: public
153-
path: ./public
154-
155-
- name: Copy website to host
156-
uses: appleboy/scp-action@ff85246acaad7bdce478db94a363cd2bf7c90345 # v1.0.0
157-
with:
158-
host: ${{ env.uberspace_host }}
159-
username: ${{ env.uberspace_user }}
160-
key: ${{ secrets.SSH_KEY }}
161-
port: 22
162-
timeout: 1m
163-
command_timeout: 2m
164-
target: ${{ env.uberspace_virtual_base }}/${{ env.uberspace_user }}/${{ env.preview_domain }}/${{ env.preview_segment }}
165-
source: "public/*"
166-
rm: true
167-
strip_components: 1
168-
169-
- name: Inform about Preview URL
170-
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2.9.4
171-
with:
172-
header: pr-preview
173-
message: |
174-
Pull Request Live Preview
175-
:---:
176-
| <p><br />:rocket: View preview at <br />https://${{ env.preview_domain }}/${{ env.preview_segment }}/<br /><br /></p>
177-
| <p>Last updated: ${{ needs.vars.outputs.datetime }}</p>
178-
179-
remove-preview:
180-
runs-on: ubuntu-24.04
181-
needs:
182-
- vars
183-
# Only deploy if non-closed/non-merged pull request
184-
if: github.event.pull_request && needs.vars.outputs.pr_closed_merged != 'false'
185-
steps:
186-
- name: Create deletion notice
187-
run: mkdir -p public && echo "This PR has been closed or merged. The preview has been removed." > public/index.html
188-
189-
- name: Copy empty folder to host
190-
uses: appleboy/scp-action@ff85246acaad7bdce478db94a363cd2bf7c90345 # v1.0.0
191-
with:
192-
host: ${{ env.uberspace_host }}
193-
username: ${{ env.uberspace_user }}
194-
key: ${{ secrets.SSH_KEY }}
195-
port: 22
196-
timeout: 1m
197-
command_timeout: 2m
198-
target: ${{ env.uberspace_virtual_base }}/${{ env.uberspace_user }}/${{ env.preview_domain }}/${{ env.preview_segment }}
199-
source: "public/*"
200-
rm: true
201-
strip_components: 1
202-
203-
- name: Inform about preview removal
204-
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2.9.4
71+
- uses: OpenRailAssociation/web-deployment-action@v1
20572
with:
206-
header: pr-preview
207-
message: |
208-
Pull Request Live Preview
209-
:---:
210-
| <p><br />:x: Preview has been removed.<br /><br /></p>
73+
artifact_name: ${{ env.artifact_name }}
74+
condition_production: ${{ env.condition_production }}
75+
domain_production: ${{ env.domain_production }}
76+
domain_preview: ${{ env.domain_preview }}
77+
dir_base: /var/www/virtual/openrail
78+
dir_production: html
79+
dir_preview_base: web-preview.openrailassociation.org
80+
dir_preview_subdir: ${{ env.dir_preview_subdir }}
81+
ssh_host: uberspace1.openrailassociation.org
82+
ssh_user: openrail
83+
ssh_key: ${{ secrets.SSH_KEY }}
84+
linkchecker_exclude: "sncf.com,flatland.cloud"

0 commit comments

Comments
 (0)