-
Notifications
You must be signed in to change notification settings - Fork 15
67 lines (61 loc) · 2.38 KB
/
mike-redeploy.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
name: Re-deploy via mike
on:
workflow_dispatch:
inputs:
version:
description: 'The version to deploy'
required: true
default: '0.8.0'
sourceBranch:
description: 'Source Branch'
required: true
default: '0.8'
schedule:
- cron: '0 0 * * *' # Runs every day at midnight UTC
jobs:
mike-redeploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0 # Fetches all history for all branches and tags
ref: ${{ github.event_name == 'schedule' && 'main' || github.event.inputs.sourceBranch }}
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install Requirements
run: pip install -r requirements.txt
- name: Validate User Permissions
id: validate_user
run: |
if [ "${{ github.event_name }}" == "schedule" ]; then
echo "Scheduled run, bypassing user permission check."
echo "::set-output name=can_deploy::true"
else
USER_PERMISSION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/collaborators/${{ github.actor }}/permission")
echo "User permissions: $USER_PERMISSION"
if [[ "$USER_PERMISSION" =~ (\"permission\": \"admin\") ]]; then
echo "User is authorized to deploy."
echo "::set-output name=can_deploy::true"
else
echo "::error::User is not authorized to deploy."
echo "::set-output name=can_deploy::false"
fi
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Git Config
if: steps.validate_user.outputs.can_deploy == 'true'
run: |
git config --global user.name "Docs Deploy"
git config --global user.email "[email protected]"
- name: Deploy Documentation
if: steps.validate_user.outputs.can_deploy == 'true'
run: |
mkdocs build -s
mike deploy ${{ github.event_name == 'schedule' && 'dev' || github.event.inputs.version }} -t "${{ github.event_name == 'schedule' && 'dev' || github.event.inputs.version }}" --push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}