-
-
Notifications
You must be signed in to change notification settings - Fork 59
162 lines (145 loc) · 5.73 KB
/
deploy-docs.yml
File metadata and controls
162 lines (145 loc) · 5.73 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# ==============================================================================
# HOW TO USE THIS WORKFLOW:
# ==============================================================================
# 1. PUSH TO 'main' BRANCH:
# - Automatically updates the '/main/' folder on the gh-pages branch.
# - NOTE: This only triggers if files in 'docs/' or 'mkdocs.yml' changed.
# - Use this for "Bleeding Edge" documentation.
#
# 2. PUBLISH A RELEASE:
# - Automatically creates a folder named after the tag (e.g., /v2.5.0/).
# - Automatically points the '/latest/' folder (alias) to that new tag.
# - Use this for official, stable version launches.
#
# 3. MANUAL RUN (GitHub Actions UI -> "Run workflow"):
# - "Version": The folder name you want to create or overwrite (e.g., v2.5.0).
# - "Alias": (Optional) The redirect folder you want to point to that version
# (e.g., enter 'latest' to move the latest pointer to the version above).
# - Use this to FIX an existing version folder without making a new release.
# ==============================================================================
name: Deploy Documentation
concurrency:
group: deploy-docs
cancel-in-progress: false
on:
release:
types: [published]
push:
branches:
- main
# checkov:skip=CKV_GHA_7: Inputs are validated and sanitized via regex below to prevent injection.
workflow_dispatch:
inputs:
version:
description: 'Version to deploy (e.g., v2.5.0 or main)'
required: true
default: 'main'
alias:
description: 'Alias to update (e.g., latest)'
required: false
default: ''
permissions:
contents: read
jobs:
check-for-changes:
if: github.event_name == 'push'
name: Check for changes
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.check_files.outputs.any_changed }}
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check for changed documentation files
id: check_files
uses: tj-actions/changed-files@v47
with:
files: |
docs/**
mkdocs.yml
deploy:
name: Deploy MkDocs Site
permissions:
contents: write
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [check-for-changes]
if: |
always() &&
!cancelled() &&
(github.event_name != 'push' || needs.check-for-changes.outputs.changed == 'true')
env:
CI_COMMIT_AUTHOR: 'CI Bot'
CI_COMMIT_EMAIL: 'ci@noreply.github.com'
CI_COMMIT_MESSAGE: 'Continuous Integration - Deploy Documentation'
steps:
- name: Validate Inputs
id: validation
env:
MY_VERSION: ${{ github.event.inputs.version }}
MY_ALIAS: ${{ github.event.inputs.alias }}
# language=bash
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
if [[ ! "$MY_VERSION" =~ ^[a-zA-Z0-9._-]+$ ]]; then
echo "::error::Invalid version name: $MY_VERSION. Only alphanumeric, dots, and hyphens allowed."
exit 1
fi
if [[ -n "$MY_ALIAS" && ! "$MY_ALIAS" =~ ^[a-zA-Z0-9._-]+$ ]]; then
echo "::error::Invalid alias name: $MY_ALIAS. Only alphanumeric, dots, and hyphens allowed."
exit 1
fi
fi
if [ "${{ github.event_name }}" == "release" ]; then
TARGET_REF="${{ github.event.release.tag_name }}"
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
TARGET_REF="${{ github.event.inputs.version }}"
else
TARGET_REF="${{ github.ref }}"
fi
echo "target_version=$MY_VERSION" >> "$GITHUB_OUTPUT"
echo "target_alias=$MY_ALIAS" >> "$GITHUB_OUTPUT"
echo "target_ref=$TARGET_REF" >> "$GITHUB_OUTPUT"
- name: Generate GitHub App Token
id: generate_token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout Code
uses: actions/checkout@v6
with:
token: ${{ steps.generate_token.outputs.token }}
ref: ${{ steps.validation.outputs.target_ref }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.x'
cache: 'pip'
- name: Install MkDocs and dependencies
run: pip install -r requirements.txt
- name: Deploy Docs to GitHub Pages
# language=bash
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "${{ env.CI_COMMIT_EMAIL }}"
git remote set-url origin https://x-access-token:${{ steps.generate_token.outputs.token }}@github.com/DigiLive/mushroom-strategy.git
if ! git fetch origin gh-pages --depth=1 2>/dev/null; then
echo "::notice::gh-pages branch does not exist yet. mike will create it."
fi
if [ "${{ github.event_name }}" == "release" ]; then
# Release: Create a permanent version folder and update latest alias.
mike deploy --push --update-aliases "${{ github.event.release.tag_name }}" latest
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
if [ -n "${{ steps.validation.outputs.target_alias }}" ]; then
mike deploy --push --update-aliases "${{ steps.validation.outputs.target_version }}" "${{ steps.validation.outputs.target_alias }}"
else
mike deploy --push "${{ steps.validation.outputs.target_version }}"
fi
else
# Push: Update the /main/ folder
mike deploy --push main
fi