Skip to content

Commit

Permalink
workflow: update to new tg notify format
Browse files Browse the repository at this point in the history
  • Loading branch information
gtxaspec committed Dec 16, 2024
1 parent e768071 commit 971bc33
Showing 1 changed file with 92 additions and 51 deletions.
143 changes: 92 additions & 51 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: u-boot-ingenic

on:
schedule:
Expand All @@ -21,6 +21,11 @@ on:
description: 'Only build T31X profile '
required: false
default: false
debug_enabled:
type: boolean
description: 'Debug: Generate dummy image files'
required: false
default: false

env:
TAG_NAME: latest
Expand All @@ -29,7 +34,6 @@ env:
TG_CHANNEL: ${{secrets.TELEGRAM_CHANNEL_THINGINO_BUILD}}
TG_TOPIC: ${{secrets.TELEGRAM_TOPIC_THINGINO_BUILD}}
TG_CHANNEL_SCRATCH: ${{secrets.TELEGRAM_CHANNEL_THINGINO_SCRATCH}}
TG_OPTIONS: -s
TZ: America/Los_Angeles

jobs:
Expand All @@ -43,31 +47,34 @@ jobs:
run: |
sudo timedatectl set-timezone ${{ env.TZ }}
- name: Save workflow start time
- name: Save workflow start time to ENV
id: set_output
run: echo "time=$(date +%s)" >> $GITHUB_OUTPUT

- name: Setup Notify Environment
- name: Configure Environment Variables
run: |
echo "TG_DISABLED=${{ github.event.inputs.tg_disabled || 'false' }}" >> $GITHUB_ENV
echo "tg_disabled=${{ github.event.inputs.tg_disabled || 'false' }}" >> $GITHUB_OUTPUT
- name: Setup Notification Channel
if: ${{ github.event.inputs.tg_scratch == 'true' }}
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: "master"
fetch-depth: "1"

- name: Download TG-Notify script
run: |
echo "TG_TOPIC=" >> $GITHUB_ENV
curl -o .github/scripts/tg-notify.sh https://raw.githubusercontent.com/themactep/thingino-firmware/master/.github/scripts/tg-notify.sh
chmod +x .github/scripts/tg-notify.sh
- name: Send build start notifcation
- name: Send build start notifcation via Telegram
if: env.TG_DISABLED == 'false'
run: |
if [[ "${{ github.event.inputs.tg_scratch }}" == 'true' ]]; then
TG_CHANNEL=${{ env.TG_CHANNEL_SCRATCH }}
export TG_TOPIC=""
fi
TG_MSG="u\\-boot\\-ingenic build started:\nJob: [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})\n\n"
TG_ICON="\xF0\x9F\x9A\xA6 GitHub Actions"
TG_HEADER=$(echo -e ${TG_MSG}${TG_ICON})
HTTP=$(curl ${TG_OPTIONS} -H "Content-Type: multipart/form-data" -X POST https://api.telegram.org/bot${TG_TOKEN}/sendMessage -F parse_mode=MarkdownV2 -F message_thread_id=${TG_TOPIC} -F chat_id=${TG_CHANNEL} -F text="${TG_HEADER}" -F disable_web_page_preview=true)
echo Telegram response: ${HTTP}
.github/scripts/tg-notify.sh -s $TG_TOKEN $TG_CHANNEL $TG_TOPIC start ${{ github.workflow }} ${{ github.run_id }} ${{ github.repository }}
generate-matrix:
runs-on: ubuntu-24.04
Expand All @@ -78,19 +85,23 @@ jobs:
run: |
sudo timedatectl set-timezone ${{ env.TZ }}
- name: setup env test
- name: Configure GH workspace
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

- name: Checkout source
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: "master"
fetch-depth: "1"

- name: Generate matrix
- name: Generate device matrix
id: set-matrix
run: |
CONFIGS=$(cat boards.cfg | grep isvp | awk '{print $1}' | grep -v -e nand)
if [[ "${{ github.event.inputs.t31x_only }}" == 'true' ]]; then
CONFIGS=$(cat boards.cfg | grep isvp | awk '{print $1}' | grep isvp_t31_sfcnor_ddr128M)
else
CONFIGS=$(cat boards.cfg | grep isvp | awk '{print $1}' | grep -v -e nand)
fi
JSON_MATRIX="{\"u-boot-version\": ["
for CONFIG in $CONFIGS; do
JSON_MATRIX+="\"${CONFIG}\","
Expand All @@ -108,7 +119,6 @@ jobs:
strategy:
fail-fast: false
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}

