-
Notifications
You must be signed in to change notification settings - Fork 2
139 lines (135 loc) · 5.12 KB
/
build_full_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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# This file is part of pydidas.
#
# Copyright 2024, Helmholtz-Zentrum Hereon
# SPDX-License-Identifier: CC-BY-4.0
#
# This workflow will check the formatting of the newly pushed commits
# to verify that all files are corretly formatted.
name: Build GitHub-pages
on:
push:
branches:
- "master"
tags:
- "v*"
jobs:
create_docs:
runs-on: ubuntu-latest
env:
CI_COMMIT_MESSAGE: Continuous Integration Build Artifacts
CI_COMMIT_AUTHOR: Continuous Integration
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Echo fetched ref
run: |
echo "Fetched ref: ${{ github.ref }}"
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Configure local git
run: |
echo "COMMIT_EMAIL=$(git log -1 --pretty=format:'%ae')" >> $GITHUB_ENV
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${{env.COMMIT_EMAIL}}"
- name: Install dependencies
run: |
python -m pip cache purge
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: Extract version
id: extract_version
run: |
export QT_QPA_PLATFORM=offscreen
if [[ ${{ github.ref }} == refs/tags/* ]]; then
# need the first 'dummy' echo to set up pydidas
echo $(python -c "import pydidas" --no-sphinx)
{
echo $(python -c "from pydidas import VERSION; print(f'THIS_VERSION={VERSION}')" --no-sphinx)
} >> $GITHUB_OUTPUT
elif [[ ${{ github.ref }} == refs/heads/* ]]; then
echo "THIS_VERSION=dev" >> $GITHUB_OUTPUT
else
exit 1
fi
- name: Fetch stable_version
id: fetch_stable_version
run: |
git fetch origin gh-pages-version-snapshots:gh-pages-version-snapshots
git checkout gh-pages-version-snapshots -- stable_version.txt
echo "STABLE_VERSION=$(cat stable_version.txt)" >> $GITHUB_OUTPUT
rm stable_version.txt
- name: Verify tagged version has a new version tag
id: check_version_tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
if [[ ${{ steps.extract_version.outputs.THIS_VERSION }} == ${{ steps.fetch_stable_version.outputs.STABLE_VERSION }} ]]; then
echo "The pydidas.version for the new git tag is the same as the stable version. Please update the version in pydidas" >> $GITHUB_STEP_SUMMARY
exit 1
fi
- name: Set stable version if a new release tag is pushed
run: |
if [[ ${{ github.ref }} == refs/tags/* ]]; then
echo "${{ steps.extract_version.outputs.THIS_VERSION }}" > stable_version.txt
else
git fetch origin gh-pages-version-snapshots:gh-pages-version-snapshots
git checkout gh-pages-version-snapshots -- stable_version.txt
fi
- name: Sphinx build
run: |
export QT_QPA_PLATFORM=offscreen
sphinx-build src/pydidas/docs/src versions/${{ steps.extract_version.outputs.THIS_VERSION }}
- name: Create temporary branch for gh-pages-output
run: |
git checkout -b __temp-gh-pages
git add versions/${{ steps.extract_version.outputs.THIS_VERSION }}
git add stable_version.txt
git commit -m "Add temporary gh-pages."
- name: Merge latest version into gh-pages-versions-snapshot
run: |
git checkout gh-pages-version-snapshots
git checkout __temp-gh-pages -- versions/${{ steps.extract_version.outputs.THIS_VERSION }}
git checkout __temp-gh-pages -- stable_version.txt
git add versions/${{ steps.extract_version.outputs.THIS_VERSION }}
git add stable_version.txt
git commit -m "Add gh-pages for version ${{ steps.extract_version.outputs.THIS_VERSION }}"
git push origin gh-pages-version-snapshots
- name: Update pydata version switcher
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
python update_pydata_version_switcher.py --new-version
git add pydata_version_switcher.json
git commit -m "Added version ${{ steps.extract_version.outputs.THIS_VERSION }} to pydata_version_switcher.json"
git push origin gh-pages-version-snapshots
- name: Remove temporary branch
run: |
git branch -D __temp-gh-pages
- name: Copy full docs into _site folder
run: |
mkdir -p _site
cp -r versions _site/versions
export STABLE_VER=$(cat stable_version.txt)
cp -r versions/${STABLE_VER}/* _site/
- name: Set permissions
run: |
chmod -c -R +rX "versions/" | while read line; do
echo "::warning title=Invalid file permissions automatically fixed::$line"
done
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v2
deploy_docs:
needs: create_docs
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: _site
runs-on: ubuntu-latest
steps:
- name: Deploy to Github Pages
id: deployment
uses: actions/deploy-pages@v3