-
Notifications
You must be signed in to change notification settings - Fork 1
142 lines (125 loc) · 4.63 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Lint, Build, Deploy, and Index site
on:
push:
branches:
- 'staging'
- 'main'
pull_request:
branches:
- 'staging'
- 'main'
concurrency:
group: ${{ format('{0}-{1}', github.workflow, github.ref) }}
cancel-in-progress: true
jobs:
build:
name: Build the site
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Staging site configuration
if: github.ref_name != 'main'
run: |
echo "XARGS=--drafts" >> $GITHUB_ENV
echo 'User-agent: * Disallow: /' > ${{ github.workspace }}/robots.txt
sed -i 's_sebsscholarship.org_test.sebsscholarship.org_g' ${{ github.workspace }}/_config.yml
- name: Install Composer dependencies
run: |
docker run --rm \
-v ${{ github.workspace }}:/app \
composer:2 install -n
- name: Build site
run: |
docker run -v ${{ github.workspace }}:/srv/jekyll jekyll/builder:4.2.2 /bin/bash -c \
"bundle install && chmod 777 /srv/jekyll && bundle exec jekyll build --future ${{ env.XARGS }}"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: Built Site
path: ${{ github.workspace }}/_site/
deploy:
name: Deploy the site
runs-on: ubuntu-latest
needs:
- build
# Only deploy if on the staging or main branch
if: github.ref_name == 'staging' || github.ref_name == 'main'
steps:
- name: Set test environment
if: github.ref_name == 'staging'
run: |
echo "SITE_USER=${{ secrets.TEST_SSH_USER }}" >> $GITHUB_ENV
echo "SITE_KEY<<EOF" >> $GITHUB_ENV
echo "${{ secrets.TEST_SSH_KEY }}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "SITE_DIR=test.sebsscholarship.org" >> $GITHUB_ENV
- name: Set main environment
if: github.ref_name == 'main'
run: |
echo "SITE_USER=${{ secrets.PROD_SSH_USER }}" >> $GITHUB_ENV
echo "SITE_KEY<<EOF" >> $GITHUB_ENV
echo "${{ secrets.PROD_SSH_KEY }}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "SITE_DIR=sebsscholarship.org" >> $GITHUB_ENV
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: Built Site
path: _site/
- name: Install SSH key
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ env.SITE_KEY }}
- name: Trust SSH key
run: ssh-keyscan sebsscholarship.org > ~/.ssh/known_hosts
- name: Deploy
run: |
scp -r ${{ github.workspace }}/_site/* ${{ env.SITE_USER }}@sebsscholarship.org:~/staging/
ssh ${{ env.SITE_USER }}@sebsscholarship.org 'rm -rf ~/${{ env.SITE_DIR }}/* \
&& mv ~/staging/* ~/${{ env.SITE_DIR }}/'
notify:
name: Send job complete notification
runs-on: ubuntu-latest
needs:
- build
- deploy
# Run if on staging or main
if: always() && (github.ref_name == 'staging' || github.ref_name == 'main')
steps:
- name: Set test environment
if: github.ref_name == 'staging'
run: |
echo "SITE_NAME=test" >> $GITHUB_ENV
echo "SITE_ADDR=https://test.sebsscholarship.org" >> $GITHUB_ENV
- name: Set main environment
if: github.ref_name == 'main'
run: |
echo "SITE_NAME=main" >> $GITHUB_ENV
echo "SITE_ADDR=https://sebsscholarship.org" >> $GITHUB_ENV
- name: Notify on success
# If the site was successfully built and indexed
if: needs.build.result == 'success' && needs.deploy.result == 'success'
uses: appleboy/discord-action@v1.1.0
with:
webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }}
webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
color: "#800000"
username: "SSF Website Status Bot"
message: >
Updates were successfully pushed to ${{ env.SITE_NAME }} site:
${{ env.SITE_ADDR }}
- name: Notify on failure
# If the site failed at any point
if: needs.build.result == 'failure' || needs.deploy.result == 'failure'
uses: appleboy/discord-action@v1.1.0
with:
webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }}
webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
color: "#800000"
username: "SSF Website Status Bot"
message: >
Aborting ${{ env.SITE_NAME }} site deployment due to unexpected error:
https://github.com/sebs-scholarship/Website/actions/runs/${{ github.run_id }}