Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/social-bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Morrow Brief bot

# The Telegram bot's fallback path: answer commands by polling every five minutes.
# The faster path is the Cloudflare Worker in bot/worker.js; this workflow also sets its webhook.
# The scheduled run does nothing until the repo variable MORROW_BOT is set to "on". See docs/SOCIAL.md.

on:
schedule:
- cron: "*/5 * * * *"
workflow_dispatch:
inputs:
action:
description: What to do
type: choice
default: poll
options:
- poll
- set-webhook
- delete-webhook
url:
description: Worker URL, for set-webhook (https://...workers.dev)
type: string
required: false

permissions:
contents: read

concurrency:
group: morrow-bot
cancel-in-progress: false

jobs:
poll:
if: >-
(github.event_name == 'schedule' && vars.MORROW_BOT == 'on') ||
(github.event_name == 'workflow_dispatch' && inputs.action == 'poll')
runs-on: ubuntu-latest
timeout-minutes: 8
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: scripts
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: scripts/social_requirements.txt
- name: Install
run: pip install -r scripts/social_requirements.txt
- name: Fetch today's feed
run: |
mkdir -p data
curl -fsSL "https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/social-data/feed.json" -o data/feed.json \
|| echo "no feed published yet, the bot will say the edition is not ready"
- name: Answer messages
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
run: python scripts/social_bot.py poll --feed data/feed.json --listen 240

webhook:
if: github.event_name == 'workflow_dispatch' && inputs.action != 'poll'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: scripts
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: scripts/social_requirements.txt
- name: Install
run: pip install -r scripts/social_requirements.txt
- name: Point Telegram at the Worker
if: inputs.action == 'set-webhook'
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_WEBHOOK_SECRET: ${{ secrets.TELEGRAM_WEBHOOK_SECRET }}
WORKER_URL: ${{ inputs.url }}
run: python scripts/social_bot.py set-webhook --url "$WORKER_URL"
- name: Remove the webhook
if: inputs.action == 'delete-webhook'
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
run: python scripts/social_bot.py delete-webhook
122 changes: 122 additions & 0 deletions .github/workflows/social.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Morrow Brief

# Posts the day's digest and a few alerts to the Morrow Brief pages when the edition changes.
# The schedule is a fallback in case the generator's pushes do not start workflows; a run with
# nothing new to post changes nothing.
# With no secrets set it sends nothing and records every target as skipped. See docs/SOCIAL.md.

on:
push:
branches: [main]
paths:
- index.html
pull_request:
paths:
- "scripts/social_*"
- "tests/social/**"
- "bot/**"
- "assets/fonts/**"
- ".github/workflows/social*.yml"
schedule:
- cron: "17 */3 * * *"
workflow_dispatch:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: scripts/social_requirements.txt
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Install
run: pip install -r scripts/social_requirements.txt
- name: Python tests
run: python -m unittest discover -s tests/social -v
- name: Worker tests
run: node --test bot/worker.test.mjs
- name: Render what today's page would post
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
run: python scripts/social_post.py preview --page index.html --out preview
- name: Keep the preview
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
uses: actions/upload-artifact@v4
with:
name: morrow-brief-preview
path: preview
retention-days: 14

publish:
needs: test
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: write
concurrency:
group: morrow-social
cancel-in-progress: false
env:
RUN_ID: ${{ github.run_id }}-${{ github.run_attempt }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: scripts/social_requirements.txt
- name: Install
run: pip install -r scripts/social_requirements.txt

- name: Open the data branch
run: |
git config user.name "morrow-brief[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
set +e
git ls-remote --exit-code --heads origin social-data > /dev/null
found=$?
set -e
if [ "$found" -eq 0 ]; then
git fetch --depth 1 origin social-data
git worktree add --detach data FETCH_HEAD
elif [ "$found" -eq 2 ]; then
echo "social-data does not exist yet, starting empty"
git worktree add --detach data HEAD
git -C data rm -rf --quiet .
else
# Starting from an empty state here could post today's digest a second time.
echo "::error::could not read the social-data branch (git exit $found); nothing posted"
exit 1
fi

- name: Pick and freeze the next post
run: python scripts/social_post.py build --page index.html --out data --run "$RUN_ID"

- name: Save the claim before anything is sent
run: |
sha="$(bash scripts/social_save.sh "Morrow Brief data, run $RUN_ID (before delivery)")"
echo "DATA_SHA=$sha" >> "$GITHUB_ENV"

- name: Deliver
env:
BUFFER_API_KEY: ${{ secrets.BUFFER_API_KEY }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
MORROW_BUFFER_CHANNELS: ${{ vars.MORROW_BUFFER_CHANNELS }}
run: |
python scripts/social_post.py deliver --out data --run "$RUN_ID" \
--image-base "https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/${DATA_SHA}/" \
--image-base "https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/social-data/"

- name: Save the results
if: always() && env.DATA_SHA != ''
run: bash scripts/social_save.sh "Morrow Brief data, run $RUN_ID" "$DATA_SHA"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__pycache__/
*.pyc
node_modules/
/preview/
/data/
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ A planned add-on: last night's US move plus the rupiah, coal, oil and nickel, ma
- `.github/workflows/waitlist.yml` thanks each sign-up and keeps a live tally issue up to date (`scripts/waitlist_tally.py`, tests in `tests/`).
- Success line: 50 sign-ups between 2026-11-08 and 2026-11-22. 15-49 means rework the pitch; under 15 means stop.

## Morrow Brief (social page)

The same edition as a page channel: one morning digest of five stories, plus a few alerts for stories that three or more outlets report. Every post carries its outlet count, a link and a typographic card. Telegram is posted to directly; Instagram, Threads and X go through Buffer. A Telegram bot answers section commands and `/find`.

- `.github/workflows/social.yml` ("Morrow Brief") runs the tests on every pull request. On `main` it builds the posts from the published `index.html` and delivers them.
- `.github/workflows/social-bot.yml` ("Morrow Brief bot") sets the bot's webhook, or polls as a slower fallback.
- Setup, post formats, failure handling and what is not verified yet: [docs/SOCIAL.md](docs/SOCIAL.md).

Nothing is posted until the secrets are added, and no post has been sent to a real platform yet.

## Notes

- Built by [Juwen Lie](https://github.com/juw12) as an independent personal project. Still being built, so expect changes.
Expand Down
93 changes: 93 additions & 0 deletions assets/fonts/OFL-SourceSans3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright 2010-2024 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries.

This Font Software is licensed under the SIL Open Font License, Version 1.1.

This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Loading
Loading