-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (91 loc) · 3.28 KB
/
Copy pathpost-reel.yml
File metadata and controls
102 lines (91 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Post weekly reel to Instagram
# Generates the week's reel, commits it so GitHub Pages serves it at a public
# URL, then publishes it to Instagram via the Meta Graph API.
#
# Required repo secrets (Settings → Secrets and variables → Actions):
# IG_USER_ID Instagram Business account id
# IG_ACCESS_TOKEN long-lived access token
# See tools/REELS_AUTOMATION.md for the one-time setup.
on:
schedule:
- cron: "0 16 * * 3" # every Wednesday 16:00 UTC
workflow_dispatch:
inputs:
key:
description: "Edition key to post (blank = auto rotation)"
required: false
default: ""
color:
description: "Ink color"
required: false
default: "red"
dry_run:
description: "Build + print only, do not publish"
type: boolean
required: false
default: false
permissions:
contents: write # to commit the generated mp4
concurrency:
group: post-reel
cancel-in-progress: false
jobs:
post:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install fonts and Python deps
run: |
sudo apt-get update
sudo apt-get install -y fonts-ipafont-gothic fonts-liberation
python -m pip install --upgrade pip
pip install pillow numpy imageio-ffmpeg
- name: Resolve edition key
id: pick
run: |
KEY="${{ github.event.inputs.key }}"
if [ -z "$KEY" ]; then
KEY=$(python - <<'PY'
import json, time
src=open("data/editions.js").read(); src=src[src.index("{"):src.rindex("}")+1]
order=json.loads(src).get("plotterOrder")
print(order[int(time.time()//(7*86400))%len(order)])
PY
)
fi
COLOR="${{ github.event.inputs.color }}"; COLOR="${COLOR:-red}"
echo "key=$KEY" >> "$GITHUB_OUTPUT"
echo "color=$COLOR" >> "$GITHUB_OUTPUT"
echo "Posting: $KEY ($COLOR)"
- name: Generate reel
run: |
mkdir -p reels
python - <<PY
import sys; sys.path.insert(0, "tools")
import gen_reel
gen_reel.render("${{ steps.pick.outputs.key }}", "${{ steps.pick.outputs.color }}",
dur=15, fps=30,
out="reels/${{ steps.pick.outputs.key }}-${{ steps.pick.outputs.color }}-reel.mp4")
PY
- name: Commit reel so Pages can serve it
run: |
git config user.name "plotflow-bot"
git config user.email "bot@plotflow.io"
git add reels/*.mp4
if git diff --staged --quiet; then
echo "No change to reel file."
else
git commit -m "Add reel for ${{ steps.pick.outputs.key }} [skip ci]"
git push origin HEAD:${{ github.ref_name }}
fi
- name: Publish to Instagram
env:
IG_USER_ID: ${{ secrets.IG_USER_ID }}
IG_ACCESS_TOKEN: ${{ secrets.IG_ACCESS_TOKEN }}
run: |
ARGS="--key ${{ steps.pick.outputs.key }} --color ${{ steps.pick.outputs.color }}"
if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then ARGS="$ARGS --dry-run"; fi
python tools/post_reel.py $ARGS