diff --git a/.github/workflows/hermes_open_project_recommendation.yaml b/.github/workflows/hermes_open_project_recommendation.yaml index 1cf50d9..c1c9ee7 100644 --- a/.github/workflows/hermes_open_project_recommendation.yaml +++ b/.github/workflows/hermes_open_project_recommendation.yaml @@ -13,14 +13,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout osscameroon-website - uses: actions/checkout@v7 + uses: actions/checkout@v4 with: token: ${{ secrets.GA_WORKFLOW_DEPLOYMENTS_TOKEN }} repository: osscameroon/osscameroon-website path: osscameroon-website - name: Set up Python 3.8 - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: 3.8 diff --git a/.github/workflows/jobsika_social_media_message_scheduler.yaml b/.github/workflows/jobsika_social_media_message_scheduler.yaml index 634eb25..f3dc9e0 100644 --- a/.github/workflows/jobsika_social_media_message_scheduler.yaml +++ b/.github/workflows/jobsika_social_media_message_scheduler.yaml @@ -12,10 +12,10 @@ jobs: name: Send message runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - name: Set up Python 3.8 - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: 3.8 diff --git a/.github/workflows/notify_on_broken_link_detected.yaml b/.github/workflows/notify_on_broken_link_detected.yaml index 597f5c5..9e67413 100644 --- a/.github/workflows/notify_on_broken_link_detected.yaml +++ b/.github/workflows/notify_on_broken_link_detected.yaml @@ -12,11 +12,11 @@ jobs: name: notify runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@v4 - name: Install the broken link checker shell: bash run: | - sh /.github/workflows/notify_on_broken_link_detected/install_deps.sh + sh ./.github/workflows/notify_on_broken_link_detected/install_deps.sh - name: Check the websites shell: bash run: | diff --git a/.github/workflows/notify_on_issue_open.yaml b/.github/workflows/notify_on_issue_open.yaml index 78dd18e..826c103 100644 --- a/.github/workflows/notify_on_issue_open.yaml +++ b/.github/workflows/notify_on_issue_open.yaml @@ -17,7 +17,7 @@ jobs: name: notify runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@v4 with: repository: osscameroon/global-github-actions - name: notify telegram when issue is a created diff --git a/.github/workflows/notify_on_pull_request_open.yaml b/.github/workflows/notify_on_pull_request_open.yaml index 1d2d434..9bc3666 100644 --- a/.github/workflows/notify_on_pull_request_open.yaml +++ b/.github/workflows/notify_on_pull_request_open.yaml @@ -17,7 +17,7 @@ jobs: name: notify runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@v4 with: repository: osscameroon/global-github-actions - name: notify telegram when pull request is a created diff --git a/.github/workflows/recommend_yotas_issues.yaml b/.github/workflows/recommend_yotas_issues.yaml index 7c8cf67..0c71f8e 100644 --- a/.github/workflows/recommend_yotas_issues.yaml +++ b/.github/workflows/recommend_yotas_issues.yaml @@ -5,6 +5,11 @@ on: jobs: build: + env: + TELEGRAM_SEND_GATE_ENABLED: ${{ vars.TELEGRAM_SEND_GATE_ENABLED || 'true' }} + TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES || '5' }} + TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES || '1' }} + TELEGRAM_SEND_GATE_ON_ERROR: ${{ vars.TELEGRAM_SEND_GATE_ON_ERROR || 'skip' }} defaults: run: working-directory: ./.github/workflows/recommend_yotas_issues @@ -12,12 +17,19 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - name: get yotas issues shell: bash run: | GITHUB_TOKEN=${{ secrets.BOT_GITHUB_TOKEN }} ./get_yotas_issues.sh > yotas_issues_message + - name: check if osscameroon group allows bot posting + id: telegram_send_gate_yotas_issues + env: + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + run: "$GITHUB_WORKSPACE/.github/workflows/telegram_send_gate.sh" + - name: send custom message with to osscameroon channel uses: appleboy/telegram-action@v1.0.1 with: @@ -26,6 +38,7 @@ jobs: message_file: ./.github/workflows/recommend_yotas_issues/yotas_issues_message - name: send custom message with to osscameroon group + if: ${{ steps.telegram_send_gate_yotas_issues.outputs.telegram_send_gate == 'true' }} uses: appleboy/telegram-action@v1.0.1 with: to: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} diff --git a/.github/workflows/report_a_quiz.yaml b/.github/workflows/report_a_quiz.yaml index dc01a52..37453b8 100644 --- a/.github/workflows/report_a_quiz.yaml +++ b/.github/workflows/report_a_quiz.yaml @@ -6,6 +6,11 @@ on: jobs: build: + env: + TELEGRAM_SEND_GATE_ENABLED: ${{ vars.TELEGRAM_SEND_GATE_ENABLED || 'true' }} + TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES || '5' }} + TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES || '1' }} + TELEGRAM_SEND_GATE_ON_ERROR: ${{ vars.TELEGRAM_SEND_GATE_ON_ERROR || 'skip' }} defaults: run: working-directory: ./.github/workflows/report_quiz @@ -13,8 +18,17 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 + + - name: check if osscameroon group allows bot posting + id: telegram_send_gate_quiz + env: + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + run: "$GITHUB_WORKSPACE/.github/workflows/telegram_send_gate.sh" + - name: Send Quiz message to the channel + if: ${{ steps.telegram_send_gate_quiz.outputs.telegram_send_gate == 'true' }} shell: bash run: | ./report_quiz.sh ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} ${{ secrets.TELEGRAM_BOT_TOKEN }} ${{ secrets.QUIZAPI_KEY }} diff --git a/.github/workflows/report_contributions.yaml b/.github/workflows/report_contributions.yaml index a43a0ef..324f4fd 100644 --- a/.github/workflows/report_contributions.yaml +++ b/.github/workflows/report_contributions.yaml @@ -6,6 +6,11 @@ on: jobs: build: + env: + TELEGRAM_SEND_GATE_ENABLED: ${{ vars.TELEGRAM_SEND_GATE_ENABLED || 'true' }} + TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES || '5' }} + TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES || '1' }} + TELEGRAM_SEND_GATE_ON_ERROR: ${{ vars.TELEGRAM_SEND_GATE_ON_ERROR || 'skip' }} defaults: run: working-directory: ./.github/workflows/report_contributions @@ -13,9 +18,9 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - name: Setup python - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: 3.8 - name: Install dependencies @@ -26,6 +31,13 @@ jobs: run: | GITHUB_TOKEN=${{ secrets.BOT_GITHUB_TOKEN }} ./get_contribution_report.sh > contributions_report_message + - name: check if osscameroon group allows bot posting + id: telegram_send_gate_contributions + env: + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + run: "$GITHUB_WORKSPACE/.github/workflows/telegram_send_gate.sh" + - name: send contribution report to osscameroon channel uses: appleboy/telegram-action@v1.0.1 with: @@ -35,6 +47,7 @@ jobs: message_file: ./.github/workflows/report_contributions/contributions_report_message - name: send contribution report to osscameroon group + if: ${{ steps.telegram_send_gate_contributions.outputs.telegram_send_gate == 'true' }} uses: appleboy/telegram-action@v1.0.1 with: to: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} diff --git a/.github/workflows/report_jobs.yaml b/.github/workflows/report_jobs.yaml index 03305c3..ce1e348 100644 --- a/.github/workflows/report_jobs.yaml +++ b/.github/workflows/report_jobs.yaml @@ -7,6 +7,11 @@ on: jobs: build: + env: + TELEGRAM_SEND_GATE_ENABLED: ${{ vars.TELEGRAM_SEND_GATE_ENABLED || 'true' }} + TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES || '5' }} + TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES || '1' }} + TELEGRAM_SEND_GATE_ON_ERROR: ${{ vars.TELEGRAM_SEND_GATE_ON_ERROR || 'skip' }} defaults: run: working-directory: ./.github/workflows/report_jobs @@ -14,14 +19,22 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - name: get available jobs shell: bash run: | ./report_jobs.sh > report_jobs && cat report_jobs + - name: check if remotejobs group allows bot posting + id: telegram_send_gate_jobs + env: + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_REMOTEJOBS_GROUP_ID }} + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + run: "$GITHUB_WORKSPACE/.github/workflows/telegram_send_gate.sh" + - name: send jobs report to osscameroon group + if: ${{ steps.telegram_send_gate_jobs.outputs.telegram_send_gate == 'true' }} uses: appleboy/telegram-action@v1.0.1 with: to: ${{ secrets.TELEGRAM_REMOTEJOBS_GROUP_ID }} diff --git a/.github/workflows/report_jokes.yaml b/.github/workflows/report_jokes.yaml index 9dfaa8b..d887691 100644 --- a/.github/workflows/report_jokes.yaml +++ b/.github/workflows/report_jokes.yaml @@ -7,6 +7,11 @@ on: jobs: build: + env: + TELEGRAM_SEND_GATE_ENABLED: ${{ vars.TELEGRAM_SEND_GATE_ENABLED || 'true' }} + TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES || '5' }} + TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES || '1' }} + TELEGRAM_SEND_GATE_ON_ERROR: ${{ vars.TELEGRAM_SEND_GATE_ON_ERROR || 'skip' }} defaults: run: working-directory: ./.github/workflows/report_jokes @@ -14,9 +19,9 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@v4 - name: Set up Python 3.11 - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: 3.11 @@ -26,7 +31,15 @@ jobs: python main.py > report_joke && \ cat report_joke + - name: check if osscameroon group allows bot posting + id: telegram_send_gate_jokes + env: + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + run: "$GITHUB_WORKSPACE/.github/workflows/telegram_send_gate.sh" + - name: send joke report to osscameroon group + if: ${{ steps.telegram_send_gate_jokes.outputs.telegram_send_gate == 'true' }} uses: appleboy/telegram-action@v1.0.1 with: to: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} diff --git a/.github/workflows/report_news.yaml b/.github/workflows/report_news.yaml index 7c7e9cf..607707c 100644 --- a/.github/workflows/report_news.yaml +++ b/.github/workflows/report_news.yaml @@ -19,7 +19,7 @@ jobs: name: Build And Send runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@v4 - name: Send the news api message to osscameroon channel env: @@ -49,6 +49,10 @@ jobs: run: | git config --global user.email "github-actions[bot]@users.noreply.github.com" && \ git config --global user.name "github-actions[bot]" && \ - git add $REPORT_HASH_FILE && \ - git commit -m 'update report_news.hash' && \ - git push origin main + if ! git diff --quiet $REPORT_HASH_FILE; then \ + git add $REPORT_HASH_FILE && \ + git commit -m 'update report_news.hash' && \ + git push origin main; \ + else \ + echo "No hash changes detected, skip commit."; \ + fi diff --git a/.github/workflows/report_number_of_yotas.yaml b/.github/workflows/report_number_of_yotas.yaml index 86fae93..d21ccde 100644 --- a/.github/workflows/report_number_of_yotas.yaml +++ b/.github/workflows/report_number_of_yotas.yaml @@ -6,16 +6,28 @@ on: jobs: build: + env: + TELEGRAM_SEND_GATE_ENABLED: ${{ vars.TELEGRAM_SEND_GATE_ENABLED || 'true' }} + TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES || '5' }} + TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES || '1' }} + TELEGRAM_SEND_GATE_ON_ERROR: ${{ vars.TELEGRAM_SEND_GATE_ON_ERROR || 'skip' }} defaults: run: working-directory: ./.github/workflows/members_yotas name: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - name: get number of yotas of each member run: python extract.py > members_yotas_message + - name: check if osscameroon group allows bot posting + id: telegram_send_gate_yotas + env: + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + run: "$GITHUB_WORKSPACE/.github/workflows/telegram_send_gate.sh" + - name: send custom message to osscameroon channel uses: appleboy/telegram-action@v1.0.1 with: @@ -25,9 +37,10 @@ jobs: message_file: ./.github/workflows/members_yotas/members_yotas_message - name: send custom message to osscameroon telegram group + if: ${{ steps.telegram_send_gate_yotas.outputs.telegram_send_gate == 'true' }} uses: appleboy/telegram-action@v1.0.1 with: to: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} token: ${{ secrets.TELEGRAM_BOT_TOKEN }} format: MarkdownV2 - message_file: ./.github/workflows/members_yotas/members_yotas_message \ No newline at end of file + message_file: ./.github/workflows/members_yotas/members_yotas_message diff --git a/.github/workflows/report_open_projects.yaml b/.github/workflows/report_open_projects.yaml index db723d2..b6c2204 100644 --- a/.github/workflows/report_open_projects.yaml +++ b/.github/workflows/report_open_projects.yaml @@ -5,6 +5,11 @@ on: jobs: build: + env: + TELEGRAM_SEND_GATE_ENABLED: ${{ vars.TELEGRAM_SEND_GATE_ENABLED || 'true' }} + TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES || '5' }} + TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES || '1' }} + TELEGRAM_SEND_GATE_ON_ERROR: ${{ vars.TELEGRAM_SEND_GATE_ON_ERROR || 'skip' }} defaults: run: working-directory: ./.github/workflows/report_open_projects @@ -12,12 +17,19 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - name: get contribution report shell: bash run: | ./get_open_projects.sh > open_projects_message + - name: check if osscameroon group allows bot posting + id: telegram_send_gate_open_projects + env: + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + run: "$GITHUB_WORKSPACE/.github/workflows/telegram_send_gate.sh" + - name: send open projects report to osscameroon channel uses: appleboy/telegram-action@v1.0.1 with: @@ -27,6 +39,7 @@ jobs: message_file: ./.github/workflows/report_open_projects/open_projects_message - name: send open projects report to osscameroon group + if: ${{ steps.telegram_send_gate_open_projects.outputs.telegram_send_gate == 'true' }} uses: appleboy/telegram-action@v1.0.1 with: to: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} diff --git a/.github/workflows/report_opencollective.yaml b/.github/workflows/report_opencollective.yaml index 8787ebb..e548f38 100644 --- a/.github/workflows/report_opencollective.yaml +++ b/.github/workflows/report_opencollective.yaml @@ -5,6 +5,11 @@ on: jobs: build: + env: + TELEGRAM_SEND_GATE_ENABLED: ${{ vars.TELEGRAM_SEND_GATE_ENABLED || 'true' }} + TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES || '5' }} + TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES || '1' }} + TELEGRAM_SEND_GATE_ON_ERROR: ${{ vars.TELEGRAM_SEND_GATE_ON_ERROR || 'skip' }} defaults: run: working-directory: ./.github/workflows/opencollective_contributions @@ -12,12 +17,19 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - name: get contribution report shell: bash run: | ./get_opencollective_info.sh > contributions_report_message + - name: check if osscameroon group allows bot posting + id: telegram_send_gate_opencollective + env: + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + run: "$GITHUB_WORKSPACE/.github/workflows/telegram_send_gate.sh" + - name: send opencollective contribution report to osscameroon channel uses: appleboy/telegram-action@v1.0.1 with: @@ -27,6 +39,7 @@ jobs: message_file: ./.github/workflows/opencollective_contributions/contributions_report_message - name: send opencollective contribution report to osscameroon group + if: ${{ steps.telegram_send_gate_opencollective.outputs.telegram_send_gate == 'true' }} uses: appleboy/telegram-action@v1.0.1 with: to: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} diff --git a/.github/workflows/report_quotes.yaml b/.github/workflows/report_quotes.yaml index 8599397..5d4e9a9 100644 --- a/.github/workflows/report_quotes.yaml +++ b/.github/workflows/report_quotes.yaml @@ -7,6 +7,11 @@ on: jobs: build: + env: + TELEGRAM_SEND_GATE_ENABLED: ${{ vars.TELEGRAM_SEND_GATE_ENABLED || 'true' }} + TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES || '5' }} + TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES: ${{ vars.TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES || '1' }} + TELEGRAM_SEND_GATE_ON_ERROR: ${{ vars.TELEGRAM_SEND_GATE_ON_ERROR || 'skip' }} defaults: run: working-directory: ./.github/workflows/report_quotes @@ -14,9 +19,9 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@v4 - name: Set up Python 3.11 - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: 3.11 @@ -26,7 +31,15 @@ jobs: python main.py > report_quote && \ cat report_quote + - name: check if osscameroon group allows bot posting + id: telegram_send_gate_quotes + env: + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + run: "$GITHUB_WORKSPACE/.github/workflows/telegram_send_gate.sh" + - name: send quote report to osscameroon group + if: ${{ steps.telegram_send_gate_quotes.outputs.telegram_send_gate == 'true' }} uses: appleboy/telegram-action@v1.0.1 with: to: ${{ secrets.TELEGRAM_OSSCAMEROON_GROUP_ID }} diff --git a/.github/workflows/social_media_message_scheduler.yaml b/.github/workflows/social_media_message_scheduler.yaml index e0fcf4e..1e54f0d 100644 --- a/.github/workflows/social_media_message_scheduler.yaml +++ b/.github/workflows/social_media_message_scheduler.yaml @@ -12,10 +12,10 @@ jobs: name: Send message runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - name: Set up Python 3.8 - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: 3.8 diff --git a/.github/workflows/telegram_send_gate.sh b/.github/workflows/telegram_send_gate.sh new file mode 100755 index 0000000..ceebcd1 --- /dev/null +++ b/.github/workflows/telegram_send_gate.sh @@ -0,0 +1,134 @@ +#!/usr/bin/env bash +set -euo pipefail + +log() { + echo "[telegram-send-gate] $*" +} + +# Defaults (can be overridden per workflow) +: "${TELEGRAM_SEND_GATE_ENABLED:=true}" +: "${TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES:=5}" +: "${TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES:=1}" +: "${TELEGRAM_SEND_GATE_ON_ERROR:=skip}" + +write_outputs() { + local should_send=$1 + local reason=$2 + local human_count=$3 + local sampled_count=$4 + + if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + { + echo "telegram_send_gate=${should_send}" + echo "telegram_send_gate_reason=${reason}" + echo "telegram_send_gate_human_messages=${human_count}" + echo "telegram_send_gate_sampled_messages=${sampled_count}" + } >> "$GITHUB_OUTPUT" + fi +} + +skip_send() { + local reason=$1 + local human_count=${2:-0} + local sampled_count=${3:-0} + + write_outputs false "$reason" "$human_count" "$sampled_count" + exit 0 +} + +if [[ "${TELEGRAM_SEND_GATE_ENABLED,,}" != "true" ]]; then + log "Send gate disabled; allowing send." + write_outputs true disabled 0 0 + exit 0 +fi + +if [[ -z "${TELEGRAM_CHAT_ID:-}" ]]; then + log "Missing TELEGRAM_CHAT_ID." + skip_send missing_chat_id +fi + +if [[ -z "${TELEGRAM_BOT_TOKEN:-}" ]]; then + log "Missing TELEGRAM_BOT_TOKEN." + skip_send missing_bot_token +fi + +if ! command -v jq >/dev/null 2>&1; then + log "jq is required for send gate logic and is not available." + if [[ "${TELEGRAM_SEND_GATE_ON_ERROR,,}" == "allow" ]]; then + write_outputs true missing_dependency_jq_allow 0 0 + exit 0 + fi + + skip_send missing_dependency_jq_skip +fi + +if ! [[ "$TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES" =~ ^[0-9]+$ ]] || (( TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES == 0 )); then + log "Invalid TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES: '$TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES'." + skip_send invalid_lookback +fi + +if ! [[ "$TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES" =~ ^[0-9]+$ ]]; then + log "Invalid TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES: '$TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES'." + skip_send invalid_min_human +fi + +API_BASE="https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}" +set +e +RESP=$(curl -sS --max-time 30 --retry 2 --retry-delay 2 "${API_BASE}/getUpdates?limit=100&timeout=0") +CURL_CODE=$? +set -e +if (( CURL_CODE != 0 )); then + log "Telegram getUpdates call failed with exit code $CURL_CODE." + if [[ "${TELEGRAM_SEND_GATE_ON_ERROR,,}" == "allow" ]]; then + write_outputs true api_curl_error_allow 0 0 + exit 0 + fi + skip_send api_curl_error_skip +fi + +if [[ -z "$RESP" ]]; then + log "Telegram API returned empty response." + if [[ "${TELEGRAM_SEND_GATE_ON_ERROR,,}" == "allow" ]]; then + write_outputs true api_empty_allow 0 0 + exit 0 + fi + + skip_send api_empty_skip +fi + +if ! echo "$RESP" | jq -e '.ok == true' >/dev/null 2>&1; then + DESCRIPTION=$(echo "$RESP" | jq -r '.description // "unknown"') + log "Telegram API error: $DESCRIPTION" + if [[ "${TELEGRAM_SEND_GATE_ON_ERROR,,}" == "allow" ]]; then + write_outputs true api_error_allow 0 0 + exit 0 + fi + + skip_send api_error_skip +fi + +CHAT_MESSAGES=$(echo "$RESP" | jq --arg chat_id "$TELEGRAM_CHAT_ID" --argjson lookback "$TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES" ' + .result + | map( + if has("message") then .message + elif has("channel_post") then .channel_post + else empty + end + ) + | map(select((.chat.id|tostring) == $chat_id)) + | sort_by(.date) + | reverse + | .[:$lookback] +') + +SAMPLED_COUNT=$(echo "$CHAT_MESSAGES" | jq 'length') +HUMAN_COUNT=$(echo "$CHAT_MESSAGES" | jq '[.[] | select(.from and (.from.is_bot == false))] | length') + +if (( HUMAN_COUNT >= TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES )); then + log "Allowed. Checked ${SAMPLED_COUNT} recent update(s), found ${HUMAN_COUNT} human message(s)." + write_outputs true human_presence_ok "$HUMAN_COUNT" "$SAMPLED_COUNT" + exit 0 +fi + +log "Blocked. Checked ${SAMPLED_COUNT} recent update(s), found ${HUMAN_COUNT} human message(s) (minimum required: ${TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES})." +skip_send human_presence_low "$HUMAN_COUNT" "$SAMPLED_COUNT" diff --git a/.github/workflows/validate_message_scheduler_messages.yaml b/.github/workflows/validate_message_scheduler_messages.yaml index 1ff37f2..34d9ca8 100644 --- a/.github/workflows/validate_message_scheduler_messages.yaml +++ b/.github/workflows/validate_message_scheduler_messages.yaml @@ -16,10 +16,10 @@ jobs: name: Validate messages runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v4 - name: Set up Python 3.8 - uses: actions/setup-python@v6 + uses: actions/setup-python@v5 with: python-version: 3.8 diff --git a/README.md b/README.md index 708afdf..dc6c667 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,125 @@ All github actions that we run for the entire github organisation Pull-request validator that ensures the `social_media_message_scheduler` messages stay schema-compliant. +## How to launch these workflows + +### 1) Scheduled workflows (automated) + +Most workflows are started automatically by `on.schedule` and do **not** need a manual trigger. +GitHub evaluates schedules in UTC and only runs the workflow version on the default branch, +so schedule changes on a pull-request branch take effect only after they are merged into `main`. + +- [hermes_open_project_recommendation.yaml](./.github/workflows/hermes_open_project_recommendation.yaml) +- [jobsika_social_media_message_scheduler.yaml](./.github/workflows/jobsika_social_media_message_scheduler.yaml) +- [recommend_yotas_issues.yaml](./.github/workflows/recommend_yotas_issues.yaml) +- [report_a_quiz.yaml](./.github/workflows/report_a_quiz.yaml) +- [report_jokes.yaml](./.github/workflows/report_jokes.yaml) +- [report_jobs.yaml](./.github/workflows/report_jobs.yaml) +- [report_news.yaml](./.github/workflows/report_news.yaml) +- [report_number_of_yotas.yaml](./.github/workflows/report_number_of_yotas.yaml) +- [report_open_projects.yaml](./.github/workflows/report_open_projects.yaml) +- [report_opencollective.yaml](./.github/workflows/report_opencollective.yaml) +- [report_quotes.yaml](./.github/workflows/report_quotes.yaml) +- [social_media_message_scheduler.yaml](./.github/workflows/social_media_message_scheduler.yaml) + +`validate_message_scheduler_messages.yaml` runs on pull requests; it is not scheduled. + +### 2) Manual dispatch workflows + +These are the only workflows you can start manually from the GitHub UI or CLI: + +```bash +gh workflow run notify_on_broken_link_detected.yaml +gh workflow run report_contributions.yaml +``` + +Optional: + +```bash +gh workflow run notify_on_broken_link_detected.yaml --ref main +gh workflow run report_contributions.yaml --ref main +``` + +From the GitHub Actions UI, open each workflow page and click **Run workflow**. + +### 3) Reusable workflows (consume from another repo) + +`notify_on_issue_open.yaml` and `notify_on_pull_request_open.yaml` are defined as `workflow_call`. +They are not run directly with `gh workflow run`. They are invoked by another repository workflow via `uses: .../.github/workflows/@`. + +Example: + +```yaml +jobs: + notify: + uses: osscameroon/global-github-actions/.github/workflows/notify_on_pull_request_open.yaml@main + secrets: + telegram_channel_id: ${{ secrets.TELEGRAM_OSSCAMEROON_CHANNEL_ID }} + telegram_token: ${{ secrets.TELEGRAM_BOT_TOKEN }} +``` + +### 4) Script entrypoint map (for local reproduction of launch logic) + +Each workflow’s `run`/script flow usually maps to these local entrypoints: + +- [social_media_message_scheduler](./.github/workflows/social_media_message_scheduler): `make run` and `make validate` +- [jobsika_social_media_message_scheduler](./.github/workflows/jobsika_social_media_message_scheduler): `make run` and `make validate` +- [report_news](./.github/workflows/report_news): `make -s run` +- [report_jokes](./.github/workflows/report_jokes/main.py): `python main.py` +- [report_quotes](./.github/workflows/report_quotes/main.py): `python main.py` +- [report_jobs](./.github/workflows/report_jobs/report_jobs.sh): `./report_jobs.sh` +- [report_open_projects](./.github/workflows/report_open_projects/get_open_projects.sh): `./get_open_projects.sh` +- [opencollective_contributions](./.github/workflows/opencollective_contributions/get_opencollective_info.sh): `./get_opencollective_info.sh` +- [report_contributions](./.github/workflows/report_contributions/get_contribution_report.sh): `./get_contribution_report.sh` +- [recommend_yotas_issues](./.github/workflows/recommend_yotas_issues/get_yotas_issues.sh): `./get_yotas_issues.sh` +- [report_quiz](./.github/workflows/report_quiz/report_quiz.sh): `./report_quiz.sh ` +- [report_number_of_yotas](./.github/workflows/members_yotas/extract.py): `python extract.py` +- [notify_on_issue_open](./.github/workflows/notify_on_issue_open/build_issue_notification.sh): `./build_issue_notification.sh "$GITHUB_EVENT_PATH"` +- [notify_on_pull_request_open](./.github/workflows/notify_on_pull_request_open/build_pull_request_notification.sh): `./build_pull_request_notification.sh "$GITHUB_EVENT_PATH"` +- [notify_on_broken_link_detected](./.github/workflows/notify_on_broken_link_detected/install_deps.sh): `./install_deps.sh` then `./run.sh` + + +### 5) Telegram group send gate (anti-flood for group chats) + +Some group-send workflows now run a preflight check before posting to Telegram groups. +The check only allows a new bot message when Telegram has delivered at least one +human-authored update for that group in the sampled updates. + +Behavior: + +- Fetches recent updates from `getUpdates` for the target group chat. +- Restricts sampling to the last `N` received updates in that chat. +- Counts how many of those messages are from non-bot users. +- Sends only if the non-bot count is greater or equal to a minimum threshold. + +Configuration is done with repository/organization variables (optional): + +- `TELEGRAM_SEND_GATE_ENABLED` (`true`/`false`, default `true`) +- `TELEGRAM_SEND_GATE_LOOKBACK_MESSAGES` (default `5`) +- `TELEGRAM_SEND_GATE_MIN_HUMAN_MESSAGES` (default `1`) +- `TELEGRAM_SEND_GATE_ON_ERROR` (`skip` or `allow`, default `skip`) + +`skip` on error means the bot is blocked and the message is not sent. +`allow` on error means the message is sent if Telegram API/dep checks fail. + +Important: Telegram's Bot API does not provide a chat-history endpoint. This gate can +only inspect updates delivered to the bot, not independently retrieve the exact latest +messages visible in the group. For useful results, the bot must receive group messages +(for example, privacy mode disabled or the bot configured with the necessary access), +and no separate webhook/update consumer should drain those updates. If an exact +chat-history policy is required, use a dedicated Telegram client/service with explicit +history-read access instead of a bot-token-only workflow. + +Script reference: + +- `.github/workflows/telegram_send_gate.sh` +- it writes step outputs: + - `telegram_send_gate` + - `telegram_send_gate_reason` + - `telegram_send_gate_human_messages` + - `telegram_send_gate_sampled_messages` + + ## [notify_on_pull_request_open](https://github.com/osscameroon/global-github-actions/blob/main/.github/workflows/notify_on_pull_request_open.yaml) Send a message to the telegram channel whenever a new pull request is openened/created. @@ -69,4 +188,3 @@ You can use [this file](https://github.com/osscameroon/global-github-actions/blo ![Alt](https://repobeats.axiom.co/api/embed/543b48955b6c028475b2c10d945c24714a0e52f3.svg "Repobeats analytics image") -