name: "fsrc - Embed Anything"
description: "A GitHub Action that embeds source files into any text file."
author: "urmzd"
branding:
icon: "file"
color: "gray-dark"
inputs:
files:
description: "Space-separated list of files to process."
default: "README.md"
commit-message:
description: "The message to associate with the commit containing the modified files."
default: "chore: embed source files"
commit-name:
description: "Git user name for commits."
default: "github-actions[bot]"
commit-email:
description: "Git user email for commits."
default: "41898282+github-actions[bot]@users.noreply.github.com"
commit-push:
description: "Set to false to skip the push."
default: "true"
commit-dry:
description: "Set to true to skip the commit."
default: "false"
github-token:
description: "GitHub token for downloading the binary."
default: ${{ github.token }}
runs:
using: "composite"
steps:
- name: Configure git identity
shell: bash
run: |
echo "::group::Configure git identity"
echo "Setting user.name=${{ inputs.commit-name }}"
git config user.name "${{ inputs.commit-name }}"
echo "Setting user.email=${{ inputs.commit-email }}"
git config user.email "${{ inputs.commit-email }}"
echo "::endgroup::"
- name: Download fsrc binary
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
FSRC_REPO: ${{ github.action_repository }}
FSRC_REF: ${{ github.action_ref }}
run: |
set -euo pipefail
echo "::group::Download fsrc binary"
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
echo "Detected OS=$OS ARCH=$ARCH"
case "$ARCH" in
x86_64) ARCH="x86_64" ;;
aarch64|arm64) ARCH="aarch64" ;;
*) echo "::error::Unsupported architecture: $ARCH"; exit 1 ;;
esac
case "$OS" in
linux) TARGET="${ARCH}-unknown-linux-musl" ;;
darwin) TARGET="${ARCH}-apple-darwin" ;;
*) echo "::error::Unsupported OS: $OS"; exit 1 ;;
esac
BINARY_NAME="fsrc-${TARGET}"
DEST="$HOME/.local/bin/fsrc"
mkdir -p "$HOME/.local/bin"
echo "Target=$TARGET Binary=$BINARY_NAME"
# Resolve action ref to a release tag.
# exact tag (v3.5.2) → prefix match (v3 → v3.x.x) → latest release
API="https://api.github.com/repos/${FSRC_REPO}"
TAGS=$(curl -fsSL "${API}/releases?per_page=100" | jq -r '.[].tag_name')
RELEASE_TAG=$(echo "$TAGS" | grep -xF "$FSRC_REF" | head -1 || true)
[ -z "$RELEASE_TAG" ] && RELEASE_TAG=$(echo "$TAGS" | grep "^${FSRC_REF}\." | head -1 || true)
[ -z "$RELEASE_TAG" ] && RELEASE_TAG=$(echo "$TAGS" | head -1)
if [ -z "$RELEASE_TAG" ]; then
echo "::error::No releases found for ${FSRC_REPO}"
exit 1
fi
echo "Resolved ref=${FSRC_REF} → release=${RELEASE_TAG}"
URL="https://github.com/${FSRC_REPO}/releases/download/${RELEASE_TAG}/${BINARY_NAME}"
echo "Downloading ${URL}"
curl -fsSL "$URL" -o "$DEST"
chmod +x "$DEST"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
echo "fsrc binary installed to ${DEST}"
echo "::endgroup::"
- name: Run fsrc
shell: bash
run: |
echo "::group::Run fsrc"
echo "Processing files: ${{ inputs.files }}"
# shellcheck disable=SC2086
fsrc run ${{ inputs.files }}
echo "::endgroup::"
- name: Stage, commit, and push
shell: bash
run: |
echo "::group::Stage, commit, and push"
echo "Staging files: ${{ inputs.files }}"
# shellcheck disable=SC2086
git add ${{ inputs.files }}
if [ "${{ inputs.commit-dry }}" = "false" ]; then
if git diff --staged --quiet; then
echo "::notice::No changes to commit"
else
echo "Committing with message: ${{ inputs.commit-message }}"
git commit -m "${{ inputs.commit-message }}"
fi
else
echo "Dry run — skipping commit"
fi
if [ "${{ inputs.commit-push }}" = "true" ]; then
echo "Pushing to remote"
git push
else
echo "Push disabled — skipping"
fi
echo "::endgroup::"