Skip to content

-not-cp 練點基礎題 #76

-not-cp 練點基礎題

-not-cp 練點基礎題 #76

name: Auto Push to Threads
on:
push:
branches: [ main ]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq
python -m pip install --upgrade pip
pip uninstall httpx -y
pip install threads-py \
-i https://test.pypi.org/simple \
--extra-index-url https://pypi.org/simple
pip install pandas
# Use Actions Secrets directly; do not write secret.json in runner
- name: Determine commit message and changed files
id: vars
run: |
echo "GITHUB_EVENT_PATH: $GITHUB_EVENT_PATH"
echo "=== event payload ==="
jq . "$GITHUB_EVENT_PATH" || cat "$GITHUB_EVENT_PATH"
# commit message fallback to git log
COMMIT_MSG=$(jq -r '.head_commit.message // empty' "$GITHUB_EVENT_PATH")
if [ -z "$COMMIT_MSG" ]; then
COMMIT_MSG=$(git log -1 --pretty=%B || echo "")
fi
# get changed files from the current commit (one-per-line), convert to space-separated
FILES=$(git diff-tree --no-commit-id --name-only -r HEAD | tr '\n' ' ')
echo "DEBUG: git diff-tree output (one-per-line):"
git diff-tree --no-commit-id --name-only -r HEAD || true
echo "FILES raw (space-separated):"
printf '%s\n' "$FILES"
echo "FILES as bash array (each shown on its own line):"
for f in $FILES; do echo " - [$f]"; done
echo "GITHUB_SHA: $GITHUB_SHA"
echo "git HEAD:"
git rev-parse --verify HEAD || true
echo "git status (porcelain):"
git status --porcelain || true
echo "commit_message<<EOF" >> $GITHUB_OUTPUT
echo "$COMMIT_MSG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
echo "$FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Run auto push to Threads script
run: |
echo "Commit message:" "${{ steps.vars.outputs.commit_message }}"
echo "Changed files:" "${{ steps.vars.outputs.changed_files }}"
python3 auto_push-to-threads.py "${{ steps.vars.outputs.commit_message }}" ${{ steps.vars.outputs.changed_files }}
env:
THREADS_USER_ID: ${{ secrets.THREADS_USER_ID }}
THREADS_ACCESS_TOKEN: ${{ secrets.THREADS_ACCESS_TOKEN }}
THREADS_APP_SECRET: ${{ secrets.THREADS_APP_SECRET }}