1- name : Increment rev tag and notify chat
1+ name : Increment rev tag and notify Telegram
22on :
33 push :
44 branches :
77permissions :
88 contents : write
99
10- env :
11- # URL templates used in message formatting
12- REPO_URL : https://github.com/${{ github.repository }}
13- TAG_URL_PREFIX : https://github.com/${{ github.repository }}/releases/tag
14- COMMIT_URL_PREFIX : https://github.com/${{ github.repository }}/commit
15-
1610jobs :
17- rev_and_notify :
11+ increment-and-notify :
1812 runs-on : ubuntu-latest
1913 steps :
2014 - name : Checkout pushed ref (full)
@@ -27,37 +21,35 @@ jobs:
2721 git config user.name "github-actions[bot]"
2822 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
2923
30- - name : Find latest rev tag (by name )
31- id : find_latest_by_name
24+ - name : Find latest rev tag (by ref sort )
25+ id : find_latest
3226 run : |
33- # Pattern: rev-<number>, sort by semver-ish refname
27+ # Pattern: rev-<number>
3428 latest=$(git tag --list 'rev-*' --sort=-v:refname | head -n1 || true)
3529 if [ -z "$latest" ]; then
3630 echo "::set-output name=latest::"
3731 echo "::set-output name=num::"
3832 else
3933 num=${latest#rev-}
40- if echo "$num" | grep -Eq '^[0-9]+$'; then
41- echo "::set-output name=latest::$latest"
42- echo "::set-output name=num::$num"
43- else
44- echo "::set-output name=latest::"
45- echo "::set-output name=num::"
46- fi
34+ echo "::set-output name=latest::$latest"
35+ echo "::set-output name=num::$num"
4736 fi
4837
4938 - name : Determine next rev number
5039 id : next_rev
5140 run : |
52- latest="${{ steps.find_latest_by_name .outputs.latest }}"
53- num="${{ steps.find_latest_by_name .outputs.num }}"
41+ latest="${{ steps.find_latest .outputs.latest }}"
42+ num="${{ steps.find_latest .outputs.num }}"
5443 if [ -z "$latest" ]; then
5544 next=1
5645 else
57- next=$((num + 1))
46+ if echo "$num" | grep -Eq '^[0-9]+$'; then
47+ next=$((num + 1))
48+ else
49+ next=1
50+ fi
5851 fi
5952 tag="rev-${next}"
60- echo "Next tag will be: $tag"
6153 echo "::set-output name=tag::$tag"
6254 echo "::set-output name=number::$next"
6355
@@ -66,15 +58,12 @@ jobs:
6658 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
6759 run : |
6860 tag="${{ steps.next_rev.outputs.tag }}"
69- sha="${GITHUB_SHA}"
70- echo "Creating tag $tag at $sha"
71- # Annotated tag to carry message/author metadata
72- git tag -a "$tag" -m "Incremented rev to $tag" "$sha"
73- # Push tag using token auth (explicit URL avoids default remote issues)
61+ echo "Creating tag $tag at $GITHUB_SHA"
62+ git tag "$tag" "$GITHUB_SHA"
7463 git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" "refs/tags/${tag}"
7564
76- - name : Find latest rev tag (by creation date)
77- id : latest_by_date
65+ - name : Find latest rev tag (by creation date for notification )
66+ id : latest_for_notify
7867 run : |
7968 # find latest rev-* tag by creation date; leave empty if none
8069 entry=$(git for-each-ref --sort=-creatordate --format='%(refname:short) %(creatordate:unix)' refs/tags | grep '^rev-[0-9]\+' | head -n1 || true)
@@ -88,61 +77,19 @@ jobs:
8877 echo "::set-output name=ts::$ts"
8978 fi
9079
91- - name : Build Telegram message (HTML)
80+ - name : Build Telegram message
9281 id : message
9382 run : |
9483 repo="${GITHUB_REPOSITORY}"
95- repo_url="${REPO_URL}"
96- branch="${GITHUB_REF#refs/heads/}"
97- sha_full="${GITHUB_SHA}"
98- sha_short="${sha_full::7}"
99- author="$(git --no-pager show -s --format='%an' $GITHUB_SHA || echo '')"
100- commit_msg="$(git --no-pager show -s --format='%s' $GITHUB_SHA || echo '')"
101- latest_tag="${{ steps.latest_by_date.outputs.tag }}"
102- # Resolve URLs; if tag created in this run use that tag, else use latest_by_date
103- # Prefer the tag we just created (next_rev) to avoid mismatch
104- created_tag="${{ steps.next_rev.outputs.tag }}"
105- chosen_tag="${created_tag:-$latest_tag}"
106- # Build clickable HTML pieces (Telegram supports basic HTML)
107- repo_html="<a href=\"${repo_url}\">${repo}</a>"
108- commit_url="${COMMIT_URL_PREFIX}/${sha_full}"
109- commit_html="<a href=\"${commit_url}\">${sha_short}</a>"
110- if [ -n "$chosen_tag" ]; then
111- tag_url="${TAG_URL_PREFIX}/${chosen_tag}"
112- tag_html="<a href=\"${tag_url}\">${chosen_tag}</a>"
113- tag_text="Rev: ${tag_html}"
114- else
115- tag_text="Rev: (none)"
116- fi
117- # Escape special HTML chars in author and commit_msg
118- esc_author=$(printf '%s' "$author" | sed 's/&/\&/g; s/</\</g; s/>/\>/g')
119- esc_msg=$(printf '%s' "$commit_msg" | sed 's/&/\&/g; s/</\</g; s/>/\>/g')
120- body="Repo: ${repo_html}%0ABranch: ${branch}%0ACommit: ${commit_html}%0AAuthor: ${esc_author}%0AMessage: ${esc_msg}%0A${tag_text}"
121- echo "body<<EOF" >> $GITHUB_OUTPUT
122- echo "${body}" >> $GITHUB_OUTPUT
123- echo "EOF" >> $GITHUB_OUTPUT
124-
125- - name : Preview Telegram message (log)
126- if : always()
127- run : |
128- # Show a human-readable preview (unescaped)
129- repo="${GITHUB_REPOSITORY}"
130- repo_url="${REPO_URL}"
13184 branch="${GITHUB_REF#refs/heads/}"
13285 sha_full="${GITHUB_SHA}"
133- sha_short ="${sha_full::7}"
86+ sha ="${sha_full::7}"
13487 author="$(git --no-pager show -s --format='%an' $GITHUB_SHA || echo '')"
135- commit_msg="$(git --no-pager show -s --format='%s' $GITHUB_SHA || echo '')"
136- chosen_tag="${{ steps.next_rev.outputs.tag }}"
137- tag_display="${chosen_tag:-(none)}"
138- echo "---- Telegram message preview ----"
139- echo "Repo: ${repo} (${repo_url})"
140- echo "Branch: ${branch}"
141- echo "Commit: ${sha_short} (${COMMIT_URL_PREFIX}/${sha_full})"
142- echo "Author: ${author}"
143- echo "Message: ${commit_msg}"
144- echo "Rev: ${tag_display} (${TAG_URL_PREFIX}/${tag_display})"
145- echo "----------------------------------"
88+ msg="$(git --no-pager show -s --format='%s' $GITHUB_SHA || echo '')"
89+ latest_tag="${{ steps.latest_for_notify.outputs.tag }}"
90+ tag_part="Rev: ${latest_tag:-(none)}"
91+ body="Repo: ${repo}%0ABranch: ${branch}%0ACommit: ${sha}%0AAuthor: ${author}%0AMessage: ${msg}%0A${tag_part}"
92+ echo "::set-output name=body::$body"
14693
14794 - name : Send Telegram notification
14895 env :
@@ -154,7 +101,6 @@ jobs:
154101 exit 0
155102 fi
156103 body="${{ steps.message.outputs.body }}"
157- # Send message as HTML to enable clickable links
158104 curl -sS --fail -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
159105 -d "chat_id=${TELEGRAM_CHAT_ID}" \
160106 -d "text=${body}" \
0 commit comments