-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (84 loc) · 3.03 KB
/
deploy.yml
File metadata and controls
102 lines (84 loc) · 3.03 KB
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
name: Deploy MkDocs Page with Mike
on:
push:
tags:
- "v*.*.*"
- "v*.*.*.doc.*"
workflow_dispatch:
inputs:
version:
description: "Version tag to deploy (e.g., v1.2.0.doc.1)"
required: true
type: string
permissions:
contents: write
jobs:
publish:
runs-on: ubuntu-latest
environment:
name: github-pages
url: https://open-ev-data.github.io
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.version || github.ref }}
fetch-depth: 0
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- name: Fetch gh-pages Branch
run: |
git fetch origin gh-pages --depth=1 || echo "gh-pages branch does not exist yet"
git branch gh-pages origin/gh-pages 2>/dev/null || echo "Creating new gh-pages branch"
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Poetry
run: pip install poetry
- name: Install Dependencies
run: poetry install --no-root
- name: Extract Version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ inputs.version }}"
else
TAG=${GITHUB_REF##*/}
fi
if [[ $TAG =~ ^v([0-9]+\.[0-9]+)\.[0-9]+\.doc\.[0-9]+$ ]]; then
VERSION="${BASH_REMATCH[1]}.x"
elif [[ $TAG =~ ^v([0-9]+\.[0-9]+)\.[0-9]+$ ]]; then
VERSION="${BASH_REMATCH[1]}.x"
else
echo "Error: Tag format not recognized: $TAG"
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "TAG=$TAG" >> $GITHUB_ENV
echo "Deploying version: $VERSION (from tag: $TAG)"
- name: Deploy MkDocs using Mike
env:
GOOGLE_ANALYTICS_KEY: ${{ secrets.GOOGLE_ANALYTICS_KEY }}
run: |
poetry run mike delete dev || true
poetry run mike delete latest || true
poetry run mike deploy --update-aliases ${VERSION} latest
poetry run mike set-default latest
- name: Update Root Files (Verification + Robots.txt)
run: |
git checkout gh-pages
# Copy verification file if exists
cp ${VERSION}/googleb888a8ce45bda477.html . || echo "Verification file not found in version, skipping"
# Generate robots.txt
echo "User-agent: *" > robots.txt
echo "Sitemap: https://open-ev-data.github.io/latest/sitemap.xml" >> robots.txt
git add googleb888a8ce45bda477.html robots.txt
git commit -m "chore: update root files (verification + robots.txt)" || echo "No changes to commit"
- name: Push Changes
run: |
git push origin gh-pages