-
Notifications
You must be signed in to change notification settings - Fork 6
80 lines (69 loc) · 2.47 KB
/
deploy-production.yaml
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
name: Deploy to Production
run-name: ${{ github.workflow }} - ${{ github.event_name }}
on:
push:
branches:
- main
workflow_dispatch:
env:
ARTIFACT: deployment-artifact
GHPAGES_BRANCH: gh-pages-hugo
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build Hugo Website
uses: ./.github/actions/build-hugo-website
with:
env: production
build-artifact: ${{ env.ARTIFACT }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT }}
path: ${{ env.ARTIFACT }}
retention-days: 1
# I need to checkout the ${{env.GHPAGES_BRANCH}} branch with the built website content,
# and then download the artifact from the build job into it.
# This will ultimately change/add some files — things I need to commit and push back to the branch.
# And this is where passing the artifacts between jobs makes sense.
deploy:
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Checkout the branch for website hosting
uses: actions/checkout@v4
with:
ref: '${{ env.GHPAGES_BRANCH }}'
- name: Get the new website content
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT }}
path: ./
retention-days: 1
- name: Deploy website
run: |
set -ex
if [[ -z $(git status --porcelain) ]]; then
echo "No changes to the site were detected"
else
git config user.name "$GITHUB_ACTOR"
git config user.email "${GITHUB_ACTOR}@bots.github.com"
git add -A
git commit -a -m "Website deploy — ${GITHUB_RUN_NUMBER}"
git remote set-url origin "https://x-access-token:${{ secrets.DEPLOY_TOKEN }}@github.com/vasylenko/devdosvid.blog.git"
git push --force origin ${{ env.GHPAGES_BRANCH }}
fi
purge-cache:
needs: [deploy]
runs-on: ubuntu-latest
steps:
- name: Send API request to CloudFlare
run: |
set -ex
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLAREZONEID }}/purge_cache" \
-H "Authorization: Bearer ${{ secrets.CLOUDFLAREPURGETOKEN }}" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}' | jq '.success'