name: Release
on:
push:
tags:
- "v*"
jobs:
checks:
uses: ./.github/workflows/reusable-ci.yml
secrets: inherit
with:
all-features: true
publish:
runs-on: ubuntu-latest
needs: checks
steps:
- uses: actions/checkout@v6
- name: Read MSRV from Cargo.toml
id: msrv
shell: bash
run: |
set -euo pipefail
if ! command -v jq >/dev/null 2>&1; then
sudo apt-get update -y && sudo apt-get install -y jq
fi
PKG_NAME="telegram-webapp-sdk"
METADATA=$(cargo metadata --no-deps --format-version=1)
if ! printf '%s\n' "$METADATA" | jq -e --arg name "$PKG_NAME" '.packages[] | select(.name == $name)' >/dev/null; then
echo "Package ${PKG_NAME} not found in Cargo metadata"
exit 1
fi
RV=$(printf '%s\n' "$METADATA" | jq -r --arg name "$PKG_NAME" '.packages[] | select(.name == $name) | .rust_version // empty')
if [ -z "$RV" ]; then
echo "rust-version is not set in Cargo.toml for package ${PKG_NAME}"
exit 1
fi
if [[ "$RV" =~ ^[0-9]+\.[0-9]+$ ]]; then
RV="${RV}.0"
fi
echo "msrv=${RV}" >> "$GITHUB_OUTPUT"
- name: Ensure tag matches Cargo.toml version
shell: bash
run: |
set -euo pipefail
TAG="${GITHUB_REF#refs/tags/}"
PKG_NAME="telegram-webapp-sdk"
METADATA=$(cargo metadata --no-deps --format-version=1)
if ! printf '%s\n' "$METADATA" | jq -e --arg name "$PKG_NAME" '.packages[] | select(.name == $name)' >/dev/null; then
echo "Package ${PKG_NAME} not found in Cargo metadata"
exit 1
fi
FILE_VER=$(printf '%s\n' "$METADATA" | jq -r --arg name "$PKG_NAME" '.packages[] | select(.name == $name) | .version // empty')
if [ -z "$FILE_VER" ]; then
echo "version is not set in Cargo.toml for package ${PKG_NAME}"
exit 1
fi
if [ "v${FILE_VER}" != "${TAG}" ]; then
echo "Tag ${TAG} != Cargo.toml version v${FILE_VER}"
exit 1
fi
- name: Install Rust (${{ steps.msrv.outputs.msrv }})
uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ steps.msrv.outputs.msrv }}
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo +${{ steps.msrv.outputs.msrv }} publish --locked --token "$CARGO_REGISTRY_TOKEN"
release:
runs-on: ubuntu-latest
needs: publish
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install git-cliff
uses: taiki-e/install-action@v2
with:
tool: git-cliff@2.10.1
- name: Generate changelog
id: changelog
shell: bash
run: |
TAG="${GITHUB_REF#refs/tags/}"
# Generate changelog for current tag only
CHANGELOG=$(git cliff --current --strip header)
# Save to output using multiline format
echo "content<<EOF" >> "$GITHUB_OUTPUT"
echo "$CHANGELOG" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.changelog.outputs.content }}
generate_release_notes: false