💾 Archived View for capsule.jbowdre.lol › gemlog › 2024-03-07-gitops-omglol.gmi captured on 2024-07-08 at 23:15:47. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-05-10)
-=-=-=-=-=-=-
I've been active on omg.lol ("the best internet address that you’ve ever had") for several months now, and have really been enjoying my stay. omg.lol provides a number of delightfully-simple services, and it ties them together with a friendly API.
Last month, I made use of the Pastebin API to power near-realtime weather information on my omg.lol profile page:
(Near) Realtime Weather on profile.lol
Last night, I crafted some quick GitHub Actions workflows to talk to the Now Page and Web endpoints and make updates to those pages with simple git commits.
This brings a few benefits:
I wound up with a pair of actions for each page.
The first periodically fetches the latest version of the page from the API and commits it to the repo (in case it gets modified outside of git):
name: Fetch Now Page on: schedule: - cron: "* */4 * * *" jobs: fetch-now-page: runs-on: ubuntu-latest permissions: contents: write steps: - name: Checkout uses: actions/checkout@v2 - name: Fetch Now Page run: | curl --location --header "Authorization: Bearer ${{ secrets.OMG_TOKEN }}" \ "https://api.omg.lol/address/${{ secrets.OMG_ADDR }}/now" | \ jq -r .response.now.content > now.md - name: Commit Now Page uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: 'fetch /now page' file_pattern: 'now.md'
This will run every four hours, and uses `git-auto-commit-action` to commit new versions of `now.md` as needed.
Git Auto Commit on GitHub Marketplace
And the second workflow is used for sending a modified now page back to omg.lol:
name: Update Now Page on: push: paths: - 'now.md' jobs: update-now-page: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - name: Update Now Page run: | request_body='{"listed": "1", "content": '"$(jq -Rsa . now.md)"'}' curl --location --request POST --header "Authorization: Bearer ${{ secrets.OMG_TOKEN }}" \ "https://api.omg.lol/address/${{ secrets.OMG_ADDR }}/now" \ --data "$request_body"
This one is triggered by any `git push` with a commit which modifies the `now.md` file.
I'm handling the web page updates in basically the same way, with the minor adjustment of needing to manage the web content, css, and custom head independently:
- name: Fetch Web Page run: | response=$(curl --location --header "Authorization: Bearer ${{ secrets.OMG_TOKEN }}" \ "https://api.omg.lol/address/${{ secrets.OMG_ADDR }}/web" | \ jq -r .response) jq -r .content <<< $response > web.md jq -r .css <<< $response > web.css jq -r .head <<< $response > web_head.html
- name: Update Web Page run: | request_body='{"publish": true, "content": '"$(jq -Rsa . web.md)"', "css": '"$(jq -Rsa . web.css)"', "head": '"$(jq -Rsa . web_head.html)"'}' curl --location --request POST --header "Authorization: Bearer ${{ secrets.OMG_TOKEN }}" \ "https://api.omg.lol/address/${{ secrets.OMG_ADDR }}/web" \ --data "$request_body"
The full code (as well as my weather hijinks) are in my lolz repo. Feel free to steal and improve upon it!
And to see the fruits of my labors, check out:
─────
CC BY-SA