---
title: Using Gitea/Github actions for triggering Echo
date: 2024-03-08T11:12:00Z
tags:
    - eleventy
    - tech
excerpt: "I decided to start using Robb Knight's Echo tool to syndicate my blog posts to Mastodon, and trigger Webmentions."
---

I decided to start using [Robb Knight's Echo tool](https://echo.rknight.me), to syndicate my blog posts to Mastodon, and trigger Webmentions. I'm not going to go through the configuration of Echo here, the [project README](https://github.com/rknightuk/echo) has some good instructions for setting it up.

However, I have just started using [Gitea Actions](https://docs.gitea.com/usage/actions/overview) for CI on my private Git server, so I'm using a scheduled action to achieve this:

{% raw %}
```yaml
name: Syndicate using echo
on:
  schedule:
    - cron: '*/5 * * * *'
jobs:
  echo:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Setup Node
        uses: actions/setup-node@v3
        with:
          node-version: 20.x
      - name: Install dependencies 📦
        run: npm ci
      - name: Cache build
        id: cache-data
        uses: actions/cache@v4
        with:
          path: data
          key: cache-data-${{ gitea.run_id }}
          restore-keys: |
            cache-data
      - uses: actions/setup-go@v3
        with:
          go-version: '1.20'
      - uses: https://gitea.com/actions/go-hashfiles@v0.0.1
        id: get-hash
        with: 
          patterns: |-
            ./data/*
      - name: Init echo
        if: ${{ steps.get-hash.outputs.hash == ''}}
        run: node index.js init
        env:
          MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }}
          MASTODON_URL: ${{ secrets.MASTODON_URL }}
      - name: Run echo
        run: node index.js
        env:
          MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }}
          MASTODON_URL: ${{ secrets.MASTODON_URL }}
```
{% endraw %}

This:
* Checks out the code
* Sets up node
* Uses the [cache action](https://github.com/actions/cache) to persist the `data` directory between runs
* Uses the `go-hashfiles` action to calculate a hash of the data directory[^1]
* If the hash is empty, initialise Echo
* Run echo

[^1]: If using Github Actions, you can remove these steps and just use the `hashFiles` function