-
Notifications
You must be signed in to change notification settings - Fork 1
132 lines (112 loc) · 3.44 KB
/
generation.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
name: Code Generation
on:
workflow_dispatch:
schedule:
- cron: '*/15 * * * *'
permissions:
contents: write
pull-requests: write
jobs:
check:
name: Check for Changes
runs-on: ubuntu-latest
env:
DOCS_URL: https://core.telegram.org/bots/api
CACHE_DIR: cache
outputs:
generate: ${{ steps.check.outputs.generate }}
steps:
- name: Calculate Page Hash
id: page-hash
run: |
hash=$(curl -s "${{ env.DOCS_URL }}" | head -n -1 | sha256sum | awk '{print $1}')
echo "hash=$hash" >> "$GITHUB_OUTPUT"
- name: Setup Cache
uses: actions/cache@v4
with:
key: page-cache-${{ steps.page-hash.outputs.hash }}
path: ${{ env.CACHE_DIR }}
restore-keys: |
page-cache
- name: Check for changes
id: check
run: |
generate=false
# If no cache is available, we should generate to make sure
if [ ! -f ${{ env.CACHE_DIR }}/hash.txt ]; then
generate=true
# else we check the last hash and compare
else
last_hash=$(cat ${{ env.CACHE_DIR }}/hash.txt)
if [ "$last_hash" != "${{ steps.page-hash.outputs.hash }}" ]; then
generate=true
fi
fi
# Set cache
mkdir -p "${{ env.CACHE_DIR }}"
echo "${{ steps.page-hash.outputs.hash }}" > ${{ env.CACHE_DIR }}/hash.txt
# Set output
echo "generate=$generate" >> "$GITHUB_OUTPUT"
generate:
name: Generate Code
runs-on: ubuntu-latest
needs: check
if: needs.check.outputs.generate == 'true'
steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: composer
- name: Checkout Telepath
uses: actions/checkout@v4
with:
path: telepath
- name: Checkout Generator
uses: actions/checkout@v4
with:
repository: telepath-php/generator
path: generator
- name: Install Laravel
run: |
cd generator
composer install --no-dev
cp .env.example .env
php artisan key:generate
- name: Fetch data
id: data
run: |
cd generator
echo "version=$(php artisan docs:version)" >> "$GITHUB_ENV"
{
echo 'changelog<<END_OF_CHANGELOG'
php artisan docs:changelog
echo END_OF_CHANGELOG
} >> "$GITHUB_ENV"
- name: Generate Code
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
cd generator
php artisan generate ../telepath/src/
- name: Generate Companion App Token
id: generate-token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.COMPANION_APP_ID }}
private_key: ${{ secrets.COMPANION_APP_PRIVATE_KEY }}
- name: Commit Changes
uses: peter-evans/create-pull-request@v6
with:
token: ${{ steps.generate-token.outputs.token }}
path: telepath
branch: api-${{ env.version }}
commit-message: "Update code to reflect latest changes to the Bot API documentation"
delete-branch: true
title: "Bot API ${{ env.version }}"
body: "${{ env.changelog }}"
labels: |
Bot API
auto-generated
WTD
reviewers: TiiFuchs