Skip to content
name: Publish Release Announcement to Mastodon
on:
release:
types:
- published
workflow_dispatch:
inputs:
version-tag:
description: 'Version to announce'
required: true
type: string
dry-run:
description: 'Dry run'
default: true
type: boolean
permissions:
contents: read
jobs:
toot:
name: Generate Mastodon Toot
runs-on: ubuntu-latest
environment: production
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
fosstodon.org:443
github.com:443
- name: Checkout Repository
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- name: Current Version
if: ${{ !github.event.inputs.version-tag }}
run: |
CURRENT_VERSION="$(grep -E '__version__' xclim/__init__.py | cut -d ' ' -f3)"
echo "version=v${CURRENT_VERSION}" >> $GITHUB_ENV
- name: Set Version from Input
if: ${{ github.event.inputs.version-tag }}
run: |
echo "version=${{ github.event.inputs.version-tag }}" >> $GITHUB_ENV
- name: Get Release Description
if: ${{ !endsWith(env.current_version, '-dev') }}
id: get_release_description
run: |
# Fetch the release information using the GitHub API
RELEASE_INFO=$(curl -sH "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.version }}")
# Extract the release description from the response
RELEASE_DESCRIPTION=$(echo "$RELEASE_INFO" | jq -r .body)
# Remove Markdown links and the space preceding them
CLEANED_DESCRIPTION=$(echo "$RELEASE_DESCRIPTION" | sed -E 's/\ \(\[[^]]+\]\([^)]+\)\)//g')
# Extract the first line of the release description
CONTRIBUTORS=$(echo "$CLEANED_DESCRIPTION" | head -n 1)
echo "contributors=${CONTRIBUTORS}" >> $GITHUB_ENV
- name: Prepare Message
id: render_template
uses: chuhlomin/render-template@807354a04d9300c9c2ac177c0aa41556c92b3f75 # v1.10
with:
template: .github/publish-mastodon-template.md
vars: |
version: ${{ env.version }}
- name: Message Preview
run: |
echo "${{ steps.render_template.outputs.result }}${{ env.contributors }}"
- name: Send toot to Mastodon
if: ${{ github.event.inputs.dry-run != 'true' }} || ${{ github.event_name == 'release' }}
uses: cbrgm/mastodon-github-action@b26d62619432b20c2129edd86f07f7ede9797fc9 # v2.1.9
with:
url: ${{ secrets.MASTODON_URL }}
access-token: ${{ secrets.MASTODON_ACCESS_TOKEN }}
message: "${{ steps.render_template.outputs.result }}${{ env.contributors }}"
language: "en"
visibility: "public"