Skip to content
Merged

Beta #72

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs_gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build-docs
on:
push:
branches:
- test
- beta

jobs:
build:
Expand Down
150 changes: 150 additions & 0 deletions .github/workflows/fetch_mtproto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: Check MTProto API Schema Updates

on:
schedule:
- cron: '0 */12 * * *'
workflow_dispatch:
inputs:
force_update:
description: 'Force update even if no changes detected'
required: false
default: false
type: boolean

jobs:
check-schema-updates:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'

- name: Install dependencies
run: |
pip install requests

- name: Check for API schema updates
id: check-updates
run: |
FORCE_UPDATE=""
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.force_update }}" == "true" ]]; then
FORCE_UPDATE="--force-update"
fi

python dev_tools/check_api_schema_updates.py $FORCE_UPDATE
EXIT_CODE=$?

if [ $EXIT_CODE -eq 0 ]; then
echo "updates_detected=true" >> $GITHUB_OUTPUT
CURRENT_LAYER=$(grep -o "// LAYER [0-9]*" compiler/api/source/main_api.tl | awk '{print $3}')
echo "layer_version=$CURRENT_LAYER" >> $GITHUB_OUTPUT
elif [ $EXIT_CODE -eq 2 ]; then
echo "updates_detected=false" >> $GITHUB_OUTPUT
else
echo "Error checking for updates"
exit 1
fi

- name: Set up Git config
if: steps.check-updates.outputs.updates_detected == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"

- name: Check existing PR
if: steps.check-updates.outputs.updates_detected == 'true'
id: check-pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH_NAME="update/mtproto-api-updates"

# Check if there's an open PR for this branch
PR_NUMBER=$(gh pr list --head "$BRANCH_NAME" --state open --json number -q '.[0].number')

if [ -n "$PR_NUMBER" ]; then
echo "existing_pr=true" >> $GITHUB_OUTPUT
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
else
echo "existing_pr=false" >> $GITHUB_OUTPUT
fi

- name: Compile API
if: steps.check-updates.outputs.updates_detected == 'true'
run: |
pip install .
python -m compiler.api.compiler

- name: Compile errors
if: steps.check-updates.outputs.updates_detected == 'true'
run: |
python -m compiler.errors.compiler

- name: Create branch and commit changes
if: steps.check-updates.outputs.updates_detected == 'true' && steps.check-pr.outputs.existing_pr == 'false'
run: |
LAYER_VERSION="${{ steps.check-updates.outputs.layer_version }}"
BRANCH_NAME="update/mtproto-api-updates"

git checkout -b $BRANCH_NAME
git add compiler/api/source/main_api.tl pyrogram/raw/ pyrogram/errors/
git commit -m "Update MTProto API schema to Layer ${LAYER_VERSION}"
git push origin $BRANCH_NAME

- name: Update existing branch
if: steps.check-updates.outputs.updates_detected == 'true' && steps.check-pr.outputs.existing_pr == 'true'
run: |
LAYER_VERSION="${{ steps.check-updates.outputs.layer_version }}"
BRANCH_NAME="update/mtproto-api-updates"

# Create a new branch based on the current main branch
git checkout -b $BRANCH_NAME-temp origin/main

# Add the changes and commit
git add compiler/api/source/main_api.tl pyrogram/raw/ pyrogram/errors/
git commit -m "Update MTProto API schema to Layer ${LAYER_VERSION}"

# Force push to update the branch
git push --force origin $BRANCH_NAME-temp:$BRANCH_NAME

- name: Create Pull Request
if: steps.check-updates.outputs.updates_detected == 'true' && steps.check-pr.outputs.existing_pr == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LAYER_VERSION="${{ steps.check-updates.outputs.layer_version }}"
BRANCH_NAME="update/mtproto-api-updates"
PR_TITLE="Update MTProto API schema"
PR_BODY="This PR automatically updates the MTProto API schema to Layer ${LAYER_VERSION}.\n\n- Updated main schema file\n- Recompiled raw and errors modules\n- Created news entry for changelog"

gh pr create \
--title "$PR_TITLE" \
--body "$PR_BODY" \
--base main \
--head "$BRANCH_NAME" \
--label "enhancement" \
--label "automated"

- name: Update Pull Request Title and Description
if: steps.check-updates.outputs.updates_detected == 'true' && steps.check-pr.outputs.existing_pr == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LAYER_VERSION="${{ steps.check-updates.outputs.layer_version }}"
PR_NUMBER="${{ steps.check-pr.outputs.pr_number }}"
PR_TITLE="Update MTProto API schema"
PR_BODY="This PR automatically updates the MTProto API schema to Layer ${LAYER_VERSION}.\n\n- Updated main schema file\n- Recompiled raw and errors modules\n- Created news entry for changelog"

gh pr edit $PR_NUMBER --title "$PR_TITLE" --body "$PR_BODY"

PR_COMMENT="Updated the MTProto API schema to Layer ${LAYER_VERSION}.\n\n- Updated main schema file\n- Recompiled raw and errors modules\n- Added new news entry for changelog"
gh pr comment $PR_NUMBER --body "$PR_COMMENT"
2 changes: 1 addition & 1 deletion .github/workflows/format_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Format and test code with uv
on:
push:
branches:
- test
- beta

jobs:
lint-format-and-test:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tag_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Auto Tag and Upload Python Package
on:
push:
branches:
- dev
- main
workflow_dispatch:

jobs:
Expand Down
Loading
Loading