-
Notifications
You must be signed in to change notification settings - Fork 203
153 lines (135 loc) · 4.33 KB
/
book_deploy.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
143
144
145
146
147
148
149
150
151
152
153
name: Wiki Deploy
on:
push:
branches:
- dev
- prod
jobs:
build:
name: Build wiki
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
env:
GH_TOKEN: ${{ github.token }}
run: |-
gh release download -R rust-lang/mdBook -p mdbook-*-x86_64-unknown-linux-gnu.tar.gz
gh release download -R tommilligan/mdbook-admonish -p mdbook-admonish-*-x86_64-unknown-linux-gnu.tar.gz
gh release download -R NilPointer-Software/mdbook-discord-components -p mdbook-discord-components-*.tar.gz
for file in *.tar.gz
do tar xzf "$file" -C /usr/local/bin
rm $file
done
- name: Build book
env:
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
run: |-
mdbook-admonish install --css-dir src/theme
mdbook build
- name: Upload book
uses: actions/upload-artifact@v4
with:
name: book
path: book
deploy-prod:
name: Deploy production wiki
needs: build
if: github.ref_name == 'prod'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Prepare to fetch book
run: |-
mv nightly ..
rm -rf *
- name: Fetch book artifact
uses: actions/download-artifact@v4
with:
name: book
- name: Deploy
run: |-
mv ../nightly .
git add -A
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git commit -m "Deploy $GITHUB_SHA to gh-pages"
git push --force --set-upstream origin gh-pages
deploy-nightly:
name: Deploy nightly wiki
needs: build
if: github.ref_name == 'dev'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Prepare to fetch book
run: rm -rf nightly/*
- name: Fetch book artifact
uses: actions/download-artifact@v4
with:
name: book
path: nightly
- name: Deploy
run: |-
git add -A
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git commit -m "Deploy nightly $GITHUB_SHA to gh-pages"
git push --force --set-upstream origin gh-pages
notify-discord:
name: Send notification
needs: [deploy-prod, deploy-nightly]
if: ${{ !failure() }}
runs-on: ubuntu-latest
env:
TYPE: Nightly
LINK: nightly
steps:
- name: Prepare notification
env:
RAW: ${{ github.event.head_commit.message }}
run: |-
echo "MESSAGE<<EOF" >> $GITHUB_ENV
RAW=$(echo "$RAW" | sed -r '/^\s*$/d')
echo "$RAW" | head -n 10 | sed ':a;N;$!ba;s/\n/\n /g' >> $GITHUB_ENV
if [ $(echo "$RAW" | wc -l) -gt 10 ]; then
echo " ..." >> $GITHUB_ENV
fi
echo "EOF" >> $GITHUB_ENV
- name: Set notification type
if: github.ref_name == 'prod'
run: |-
echo "TYPE=Production" >> $GITHUB_ENV
echo "LINK=" >> $GITHUB_ENV
- name: Send notification
uses: MineBartekSA/discord-webhook@v2.1
with:
webhook: ${{ secrets.WEBHOOK }}
embed: |-
title: "${{ env.TYPE }} Wiki Update"
color: 10001644
author:
name: ${{ github.event.head_commit.author.username }}
url: https://github.com/${{ github.event.head_commit.author.username }}
icon_url: https://github.com/${{ github.event.head_commit.author.username }}.png
thumbnail:
url: https://botdesignerdiscord.com/logo512.png
description: |-
**__Content__**
${{ env.MESSAGE }}
component: |-
- type: 2
style: 5
label: View commit
url: ${{ github.event.head_commit.url }}
- type: 2
style: 5
label: Preview site
url: https://nilpointer-software.github.io/bdfd-wiki/${{ env.LINK }}