Skip to content

Commit

Permalink
chore(deploy): deploy to tiddlyhost
Browse files Browse the repository at this point in the history
  • Loading branch information
oflg committed Mar 3, 2024
1 parent 765aec6 commit 82710fb
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 18 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ jobs:
- name: Build library and static website
run: npm run publish

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release

- name: Deploy
- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist

- name: Deploy to tiddlyhost
env:
THOST_TOKEN: ${{ secrets.TH_PASSWORD }}
run: for file in $(find ./dist/empty -type f -regex ".*\.html"); do site=${file%.html}; site=${site#dist/empty/}; if [ "$site" == "index" ]; then site="tidme"; else site="tidme-${site,,}"; fi; ./bin/thost-uploader $site $file $THOST_EMAIL $TH_PASSWORD; done

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
22 changes: 11 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ public-dist
# for TiddlyWiki
dist/
output/
*/tiddlers/$__language.tid
*/tiddlers/$__StoryList.tid
*/tiddlers/$__StoryList_*.tid
*/tiddlers/$__keepstate_*
*/tiddlers/$__Import.tid
*/tiddlers/$__UpgradeLibrary
*/tiddlers/$__UpgradeLibrary_List
*/tiddlers/$__temp_*
*/tiddlers/$__view.tid
*/tiddlers/$__config_Navigation_openLinkFromInsideRiver.tid
*/tiddlers/$__config_Navigation_openLinkFromOutsideRiver.tid
**/\$__language.tid
**/\$__StoryList.tid
**/\$__StoryList_*.tid
**/\$__keepstate_*
**/\$__Import.tid
**/\$__UpgradeLibrary
**/\$__UpgradeLibrary_List
**/\$__temp_*
**/\$__view.tid
**/\$__config_Navigation_openLinkFromInsideRiver.tid
**/\$__config_Navigation_openLinkFromOutsideRiver.tid
73 changes: 73 additions & 0 deletions bin/thost-uploader
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
#
# Bash script showing how to use curl to save to a Tiddlyhost site.
#
# Example usage:
# ./thost-uploader yoursite newcontent.html youremail@example.com yourpassword
#
# To avoid including your password in scripts, you could do something like
# this for example:
# echo yourpassword > ~/.thostpass
# chmod 600 ~/.thostpass
#
# Then:
# ./thost-uploader yoursite newcontent.html youremail@example.com $(cat ~/.thostpass)
#

show_usage() {
echo Usage:
echo " $0 <sitename> <tiddlywikifile> <email> <password>"
exit 1
}

SITE=$1
FILE=$2
EMAIL=$3
PASSWD=$4

DOWNLOAD_DIR=${DOWNLOAD_DIR:-.}
mkdir -p $DOWNLOAD_DIR

[[ -z "$SITE" ]] && show_usage
[[ -z "$FILE" ]] && show_usage
[[ -z "$EMAIL" ]] && show_usage
[[ -z "$PASSWD" ]] && show_usage

[[ ! -r "$FILE" ]] && echo "Can't read file $FILE!" && exit 1

TIDDLYHOST=tiddlyhost.com
SIGN_IN=https://$TIDDLYHOST/users/sign_in
COOKIES=$(mktemp)
CURL="curl -s --cookie-jar $COOKIES --cookie $COOKIES"

# Read authenticity_token
TOKEN=$( $CURL $SIGN_IN | grep '"csrf-token"' | cut -d'"' -f4 )

# Log in
$CURL -X POST $SIGN_IN \
-d "authenticity_token=$TOKEN" \
-d "user[email]=$EMAIL" \
-d "user[password]=$PASSWD" \
> /dev/null

# Confirm that auth worked
OK=$( $CURL -I "https://$TIDDLYHOST/sites" | head -1 | grep '200 OK' )
[[ -z "$OK" ]] && echo "Authentication failed." && exit 1

# Download a copy just in case something goes wrong
# $CURL "https://$SITE.$TIDDLYHOST/download" -o $DOWNLOAD_DIR/$SITE.$(date +%Y%m%d%H%M%S).backup.html

# Now upload the new TiddlyWiki file
OK=$( $CURL -i -X PUT --data-binary "@$FILE" \
-H "Content-Type: text/html;charset=UTF-8" \
"https://$SITE.$TIDDLYHOST/" | grep '204 No Content')

# 204 means it worked
if [[ -z "$OK" ]]; then
echo "Upload failed." && exit 1
else
echo "Uploaded $FILE to https://$SITE.$TIDDLYHOST/"
fi

# Clean up
rm $COOKIES

0 comments on commit 82710fb

Please sign in to comment.