Skip to content

Build Linux

Build Linux #137

Workflow file for this run

name: Build Linux
on:
workflow_dispatch:
inputs:
tagname:
description: "tagname"
type: string
required: true
build_type:
description: "Build type"
type: choice
required: true
default: "ci"
options:
- ci
- rel
workflow_call:
inputs:
tagname:
description: "tagname"
type: string
required: true
build_type:
description: "Build type"
type: string
required: true
default: "ci"
skip_upload:
description: "Skip Telegram upload"
type: boolean
required: false
default: false
jobs:
build:
runs-on: ubuntu-latest
outputs:
tagname: ${{ steps.tagname.outputs.tagname }}
run_id: ${{ github.run_id }}
env:
IMAGE_TAG: fagram:build
steps:
- name: Set TAGNAME
id: tagname
run: |
if [ -n "${{ inputs.tagname }}" ]; then
TAGNAME="${{ inputs.tagname }}"
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
TAGNAME="${GITHUB_REF#refs/tags/}"
else
TAGNAME="${{ github.ref_name }}"
fi
echo "TAGNAME=$TAGNAME" >> $GITHUB_ENV
echo "tagname=$TAGNAME" >> $GITHUB_OUTPUT
echo "WEEK=$(date -u +%G%V)" >> $GITHUB_ENV
- name: Clone.
uses: actions/checkout@v7
with:
submodules: recursive
- name: Clone DesktopPrivate
run: |
git clone https://x-access-token:${{ secrets.PAT }}@github.com/fagramdesktop/DesktopPrivate.git $GITHUB_WORKSPACE/../DesktopPrivate
- name: Pull Docker IMG
run: |
docker pull ghcr.io/telegramdesktop/tdesktop/centos_env
docker tag ghcr.io/telegramdesktop/tdesktop/centos_env $IMAGE_TAG
- name: Restore Telegram Desktop cache.
id: cache-tdesktop
uses: actions/cache/restore@v6
with:
path: ${{ runner.temp }}/.tdesktop-cache
key: ${{ runner.OS }}-tdesktop-${{ env.WEEK }}
restore-keys: ${{ runner.OS }}-tdesktop-
- name: Configure & Build FAgram with CMake
run: |
mkdir -p ${{ runner.temp }}/.tdesktop-cache
docker run --rm \
-u $(id -u) \
-v $PWD:/usr/src/tdesktop \
-v $GITHUB_WORKSPACE/../DesktopPrivate:/usr/src/DesktopPrivate \
-v ${{ runner.temp }}/.tdesktop-cache:/var/cache/ccache \
-e CONFIG=Release \
-e CCACHE_SLOPPINESS=pch_defines,time_macros \
$IMAGE_TAG \
env -u CCACHE_DISABLE /usr/src/tdesktop/Telegram/build/docker/centos_env/build.sh \
-D CMAKE_CONFIGURATION_TYPES=Release \
-D CMAKE_INSTALL_PREFIX="/usr" \
-D CMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -Wl,-z,muldefs" \
-D CMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld -Wl,-z,muldefs" \
-D HAVE_EGL=TRUE \
-D TDESKTOP_API_ID=${{ secrets.API_ID_CONFIG }} \
-D TDESKTOP_API_HASH=${{ secrets.API_HASH_CONFIG }} \
-D DESKTOP_APP_DISABLE_AUTOUPDATE=OFF \
-D DESKTOP_APP_BUILD_PACKER=ON
- name: Save Telegram Desktop cache.
if: >
github.ref_name == github.event.repository.default_branch
&& steps.cache-tdesktop.outputs.cache-hit != 'true'
uses: actions/cache/save@v6
with:
path: ${{ runner.temp }}/.tdesktop-cache
key: ${{ steps.cache-tdesktop.outputs.cache-primary-key }}
- name: Read version info
id: version
run: |
VERSION_FILE="Telegram/build/version"
APP_VERSION=$(grep 'AppVersion ' "$VERSION_FILE" | awk '{print $2}')
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
echo "app_version=$APP_VERSION" >> $GITHUB_OUTPUT
- name: Sign OTA update
if: ${{ inputs.build_type == 'rel' }}
run: |
PACKER=$(find out -name Packer -type f | head -1)
TELEGRAM=$(find out -name fagram -type f -not -path "*/install/*" | head -1)
if [ -z "$PACKER" ] || [ -z "$TELEGRAM" ]; then
echo "Error: Packer or Telegram binary not found"
find out -type f -name 'Packer' -o -name 'fagram'
exit 1
fi
docker run --rm \
-u $(id -u) \
-v $PWD:/usr/src/tdesktop \
$IMAGE_TAG \
/bin/bash -c "cd /usr/src/tdesktop && ./$PACKER -path ./$TELEGRAM -version $APP_VERSION"
- name: Create Tar
run: |
cd out/install
tar -czvf fagram-${{ env.TAGNAME }}.tar.gz usr
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: fagram-${{ env.TAGNAME }}
path: out/install/fagram-${{ env.TAGNAME }}.tar.gz
- name: Upload OTA Update
if: ${{ inputs.build_type == 'rel' }}
uses: actions/upload-artifact@v7
with:
name: ota-linux
path: tlinuxupd${{ env.APP_VERSION }}
upload-telegram:
name: Upload to Telegram
needs: build
if: ${{ !inputs.skip_upload }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
sparse-checkout: |
scripts/tgupload.py
Telegram/SourceFiles/fa/fa_version.h
- name: Extract TGD version
run: |
TGD_VERSION=$(grep 'AppTGDVersion' Telegram/SourceFiles/fa/fa_version.h | sed 's/.*"\(.*\)".*/\1/')
echo "TGD_VERSION=$TGD_VERSION" >> $GITHUB_ENV
- name: Generate changelog
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
run: |
REPO="${{ github.repository }}"
RUN_ID="${{ github.run_id }}"
RUN_INFO=$(curl -s -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/actions/runs/$RUN_ID")
HEAD_SHA=$(echo "$RUN_INFO" | jq -r '.head_sha')
BRANCH=$(echo "$RUN_INFO" | jq -r '.head_branch')
WORKFLOW_ID=$(echo "$RUN_INFO" | jq -r '.workflow_id')
if [ "${{ inputs.build_type }}" = "rel" ]; then
PREV_TAG=$(curl -s -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/releases/latest" | jq -r '.tag_name // empty')
if [ -n "$PREV_TAG" ]; then
COMPARE=$(curl -s -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/compare/$PREV_TAG...$HEAD_SHA")
CHANGELOG=$(echo "$COMPARE" | jq -r '[.commits[] | select(.author.login == "Burhanverse" or .committer.login == "Burhanverse") | .commit.message | split("\n")[0]] | map("• " + .) | join("\n")')
fi
else
LAST_SHA=$(curl -s -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/actions/workflows/$WORKFLOW_ID/runs?status=completed&conclusion=success&branch=$BRANCH&per_page=2" \
| jq -r --arg head "$HEAD_SHA" '[.workflow_runs[] | select(.head_sha != $head)][0].head_sha // empty')
if [ -n "$LAST_SHA" ]; then
COMPARE=$(curl -s -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/compare/$LAST_SHA...$HEAD_SHA")
CHANGELOG=$(echo "$COMPARE" | jq -r '[.commits[] | select(.author.login == "Burhanverse" or .committer.login == "Burhanverse") | .commit.message | split("\n")[0]] | map("• " + .) | join("\n")')
fi
fi
if [ -z "$CHANGELOG" ]; then
CHANGELOG="No new changes"
fi
CHANGELOG=$(echo "$CHANGELOG" | head -15)
echo "CHANGELOG<<CHANGELOG_EOF" >> $GITHUB_ENV
echo "$CHANGELOG" >> $GITHUB_ENV
echo "CHANGELOG_EOF" >> $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
run: pip install kurigram tgcrypto
- name: Download Linux artifact
uses: actions/download-artifact@v8
with:
name: fagram-${{ inputs.tagname }}
path: artifacts/linux
- name: Upload Linux artifact to Telegram
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
API_ID: ${{ secrets.API_ID_CONFIG }}
API_HASH: ${{ secrets.API_HASH_CONFIG }}
run: |
LINUX_FILE=$(find artifacts/linux -name "fagram-*.tar.gz" | head -1)
python3 scripts/tgupload.py "$LINUX_FILE" --chat-id ${{ secrets.CHAT_ID }} --caption "$(cat <<EOF
<b>FAgram Linux ${{ inputs.tagname }}</b>
TGD Base: <code>${{ env.TGD_VERSION }}</code>
Build Type: <code>${{ inputs.build_type }}</code>
Branch: <code>${{ github.ref_name }}</code>
<blockquote expandable>${{ env.CHANGELOG }}</blockquote>
EOF
)"