-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (148 loc) · 5.71 KB
/
generate.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Generate website
on:
workflow_dispatch:
inputs:
site_name:
type: string
required: true
description: "The name of the site"
site_url:
type: string
required: true
description: "The url of the site"
site_description:
type: string
required: true
description: "The description of the site"
site_author:
type: string
required: true
description: "The author of the site"
language:
type: string
required: true
description: "The language of the site"
auto_h1:
type: boolean
required: false
description: "Automatically add h1 to pages"
default: false
comments:
type: boolean
required: false
description: "Enable comments"
default: false
auto_merge:
description: "Automatically merge the pull request"
required: false
default: false
type: boolean
submodule:
description: If you use submodule for the docs, set this to true
required: false
default: false
type: boolean
permissions:
contents: write
pull-requests: write
jobs:
generate:
runs-on: ubuntu-latest
steps:
- name: Print github.event.inputs
run: |
echo "📫 Commands arguments" >> $GITHUB_STEP_SUMMARY
echo "- site_name: ${{ github.event.inputs.site_name }}" >> $GITHUB_STEP_SUMMARY
echo "- site_url: ${{ github.event.inputs.site_url }}" >> $GITHUB_STEP_SUMMARY
echo "- site_description: ${{ github.event.inputs.site_description }}" >> $GITHUB_STEP_SUMMARY
echo "- site_author: ${{ github.event.inputs.site_author }}" >> $GITHUB_STEP_SUMMARY
echo "- language: ${{ github.event.inputs.language }}" >> $GITHUB_STEP_SUMMARY
echo "- auto_h1: ${{ github.event.inputs.auto_h1 }}" >> $GITHUB_STEP_SUMMARY
echo "- comments: ${{ github.event.inputs.comments }}" >> $GITHUB_STEP_SUMMARY
echo "- Submodule: ${{ github.event.inputs.submodule }}" >> $GITHUB_STEP_SUMMARY
- name: checkout repo
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Install python
run: uv python install
- name: Install dependencies
run: uv sync
- name: Format arguments
id: args
run:
|
auto_h1=''
comments=''
submodule=''
if [ "${{ github.event.inputs.auto_h1 }}" = "true" ]; then
auto_h1='--auto-h1'
fi
if [ "${{ github.event.inputs.comments }}" = "true" ]; then
comments='--comments'
fi
if [ "${{ github.event.inputs.submodule }}" = "true" ]; then
submodule='--submodule'
fi
echo "auto_h1=$auto_h1" >> $GITHUB_OUTPUT
echo "comments=$comments" >> $GITHUB_OUTPUT
echo "submodule=$submodule" >> $GITHUB_OUTPUT
echo "- auto_h1: $auto_h1" >> $GITHUB_STEP_SUMMARY
echo "- comments: $comments" >> $GITHUB_STEP_SUMMARY
echo "- submodule: $submodule" >> $GITHUB_STEP_SUMMARY
- name: Generate files
run: |
echo "📝 Generate files"
pwd
ls *.py
echo "📝 Generate files" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
uv run python generate_template.py "${{github.event.inputs.site_name}}" "${{github.event.inputs.site_url}}" "${{github.event.inputs.site_description}}" "${{github.event.inputs.site_author}}" "${{github.event.inputs.language}}" ${{ steps.args.outputs.auto_h1 }} ${{ steps.args.outputs.comments }} ${{steps.args.outputs.submodule}} >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: Pull Request
id: cpr
uses: peter-evans/create-pull-request@v5
with:
commit-message: Generating template
title: "First commit -- Generate template"
body: |
📫 Commands arguments
- site_name: ${{ github.event.inputs.site_name }}
- site_url: ${{ github.event.inputs.site_url }}
- site_description: ${{ github.event.inputs.site_description }}
- site_author: ${{ github.event.inputs.site_author }}
- language: ${{ github.event.inputs.language }}
- auto_h1: ${{ github.event.inputs.auto_h1 }}
- comments: ${{ github.event.inputs.comments }}
- Generated by [Create Pull Request](https://github.com/peter-evans/create-pull-request)
labels: |
generate
branch: generate
base: "main"
delete-branch: true
token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
- name: AutoMerging
id: automerge
if: ${{ inputs.AUTO_MERGE }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
run: |
gh pr merge ${{ steps.cpr.outputs.pull-request-number }} --squash
echo "Pull Request merged"
echo "done=true" >> $GITHUB_OUTPUT
- name: Delete update branch if possible
if: ${{ inputs.AUTO_MERGE && steps.automerge.outputs.done == 'true' }}
run: |
# verify if the branch exists
if [[ $(git ls-remote --heads origin generate | wc -l) -eq 1 ]]; then
git push origin --delete generate
fi
- name: deploy
if: ${{ inputs.AUTO_MERGE && steps.automerge.outputs.done == 'true' }}
run: |
echo "Deploying"
uv run mkdocs gh-deploy --force