Code Generation #19315
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |