forked from opensearch-project/documentation-website
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (88 loc) · 3.2 KB
/
publish_site.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
name: Publish Website
on:
workflow_dispatch:
push:
branches:
- 2.11.x-ee
pull_request:
env:
WEBSITE_URL: 'eliatra.com'
UPLOAD_DIR: 'eoed-docs.eliatra.com'
jobs:
setup:
runs-on: ubuntu-latest
outputs:
ruby-version: '3.2'
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
build:
needs: setup
runs-on: ubuntu-latest
outputs:
version: ${{ steps.config.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ needs.setup.outputs.ruby-version }}
bundler-cache: true
- id: config
name: Update _config.yml
run: |
sed -i '/^url:/c\url: "https://${{ env.WEBSITE_URL }}"' _config.yml
WEBSITE_VERSION=$(cat _config.yml | grep "^opensearch_major_minor_version:" | cut -d ':' -f2 | tr -d " '")
echo "version=$WEBSITE_VERSION" >> $GITHUB_OUTPUT
sed -i '/^baseurl:/c\baseurl: "/docs/'"$WEBSITE_VERSION"'"' _config.yml
cat _config.yml|grep -e "^url:" -e "^baseurl:"
- run: JEKYLL_FATAL_LINK_CHECKER=internal JEKYLL_ENV=production bundle exec jekyll build --future
- uses: actions/upload-artifact@v4
with:
name: site-artifacts
path: _site
retention-days: 1
deploy:
needs: build
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- uses: actions/download-artifact@v4
with:
name: site-artifacts
path: _site
- name: Install SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SFTP_SSH_PRIVATE_KEY }}
- name: Upload Folder
run: |
sudo apt install lftp -y
lftp --version
WEBSITE_VERSION=${{ needs.build.outputs.version }}
if [ -z "$WEBSITE_VERSION" ]; then
echo "WEBSITE_VERSION is empty"
exit 1
fi
echo "Start SFTP upload version: $WEBSITE_VERSION"
lftp -u ${{ secrets.SFTP_USERNAME }}, -e "set sftp:connect-program 'ssh -a -x -o StrictHostKeyChecking=no'; mkdir -p /var/www/${{ env.UPLOAD_DIR }}/html/$WEBSITE_VERSION; mirror --reverse --parallel=20 --verbose _site/ /var/www/${{ env.UPLOAD_DIR }}/html/$WEBSITE_VERSION/; quit" sftp://${{ secrets.SFTP_SERVER }}
post_deploy:
needs: deploy
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- name: Purge Cloudflare Cache
run: |
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
-X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.ELIATRA_CLOUDFLARE_ZONEID }}/purge_cache" \
-H "Authorization: Bearer ${{ secrets.ELIATRA_CLOUDFLARE_DECACHE_TOKEN }}" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}')
if [ "$STATUS_CODE" -ne 200 ]; then
echo "Cloudflare API call failed with status $STATUS_CODE"
exit 1
else
echo "Cloudflare cache purged successfully"
fi