-
Notifications
You must be signed in to change notification settings - Fork 4
125 lines (120 loc) · 4.48 KB
/
gh-pages.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
name: GitHub Pages
on:
push:
branches: ["*"]
delete:
branches: ["*"]
env:
GITHUB_PAGES_BRANCH: "gh-pages"
GITHUB_PAGES_ROOT_DIR: "./gh-pages-root"
BUILD_DIR: "./build"
REPO_NAME: 'folkebibliotekernes_cms_manual'
PREVIEW_SUBDIR: 'preview'
permissions:
contents: write
deployments: write
jobs:
build:
name: "Build and deploy Jekyll site"
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare documentation root
run: |
mkdir -p ${{ env.GITHUB_PAGES_ROOT_DIR }}
echo "<!DOCTYPE html>
<html>
<head><meta http-equiv=\"refresh\" content=\"0; url='./main/'\" /></head>
<body><p>You will be redirected to the documentation</p></body>
</html>" > ${{ env.GITHUB_PAGES_ROOT_DIR }}/index.html
- name: Deploy documentation root
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: ${{ env.GITHUB_PAGES_BRANCH }}
publish_dir: ${{ env.GITHUB_PAGES_ROOT_DIR }}
destination_dir: "."
keep_files: true
commit_message: "Create root index.html"
- name: Get branch names
id: branch-name
uses: tj-actions/branch-names@v7
- name: Set GitHub Pages directory
id: github-pages
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "directory=main" >> $GITHUB_OUTPUT
echo "url=https://${{ github.repository_owner }}.github.io/${{ env.REPO_NAME }}/main" >> $GITHUB_OUTPUT
else
echo "directory=preview/${{ steps.branch-name.outputs.current_branch }}" >> $GITHUB_OUTPUT
echo "url=https://${{ github.repository_owner }}.github.io/${{ env.REPO_NAME }}/${{ env.PREVIEW_SUBDIR }}/${{ steps.branch-name.outputs.current_branch }}" >> $GITHUB_OUTPUT
fi
- name: Configure GitHub Pages
id: pages
uses: actions/configure-pages@v3
- name: Set Jekyll base url
uses: fjogeleit/yaml-update-action@main
with:
valueFile: '_config.yml'
propertyPath: 'baseurl'
value: '/${{ steps.github-pages.outputs.directory }}'
commitChange: false
- name: Build Jekyll site
uses: actions/jekyll-build-pages@v1
with:
destination: ${{ env.BUILD_DIR }}
- name: Start deployment
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: ${{ steps.branch-name.outputs.current_branch }}
- name: Deploy Jekyll site to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: ${{ env.GITHUB_PAGES_BRANCH }}
publish_dir: ${{ env.BUILD_DIR }}
destination_dir: ${{ steps.github-pages.outputs.directory }}
enable_jekyll: false
commit_message: "Create/update Jekyll site for ${{ steps.branch-name.outputs.current_branch }}"
- name: Wait for deployment to become available
uses: iFaxity/wait-on-action@v1
with:
resource: ${{ steps.github-pages.outputs.url }}
- name: Update deployment status
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
env: ${{ steps.deployment.outputs.env }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: ${{ steps.github-pages.outputs.url }}
delete:
name: "Cleanup preview"
if: github.event_name == 'delete'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_PAGES_BRANCH }}
# We cannot use tj-actions/branch-names to get the name of the deleted
# branch as it will already be deleted when this runs.
- name: Delete preview site
run: |
rm -rf ${{ env.PREVIEW_SUBDIR }}/${{ github.event.ref }}
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Delete preview Jekyll site for ${{ github.event.ref }}"
- name: Deactivate environment
uses: bobheadxi/deployments@v1
with:
step: deactivate-env
token: ${{ secrets.GITHUB_TOKEN }}
env: ${{ github.event.ref }}