Post to social media from GitHub Actions with Ampost

By Published Updated

A GitHub Actions workflow can run the Ampost CLI, and one ampost post publishes to every network you name. Add the workflow file below and an AMPOST_API_KEY secret, and each published release is announced with its name and link. You can also run it by hand with your own text.

What you'll build

  • A workflow that posts "<repo> <release> is out: <link>" to your social accounts when you publish a release.
  • A manual Run workflow button that posts any text you type.
  • A step you can copy into any job: after a deploy, on a new tag, or on a schedule.

Before you start

  • An Ampost account. The Free plan includes the REST API (2 social accounts and 15 posts every 30 days); scheduling needs the Pro plan or higher, and X the Max and Scale plans. See pricing.
  • An API key from Settings, API keys. The key is shown once, so copy it when you create it. Treat it like a password.
  • At least one connected social account, under Settings, Connections in the dashboard.
  • A GitHub repository where you can add workflows, secrets and variables.

Download

Free to use and change. The file is shown in full below, so you can read it before you run it.

post-release-to-social.yml
# Announce every GitHub release on social media with the Ampost CLI.
#
# Setup (guide: https://ampost.io/how-to/post-to-social-media-from-github-actions):
#   1. Save this file as .github/workflows/post-release-to-social.yml in your repository.
#   2. Settings > Secrets and variables > Actions:
#      - secret   AMPOST_API_KEY   an API key from https://ampost.io/app/settings/api-keys
#      - variable AMPOST_PLATFORMS comma-separated networks, e.g. bluesky,threads,discord
#   3. Publish a release, or run the workflow by hand from the Actions tab.
#
# The CLI (https://ampost.io/docs/tools/cli) is installed from npm: ampost-cli 0.1.x.

name: Post release to social media

on:
  release:
    types: [published]
  workflow_dispatch:
    inputs:
      text:
        description: Post text
        required: true

permissions: {}

jobs:
  post:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: Install the Ampost CLI
        run: npm install -g ampost-cli@0.1

      - name: Post to social media with Ampost
        env:
          AMPOST_API_KEY: ${{ secrets.AMPOST_API_KEY }}
          AMPOST_PLATFORMS: ${{ vars.AMPOST_PLATFORMS }}
          # Passed through env, never pasted into the script, so a release name can't inject shell code.
          RELEASE_NAME: ${{ github.event.release.name || github.event.release.tag_name }}
          RELEASE_URL: ${{ github.event.release.html_url }}
          RELEASE_ID: ${{ github.event.release.id }}
          MANUAL_TEXT: ${{ github.event.inputs.text }}
          REPOSITORY: ${{ github.repository }}
          RUN_ID: ${{ github.run_id }}
        run: |
          set -euo pipefail
          if [ -z "${AMPOST_API_KEY}" ]; then echo "::error::Add the AMPOST_API_KEY secret"; exit 1; fi
          if [ -z "${AMPOST_PLATFORMS}" ]; then echo "::error::Add the AMPOST_PLATFORMS variable, e.g. bluesky,threads"; exit 1; fi

          if [ -n "${RELEASE_ID}" ]; then
            TEXT="${REPOSITORY} ${RELEASE_NAME} is out: ${RELEASE_URL}"
            # One key per release: a re-run of this job never posts the release twice.
            set -- --link "${RELEASE_URL}" --idempotency-key "release-${REPOSITORY}-${RELEASE_ID}"
          else
            TEXT="${MANUAL_TEXT}"
            set -- --idempotency-key "manual-${REPOSITORY}-${RUN_ID}"
          fi

          # The text goes in on stdin, so a text that starts with "-" is not read as an option.
          # --wait waits for every network's result: the job fails (exit 10) if one refused the post.
          printf '%s' "$TEXT" | ampost post --text-file - -p "$AMPOST_PLATFORMS" --wait --wait-timeout 300 "$@"

Steps

  1. 1. Add the workflow file

    Download the workflow above and commit it to your repository as .github/workflows/post-release-to-social.yml.

  2. 2. Add the API key secret and the networks

    In the repository, open Settings, Secrets and variables, Actions. Add a secret AMPOST_API_KEY with your key, then, on the Variables tab, a variable AMPOST_PLATFORMS with the networks to post to, for example bluesky,threads,discord.

    Platform keys: instagram (Instagram), facebook (Facebook), linkedin (LinkedIn), tiktok (TikTok), threads (Threads), twitter (X), discord (Discord), telegram (Telegram), bluesky (Bluesky), youtube (YouTube), pinterest (Pinterest).

    Settings > Secrets and variables > Actions
    Secret    AMPOST_API_KEY    amp_live_your_key_here
    Variable  AMPOST_PLATFORMS  bluesky,threads,discord
  3. 3. Publish a release

    Publish a release (Releases, Draft a new release, Publish). The workflow posts the repository name, the release name and its link. To test without a release, open Actions, Post release to social media, Run workflow, and type a text.

  4. 4. Check the run

    The CLI waits until every network has answered, then the job log shows the post's id and status and one line per network, with the link to each live post. If Ampost refuses the post, or one network does, the job fails with the error, so GitHub emails you.

    job log
    Post:    6f1c2a4e-...
    Status:  published
    Text:    acme/app v1.2.0 is out: https://github.com/acme/app/releases/tag/v1.2.0
    
    PLATFORM  STATUS     URL OR ERROR
    bluesky   published  https://bsky.app/profile/.../post/...
    threads   published  https://www.threads.net/@.../post/...

How the workflow works

The first step installs the CLI from npm (npm install -g ampost-cli@0.1); Node is already on GitHub's runners. The second passes every value through env, so a release title can't inject shell code, and gives the text to ampost post on stdin (--text-file -), so a text that starts with a dash is not read as an option. The job has no repository permissions (permissions: {}).

--wait waits for each network's result and exits with 10 if one refused the post. --idempotency-key is built from the release's id: if you re-run the job, or the CLI retries after a timeout, Ampost returns the first post instead of posting the release twice.

Change the text or the trigger

Edit the TEXT= line to change the post, for example to add hashtags. To post after a deploy instead, copy the two steps into your deploy job; to post on a schedule, add a schedule: trigger with a cron line. To schedule the post itself, replace --wait --wait-timeout 300 with --schedule 2027-01-14T15:00:00Z; ampost post --help lists the other options, such as -m for an image.

FAQ

Does this need a GitHub Action from the Marketplace?

No. The workflow installs the Ampost CLI (ampost-cli, open source, MIT) from npm with the Node that GitHub's ubuntu-latest runners already have, so there is no third-party action to trust or update. The version is pinned to 0.1.x.

Will a draft or a pre-release be posted?

Drafts are not: the workflow runs when a release is published. A pre-release is published too, so it is posted; add if: !github.event.release.prerelease to the job to skip pre-releases.

Which social networks can I post to from GitHub Actions?

Every network you connect to Ampost: Instagram, Facebook, LinkedIn, TikTok, Threads, X, Discord, Telegram, Bluesky, YouTube, Pinterest. Name them by key in targets[].platforms; X is twitter. LinkedIn and TikTok are coming soon.

Can I schedule a post instead of publishing it now?

Yes. Send scheduledFor with an ISO 8601 time (for example 2027-01-14T15:00:00Z) instead of publishNow: true, and Ampost publishes it then. Scheduling needs the Pro plan or higher.

What happens if the same request is sent twice?

The templates send an Idempotency-Key header. A retry with the same key within 24 hours returns the first post instead of creating a second one, so a retried step never posts twice.