From d3f38ad2f549392c43817b139e9570be84798b88 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Apr 2026 06:34:54 +0000 Subject: [PATCH] Add GitHub Actions automation to mirror repository events to LOGS Agent-Logs-Url: https://github.com/th30d4y/OpenLearnX/sessions/17fba2c8-4f49-4a78-9dc4-483acc8cc945 Co-authored-by: Stalin-143 <161853795+Stalin-143@users.noreply.github.com> --- .../workflows/mirror-repo-events-to-logs.yml | 102 ++++++++++++++++++ README.md | 17 +++ 2 files changed, 119 insertions(+) create mode 100644 .github/workflows/mirror-repo-events-to-logs.yml diff --git a/.github/workflows/mirror-repo-events-to-logs.yml b/.github/workflows/mirror-repo-events-to-logs.yml new file mode 100644 index 0000000..bfcdd2f --- /dev/null +++ b/.github/workflows/mirror-repo-events-to-logs.yml @@ -0,0 +1,102 @@ +name: Mirror repository events to LOGS + +on: + push: + pull_request: + issues: + issue_comment: + pull_request_review: + pull_request_review_comment: + watch: + types: [started] + fork: + create: + delete: + workflow_dispatch: + +permissions: + contents: read + +jobs: + mirror-event-log: + runs-on: ubuntu-latest + steps: + - name: Ensure personal access token exists + env: + LOGS_REPO_PAT: ${{ secrets.LOGS_REPO_PAT }} + run: | + if [ -z "$LOGS_REPO_PAT" ]; then + echo "Missing required secret: LOGS_REPO_PAT" + exit 1 + fi + + - name: Checkout logs repository + uses: actions/checkout@v4 + with: + repository: th30d4y/LOGS + token: ${{ secrets.LOGS_REPO_PAT }} + path: logs-repo + + - name: Append event payload to daily log file + env: + SOURCE_REPOSITORY: ${{ github.repository }} + SOURCE_EVENT_NAME: ${{ github.event_name }} + SOURCE_EVENT_ACTION: ${{ github.event.action }} + SOURCE_ACTOR: ${{ github.actor }} + SOURCE_REF: ${{ github.ref }} + SOURCE_SHA: ${{ github.sha }} + SOURCE_RUN_ID: ${{ github.run_id }} + SOURCE_RUN_ATTEMPT: ${{ github.run_attempt }} + SOURCE_SERVER_URL: ${{ github.server_url }} + run: | + set -euo pipefail + export TZ=UTC + + DAY="$(date +%F)" + LOG_DIR="logs-repo/openlearnx-events/$DAY" + mkdir -p "$LOG_DIR" + LOG_FILE="$LOG_DIR/events.jsonl" + + jq -cn \ + --arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ + --arg repository "$SOURCE_REPOSITORY" \ + --arg event_name "$SOURCE_EVENT_NAME" \ + --arg event_action "$SOURCE_EVENT_ACTION" \ + --arg actor "$SOURCE_ACTOR" \ + --arg ref "$SOURCE_REF" \ + --arg sha "$SOURCE_SHA" \ + --arg run_id "$SOURCE_RUN_ID" \ + --arg run_attempt "$SOURCE_RUN_ATTEMPT" \ + --arg run_url "$SOURCE_SERVER_URL/$SOURCE_REPOSITORY/actions/runs/$SOURCE_RUN_ID" \ + --slurpfile payload "$GITHUB_EVENT_PATH" \ + '{ + timestamp: $timestamp, + source_repository: $repository, + event_name: $event_name, + event_action: (if $event_action == "" then null else $event_action end), + actor: $actor, + ref: (if $ref == "" then null else $ref end), + sha: (if $sha == "" then null else $sha end), + run: { + id: $run_id, + attempt: $run_attempt, + url: $run_url + }, + payload: $payload[0] + }' >> "$LOG_FILE" + + - name: Commit and push logs + run: | + set -euo pipefail + cd logs-repo + git config user.name "openlearnx-log-bot" + git config user.email "openlearnx-log-bot@users.noreply.github.com" + + if git diff --quiet; then + echo "No log changes to commit" + exit 0 + fi + + git add openlearnx-events + git commit -m "log(OpenLearnX): ${{ github.event_name }} @ ${{ github.run_id }}" + git push diff --git a/README.md b/README.md index b6320f0..bf13f48 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,23 @@ pnpm run dev --- +## 🧾 Repository Event Logging Automation + +This repository includes a GitHub Actions workflow at: + +- `.github/workflows/mirror-repo-events-to-logs.yml` + +It captures repository events (push, pull request activity, stars, forks, create/delete, and related interactions) and appends structured JSON logs to: + +- `https://github.com/th30d4y/LOGS` + +### Required setup + +Add this repository secret in **OpenLearnX**: + +- `LOGS_REPO_PAT`: a Personal Access Token with write access to `th30d4y/LOGS` (for example, `contents:write` on that repo). + +---