Skip to content

Commit

Permalink
Post a summary of auto updates to Twist
Browse files Browse the repository at this point in the history
  • Loading branch information
norm committed Apr 20, 2021
1 parent d058764 commit 8689ecc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull_content.yaml
Expand Up @@ -42,5 +42,6 @@ jobs:
- name: Commit and PR any changes
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
TWIST_URL: ${{secrets.TWIST_URL}}
run: |
./script/commit_changes "Automatic content updates"
15 changes: 15 additions & 0 deletions script/commit_changes
@@ -1,5 +1,7 @@
#!/usr/bin/env -S bash -euo pipefail

DIFF_BASE='https://github.com/norm/marknormanfrancis.com/commit'

message="${1:-Automated changes}"

git config user.name "GitHub Actions"
Expand All @@ -11,4 +13,17 @@ if [ -n "$(git status --porcelain)" ]; then
git add -A
git commit --message "$message"
git push

rev=$(git rev-parse HEAD)

# ... and send an update
(
echo "# Updated files"
echo ''
echo "[See diff on GitHub]($DIFF_BASE/$rev)"
echo ''
git show --pretty='' --name-only $rev | sed -e 's/^/* /'
) \
| ./script/twist_post $(date +'%Y-%m-%d') $message

fi
22 changes: 22 additions & 0 deletions script/twist_post
@@ -0,0 +1,22 @@
#!/usr/bin/env -S bash -euo pipefail
#
# Send content to a Twist channel integration.

# capture stdin to a file
content=$(mktemp)
cat > $content

title=$(mktemp)
echo "${*:-Automated post}" > $title

# send content to a Twist channel integration
jq --null-input \
--rawfile content $content \
--rawfile title $title \
'{$content,$title}' \
| \
curl \
-X POST \
-H 'Content-type: application/json' \
--data @- \
"$TWIST_URL"

0 comments on commit 8689ecc

Please sign in to comment.