mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-10-12 00:45:02 +00:00
* ci(workflows): migrate to shared go-pr and go-release workflows Replace the generic vet, staticcheck, govulncheck, gosec, test and release jobs with the shared go-pr and go-release workflows. Keep the codegen-clean and audit jobs in ci.yml. Add an examples build job and the ci-success aggregator there. Add autoupdate.yaml from the shared go-autoupdate workflow. The release job now runs only on Go source changes and on manual dispatch. The dry-run input and the Bot API note in the tag message no longer exist. * ci(release): gate release on repo checks and export Bot API version Move the codegen-clean, audit and examples jobs into the reusable checks.yml workflow. The ci.yml and release.yml workflows both call it. The release job now needs the checks job. A failed or cancelled check blocks the release. Add workflow-prepare.sh. It appends BOT_API_VERSION to GITHUB_ENV so the GoReleaser header shows the Bot API version. The script does nothing when GITHUB_ENV is unset. * ci(regen): name release.yml in the merge step comments The release now runs from release.yml. The comments still named ci.yml as the workflow that cuts the release.
141 lines
5.0 KiB
YAML
141 lines
5.0 KiB
YAML
name: regen
|
|
|
|
on:
|
|
schedule:
|
|
- cron: "0 6 * * 1" # Monday 06:00 UTC
|
|
workflow_dispatch: {}
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
regen:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
with:
|
|
fetch-depth: 0 # full history so audit -drift can compare against main
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v6
|
|
with:
|
|
go-version: '1.25.x'
|
|
check-latest: true
|
|
|
|
- name: Capture latest snapshot
|
|
id: snapshot
|
|
run: |
|
|
DATE=$(date +%Y-%m-%d)
|
|
DEST="testdata/html/snapshot_${DATE}.html"
|
|
curl -fsSL --user-agent "go-telegram codegen scraper" \
|
|
https://core.telegram.org/bots/api -o "$DEST.tmp"
|
|
# The page ends with a "<!-- page generated in NN.NNms -->" comment
|
|
# that changes on every fetch. Drop it, so an unchanged API produces
|
|
# a byte-identical snapshot instead of a no-op update PR.
|
|
sed '/<!-- page generated in .*ms -->/d' "$DEST.tmp" > "$DEST"
|
|
rm "$DEST.tmp"
|
|
ln -sf "snapshot_${DATE}.html" testdata/html/latest.html
|
|
echo "date=$DATE" >> $GITHUB_OUTPUT
|
|
echo "dest=$DEST" >> $GITHUB_OUTPUT
|
|
|
|
- name: Regenerate (scrape + emit, with clean-generated)
|
|
# `make regen` depends on `clean-generated`, which sweeps any orphan
|
|
# api/*.gen.go files left behind by removed/renamed methods.
|
|
run: make regen
|
|
|
|
- name: Audit fallbacks
|
|
id: audit
|
|
run: |
|
|
set +e
|
|
OUT=$(make audit 2>&1)
|
|
STATUS=$?
|
|
set -e
|
|
echo "$OUT"
|
|
{
|
|
echo 'output<<EOF'
|
|
echo "$OUT"
|
|
echo 'EOF'
|
|
} >> $GITHUB_OUTPUT
|
|
echo "status=$STATUS" >> $GITHUB_OUTPUT
|
|
# Don't fail the workflow on fallbacks — surface them in the PR body so
|
|
# the reviewer can extend overrides.json or fix scraper patterns.
|
|
|
|
- name: Audit drift vs main
|
|
id: drift
|
|
run: |
|
|
set +e
|
|
DRIFT=$(go run ./cmd/audit -ir internal/spec/api.json -drift -against origin/main 2>&1)
|
|
set -e
|
|
echo "$DRIFT"
|
|
{
|
|
echo 'output<<EOF'
|
|
echo "$DRIFT"
|
|
echo 'EOF'
|
|
} >> $GITHUB_OUTPUT
|
|
|
|
- name: Run tests
|
|
run: go test -race ./...
|
|
|
|
- name: Detect changes
|
|
id: diff
|
|
run: |
|
|
git status --porcelain
|
|
# Gate on the generated surface only. A fresh snapshot file and the
|
|
# latest.html symlink flip every run, so including testdata/html/
|
|
# here would open a PR on a week when Telegram changed nothing.
|
|
if git diff --quiet internal/spec/api.json api/ docs/reference/; then
|
|
echo "no_changes=true" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Read API version
|
|
if: steps.diff.outputs.no_changes != 'true'
|
|
id: meta
|
|
run: |
|
|
VERSION=$(python3 -c 'import json; print(json.load(open("internal/spec/api.json")).get("version", "unknown"))')
|
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Open PR
|
|
id: pr
|
|
if: steps.diff.outputs.no_changes != 'true'
|
|
uses: peter-evans/create-pull-request@v8
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
commit-message: |
|
|
chore(api): regenerate from Telegram Bot API v${{ steps.meta.outputs.version }}
|
|
branch: regen/api-v${{ steps.meta.outputs.version }}
|
|
title: "chore(api): regenerate from Telegram Bot API v${{ steps.meta.outputs.version }}"
|
|
labels: automated, api-update
|
|
body: |
|
|
Automated regeneration from `https://core.telegram.org/bots/api`.
|
|
|
|
**API version:** v${{ steps.meta.outputs.version }}
|
|
**Snapshot date:** ${{ steps.snapshot.outputs.date }}
|
|
|
|
## Audit (fallbacks)
|
|
```
|
|
${{ steps.audit.outputs.output }}
|
|
```
|
|
|
|
## Drift vs `main`
|
|
```
|
|
${{ steps.drift.outputs.output }}
|
|
```
|
|
|
|
Inspect the IR diff (`internal/spec/api.json`) for added/changed/removed methods.
|
|
|
|
This PR merges itself once every step above passes. The gates are
|
|
`make regen` (which fails on any audit fallback) and `go test -race ./...`,
|
|
both run in this job before the PR opens.
|
|
|
|
# A PR opened with GITHUB_TOKEN does not trigger `ci.yml` or `pr.yaml`, so waiting for
|
|
# PR checks would wait forever. The gates already ran in this job: `make
|
|
# regen` fails on any audit fallback, and the test step runs the full race
|
|
# suite. Merging here therefore means "merged because the checks passed".
|
|
# `release.yml` then runs on the push to main and cuts the release.
|
|
- name: Merge regen PR
|
|
if: steps.diff.outputs.no_changes != 'true' && steps.pr.outputs.pull-request-number != ''
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: gh pr merge "${{ steps.pr.outputs.pull-request-number }}" --squash --delete-branch
|