Path: Fix tests #90
This file contains hidden or 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: Increment rev tag and notify Telegram | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| jobs: | |
| increment-and-notify: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout pushed ref (full) | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure git user | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| - name: Check if push is a PR branch | |
| id: pr_check | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| BRANCH: ${{ github.ref_name }} | |
| run: | | |
| count=$(gh pr list --head "$BRANCH" --state open --json number --jq '. | length' 2>/dev/null || echo 0) | |
| if [ "$count" -gt 0 ]; then | |
| echo "is_pr=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "is_pr=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Find latest rev tag | |
| id: find_latest | |
| run: | | |
| latest=$(git tag --list 'rev-*' --sort=-v:refname | head -n1 || true) | |
| if [ -z "$latest" ]; then | |
| echo "latest=" >> "$GITHUB_OUTPUT" | |
| echo "num=" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "latest=$latest" >> "$GITHUB_OUTPUT" | |
| echo "num=${latest#rev-}" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Determine next rev number | |
| id: next_rev | |
| run: | | |
| num="${{ steps.find_latest.outputs.num }}" | |
| if echo "$num" | grep -Eq '^[0-9]+$'; then | |
| next=$((num + 1)) | |
| else | |
| next=1 | |
| fi | |
| echo "tag=rev-${next}" >> "$GITHUB_OUTPUT" | |
| echo "number=${next}" >> "$GITHUB_OUTPUT" | |
| - name: Create and push rev tag | |
| if: steps.pr_check.outputs.is_pr != 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| tag="${{ steps.next_rev.outputs.tag }}" | |
| git tag "$tag" "$GITHUB_SHA" | |
| git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" "refs/tags/${tag}" | |
| echo "Created tag: $tag" | |
| - name: Build Telegram message | |
| id: message | |
| env: | |
| BEFORE: ${{ github.event.before }} | |
| AFTER: ${{ github.event.after }} | |
| IS_PR: ${{ steps.pr_check.outputs.is_pr }} | |
| REV_TAG: ${{ steps.next_rev.outputs.tag }} | |
| run: | | |
| branch="${GITHUB_REF#refs/heads/}" | |
| repo="${GITHUB_REPOSITORY}" | |
| repo_url="https://github.com/${repo}" | |
| zero="0000000000000000000000000000000000000000" | |
| esc() { printf '%s' "$1" | sed 's/&/\&/g; s/</\</g; s/>/\>/g'; } | |
| # Build per-commit lines with links | |
| make_lines() { | |
| while IFS='|' read -r sha subject author; do | |
| short="${sha:0:7}" | |
| printf '• <a href="%s/commit/%s">%s</a> %s (%s)\n' \ | |
| "$repo_url" "$sha" "$short" "$(esc "$subject")" "$(esc "$author")" | |
| done | |
| } | |
| if [ "$BEFORE" = "$zero" ] || [ -z "$BEFORE" ]; then | |
| commits=$(git --no-pager log -5 --reverse --format="%H|%s|%an" | make_lines) | |
| else | |
| commits=$(git --no-pager log --reverse --format="%H|%s|%an" \ | |
| "${BEFORE}..${AFTER}" 2>/dev/null | make_lines) | |
| fi | |
| if [ "$IS_PR" = "true" ]; then | |
| rev_line="Rev: (PR branch — no tag created)" | |
| else | |
| rev_line="Rev: <b>$(esc "$REV_TAG")</b>" | |
| fi | |
| header="<b>$(esc "$repo") [$(esc "$branch")]</b>" | |
| full="${header}"$'\n'"${rev_line}"$'\n\n'"${commits}" | |
| # Telegram HTML limit is 4096 chars — stay safely under it | |
| limit=3800 | |
| if [ "${#full}" -gt "$limit" ]; then | |
| full="${full:0:$limit}"$'\n'"...(truncated)" | |
| fi | |
| { | |
| echo 'msg<<__DELIM__' | |
| printf '%s\n' "$full" | |
| echo '__DELIM__' | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Send Telegram notification | |
| env: | |
| TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
| TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} | |
| MSG: ${{ steps.message.outputs.msg }} | |
| run: | | |
| if [ -z "${TELEGRAM_BOT_TOKEN}" ] || [ -z "${TELEGRAM_CHAT_ID}" ]; then | |
| echo "Missing TELEGRAM_BOT_TOKEN or TELEGRAM_CHAT_ID — skipping." | |
| exit 0 | |
| fi | |
| curl -sS --fail -X POST \ | |
| "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ | |
| -d "chat_id=${TELEGRAM_CHAT_ID}" \ | |
| -d "parse_mode=HTML" \ | |
| --data-urlencode "text=${MSG}" |