steps:
- name: Setup cache directories
run: |
Expand All @@ -123,13 +133,13 @@ jobs:
restore-keys: |
${{ runner.os }}-ccache-$-
- name: Update repo sources
- name: Update package manager sources
run: |
apt-get update
- name: Install dependencies
- name: Install build dependencies
run: |
apt-get install -y --no-install-recommends --no-install-suggests build-essential bc ccache cpio curl ca-certificates file git make gawk lzop procps rsync tzdata u-boot-tools unzip wget
apt-get install -y --no-install-recommends --no-install-suggests 7zip build-essential bc ccache cpio curl ca-certificates file git make gawk lzop procps rsync tzdata u-boot-tools unzip wget
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Set timezone
Expand All @@ -138,34 +148,48 @@ jobs:
echo ${{ env.TZ }} > /etc/timezone
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure -f noninteractive tzdata
- name: Checkout
- name: Setup gh workspace to container
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

- name: Checkout repository source
uses: actions/checkout@v4
with:
ref: "master"
fetch-depth: "1"

- name: Download TG-Notify script
run: |
curl -o .github/scripts/tg-notify.sh https://raw.githubusercontent.com/themactep/thingino-firmware/master/.github/scripts/tg-notify.sh
chmod +x .github/scripts/tg-notify.sh
- name: Download toolchain
run: |
wget https://github.com/themactep/thingino-firmware/releases/download/toolchain/thingino-toolchain_xburst1_musl_gcc14-linux-mipsel.tar.gz -O ~/thingino-toolchain_xburst1_musl_gcc14-linux-mipsel.tar.gz
tar -xf ~/thingino-toolchain_xburst1_musl_gcc14-linux-mipsel.tar.gz -C ~/
- name: u-boot-ingenic Build
if: ${{ github.event.inputs.debug_enabled != 'true' }}
shell: bash
run: |
echo "HASH IS"
git rev-parse --short ${GITHUB_SHA}
export GIT_HASH=$(git rev-parse --short ${GITHUB_SHA})
export GIT_BRANCH=${GITHUB_REF_NAME}
echo "GIT_HASH=${GIT_HASH}" >> ${GITHUB_ENV}
echo "GIT_BRANCH=${GIT_BRANCH}" >> ${GITHUB_ENV}
#cp -f .github/scripts/build.sh build-ci.sh
echo "TG_DISABLED=${{ github.event.inputs.tg_disabled || 'false' }}" >> $GITHUB_ENV
VERSION=${{ matrix.u-boot-version }}
CROSS_COMPILE=~/mipsel-thingino-linux-musl_sdk-buildroot/bin/mipsel-linux- bash build.sh $VERSION
TIME=$(date -d @${SECONDS} +%M:%S)
echo "TIME=${TIME}" >> ${GITHUB_ENV}
- name: Generate debug dummy firmware for workflow testing
if: ${{ github.event.inputs.debug_enabled == 'true' }}
run: |
mkdir -p ./uboot_build
echo "debug" > ./uboot_build/u-boot-${{ matrix.u-boot-version }}.bin
echo "TIME=7:77" >> ${GITHUB_ENV}
- name: Check if compiled u-boot exists
run: |
FILE=./uboot_build/u-boot-${{ matrix.u-boot-version }}.bin
Expand All @@ -178,45 +202,52 @@ jobs:
echo "Found file: $FILE"
echo "UBOOTFW=$FILE" >> $GITHUB_ENV
- name: Generate checksum file
run: |
sha256sum "${{ env.UBOOTFW }}" | awk -v filename="$(basename "${{ env.UBOOTFW }}")" '{print $1, filename}' > ./uboot_build/u-boot-${{ matrix.u-boot-version }}.bin.sha256sum
echo "UBOOTFW_SHA=./uboot_build/u-boot-${{ matrix.u-boot-version }}.bin.sha256sum" >> $GITHUB_ENV
- name: Upload firmware as artifact
uses: actions/upload-artifact@v4
with:
name: u-boot-${{ matrix.u-boot-version }}.bin
path: ${{ env.UBOOTFW }}
path: |
${{ env.UBOOTFW }}
${{ env.UBOOTFW_SHA }}
- name: Upload ${{ matrix.u-boot-version }}
if: github.event_name != 'pull_request'
uses: softprops/action-gh-release@v2.1.0
with:
tag_name: ${{ env.TAG_NAME }}
files: ${{ env.UBOOTFW }}
files: |
${{ env.UBOOTFW }}
${{ env.UBOOTFW_SHA }}
- name: Send build alert
if: ${{ env.TG_DISABLED != 'true' && env.UBOOTFW }}
shell: bash
- name: Package binaries for notify
run: |
7zz a -t7z -mx=9 -mmt=on /tmp/u-boot-${{ matrix.u-boot-version }}.7z ${{ env.UBOOTFW }} ${{ env.UBOOTFW_SHA }}
- name: Send uboot completion notifications with attachment
if: ${{ env.TG_DISABLED == 'false' && (env.UBOOTFW) }}
run: |
if [[ "${{ github.event.inputs.tg_scratch }}" == 'true' ]]; then
TG_CHANNEL=${{ env.TG_CHANNEL_SCRATCH }}
export TG_TOPIC=""
fi
if [ -n "${{ env.UBOOTFW }}" ]; then
.github/scripts/tg-notify.sh -s $TG_TOKEN $TG_CHANNEL $TG_TOPIC completed $TAG_NAME ${{ github.run_id }} ${{ github.repository }} ${GIT_HASH} ${GIT_BRANCH} ${TAG_NAME} ${TIME} ${{ matrix.u-boot-version }} /tmp/u-boot-${{ matrix.u-boot-version }}.7z
fi
TG_MSG="Commit: [${GIT_HASH}](https://github.com/${GITHUB_REPOSITORY}/commit/${GIT_HASH})\nBranch: [${GIT_BRANCH}](https://github.com/${GITHUB_REPOSITORY}/tree/${GIT_BRANCH})\nTag: [${TAG_NAME}](https://github.com/${GITHUB_REPOSITORY}/releases/tag/${TAG_NAME})\nTime: ${TIME}\nJob: [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})\n\n"
TG_HEADER=$(echo -e "${TG_MSG}\xE2\x9C\x85 GitHub Actions")
HTTP_FULL=$(curl ${TG_OPTIONS} -H "Content-Type: multipart/form-data" -X POST https://api.telegram.org/bot${TG_TOKEN}/sendDocument -F parse_mode=MarkdownV2 -F message_thread_id=${TG_TOPIC} -F chat_id=${TG_CHANNEL} -F caption="${TG_HEADER}" -F document=@${UBOOTFW} -F disable_web_page_preview=true)
echo "Telegram response Full Firmware: $HTTP_FULL"
- name: Send error
if: ${{ env.TG_DISABLED != 'true' && failure() }}
shell: bash
- name: Send error notification
if: ${{ env.TG_DISABLED == 'false' && failure() }}
run: |
if [[ "${{ github.event.inputs.tg_scratch }}" == 'true' ]]; then
TG_CHANNEL=${{ env.TG_CHANNEL_SCRATCH }}
export TG_TOPIC=""
fi
TG_WARN="Error: u\\-boot\\-ingenic build failed!\n"
TG_MSG="Commit: ${GIT_HASH}\nBranch: ${GIT_BRANCH}\nTag: ${TAG_NAME}\nhttps://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\n\n"
TG_ICON="\xE2\x9A\xA0 GitHub Actions"
TG_HEADER=$(echo -e ${TG_WARN}${TG_MSG}${TG_ICON})
HTTP=$(curl ${TG_OPTIONS} -H "Content-Type: multipart/form-data" -X POST https://api.telegram.org/bot${TG_TOKEN}/sendMessage -F message_thread_id=${TG_TOPIC} -F chat_id=${TG_CHANNEL} -F text="${TG_HEADER}" -F disable_web_page_preview=true)
echo Telegram response: ${HTTP}
.github/scripts/tg-notify.sh -s $TG_TOKEN $TG_CHANNEL $TG_TOPIC error $TAG_NAME ${{ github.run_id }} ${{ github.repository }}
notify-completion:
needs: [build, notify-begin]
runs-on: ubuntu-24.04
Expand All @@ -226,23 +257,33 @@ jobs:
run: |
sudo timedatectl set-timezone ${{ env.TZ }}
- name: Setup Environment
- name: Checkout repository source
uses: actions/checkout@v4
with:
submodules: 'false'
ref: "master"

- name: Download TG-Notify script
run: |
curl -o .github/scripts/tg-notify.sh https://raw.githubusercontent.com/themactep/thingino-firmware/master/.github/scripts/tg-notify.sh
chmod +x .github/scripts/tg-notify.sh
- name: Configure Environment
run: |
echo "TG_DISABLED=${{ github.event.inputs.tg_disabled || 'false' }}" >> $GITHUB_ENV
echo "GIT_HASH=${{ needs.buildroot.outputs.git_hash }}" >> $GITHUB_ENV
echo "TAG_NAME=${{ needs.buildroot.outputs.tag_name }}" >> $GITHUB_ENV
- name: Send completion summary
- name: Send nofity completion summary
if: ${{ env.TG_DISABLED == 'false' }}
run: |
if [[ "${{ github.event.inputs.tg_scratch }}" == 'true' ]]; then
TG_CHANNEL=${{ env.TG_CHANNEL_SCRATCH }}
export TG_TOPIC=""
fi
START_TIME=${{ needs.notify-begin.outputs.start_time }}
END_TIME=$(date -u +%s)
ELAPSED=$((END_TIME - START_TIME))
ELAPSED_MIN=$((ELAPSED / 60))
ELAPSED_SEC=$((ELAPSED % 60))
TG_MSG="u\\-boot\\-ingenic build completed:\nTotal elapsed time: ${ELAPSED_MIN}m ${ELAPSED_SEC}s\nJob: [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})\n\n"
TG_ICON="\xF0\x9F\x9A\xA9 GitHub Actions"
TG_HEADER=$(echo -e ${TG_MSG}${TG_ICON})
HTTP=$(curl ${TG_OPTIONS} -H "Content-Type: multipart/form-data" -X POST https://api.telegram.org/bot${TG_TOKEN}/sendMessage -F parse_mode=MarkdownV2 -F message_thread_id=${TG_TOPIC} -F chat_id=${TG_CHANNEL} -F text="${TG_HEADER}" -F disable_web_page_preview=true)
echo Telegram response: ${HTTP}
.github/scripts/tg-notify.sh -s $TG_TOKEN $TG_CHANNEL $TG_TOPIC finish ${{ github.workflow }} "${ELAPSED_MIN}m ${ELAPSED_SEC}s" ${{ github.run_id }} ${{ github.repository }}

0 comments on commit 971bc33

Please sign in to comment.