Skip to content
This repository was archived by the owner on Dec 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/template.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
template-repository: jebel-quant/sync_template
template-branch: main
include: |
CODE_OF_CONDUCT.md
CONTRIBUTING.md
include:
- CODE_OF_CONDUCT.md
- CONTRIBUTING.md
exclude:
- README.md
- LICENSE
213 changes: 49 additions & 164 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,220 +1,105 @@
name: 'Sync Template'
description: 'Sync template into a project and optionally create a pull request'
author: 'Thomas Schmelzer'
name: Sync Repository Template
description: Synchronize a repository template into the current project and optionally open a pull request
author: Thomas Schmelzer

inputs:
token:
description: 'GitHub token or PAT for authentication'
required: true
source:
description: 'Path to the YAML configuration file containing template settings'
description: GitHub token or PAT for authentication
required: true

branch:
description: 'Target branch in the current repo'
default: 'sync/update'
description: Target branch for the sync
required: false
default: sync/template-update
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default branch name has been changed from 'sync/update' to 'sync/template-update'. This is a breaking change that could affect existing workflows or automation that depend on the previous default branch name.

Suggested change
default: sync/template-update
default: sync/update

Copilot uses AI. Check for mistakes.

commit-message:
description: 'Commit message for sync'
default: 'chore: sync template'
test-mode:
description: 'If true, skip push and PR creation'
default: 'false'
automerge:
description: 'If true, enable auto-merge on the PR'
default: 'false'
template-ref:
description: 'Tag or branch to check out from the template repository (overrides template-branch)'
description: Commit message for the sync
required: false
default: "chore: sync template"

create-pr:
description: Whether to create a pull request if changes are detected
required: false
default: "true"
Comment on lines +20 to +23
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'template-ref' input has been removed. This prevents users from specifying a specific tag or branch to check out from the template repository, limiting flexibility in template version control.

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +23
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'automerge' input has been removed without providing an alternative mechanism or migration path. Users who were relying on the automerge feature will lose this functionality.

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +23
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'test-mode' input has been removed. This makes it harder to test the action without creating actual commits and pushes, which could complicate local testing and CI workflows.

Copilot uses AI. Check for mistakes.

outputs:
changes-detected:
description: 'Whether changes were detected during the sync (true or false)'
value: ${{ steps.commit-changes.outputs.changes_detected }}
description: Whether changes were detected during the sync (true or false)
value: ${{ steps.sync.outputs.changes_detected }}

runs:
using: "composite"
using: composite
steps:

# ------------------------------------------------------------
# Checkout target repo
# Checkout target repository
# ------------------------------------------------------------
- name: Checkout the target repo
- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ inputs.token }}
fetch-depth: 0

- name: Ensure inside a git repository
shell: bash
run: git rev-parse --is-inside-work-tree >/dev/null || { echo "❌ Not in a git repository"; exit 1; }

# ------------------------------------------------------------
# Parse configuration (repository, branch, ref, includes, excludes)
# ------------------------------------------------------------
- name: Parse configuration file
shell: bash
id: config
run: |
CONFIG_FILE="${{ inputs.source }}"
echo "Reading configuration from ${CONFIG_FILE}"

if [[ ! -f "${CONFIG_FILE}" ]]; then
echo "::error::Configuration file not found: ${CONFIG_FILE}"
exit 1
fi

# Install yq if needed
if ! command -v yq &>/dev/null; then
wget -qO /tmp/yq https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_amd64
chmod +x /tmp/yq
YQ="/tmp/yq"
else
YQ="yq"
fi

TEMPLATE_REPO="$($YQ '.template-repository // ""' "${CONFIG_FILE}")"
if [[ -z "$TEMPLATE_REPO" ]]; then
echo "::error::template-repository missing in ${CONFIG_FILE}"
exit 1
fi
echo "template_repository=$TEMPLATE_REPO" >> $GITHUB_OUTPUT

TEMPLATE_BRANCH="$($YQ '.template-branch // "main"' "${CONFIG_FILE}")"
echo "template_branch=$TEMPLATE_BRANCH" >> $GITHUB_OUTPUT

TEMPLATE_REF="$($YQ '.template-ref // ""' "${CONFIG_FILE}")"
echo "template_ref=$TEMPLATE_REF" >> $GITHUB_OUTPUT

# New: Tag/Ref override
#TEMPLATE_REF_INPUT="${{ inputs.template-ref }}"
#TEMPLATE_REF_CONFIG="$($YQ '.template-ref // ""' "${CONFIG_FILE}")"
#TEMPLATE_REF="${TEMPLATE_REF_INPUT:-$TEMPLATE_REF_CONFIG}"
#echo "template_ref=$TEMPLATE_REF" >> $GITHUB_OUTPUT

# Include patterns - support both pipe (|) and list (-) syntax
INCLUDE_TYPE="$($YQ '.include | type' "${CONFIG_FILE}" 2>/dev/null || echo "null")"
if [[ "$INCLUDE_TYPE" == "!!seq" ]]; then
# It's a YAML list with dashes
INCLUDE="$($YQ '.include[]' "${CONFIG_FILE}")"
else
# It's a string (pipe syntax) or doesn't exist
INCLUDE="$($YQ '.include // ""' "${CONFIG_FILE}")"
fi
echo "include<<EOF" >> $GITHUB_OUTPUT
echo "$INCLUDE" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

# Exclude patterns - support both pipe (|) and list (-) syntax
EXCLUDE_TYPE="$($YQ '.exclude | type' "${CONFIG_FILE}" 2>/dev/null || echo "null")"
if [[ "$EXCLUDE_TYPE" == "!!seq" ]]; then
# It's a YAML list with dashes
EXCLUDE="$($YQ '.exclude[]' "${CONFIG_FILE}")"
else
# It's a string (pipe syntax) or doesn't exist
EXCLUDE="$($YQ '.exclude // ""' "${CONFIG_FILE}")"
fi
echo "exclude<<EOF" >> $GITHUB_OUTPUT
echo "$EXCLUDE" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

# ------------------------------------------------------------
# Sparse checkout template (branch or tag -> ref)
# Tooling
# ------------------------------------------------------------
- name: Sparse checkout template
uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
repository: ${{ steps.config.outputs.template_repository }}
ref: ${{ steps.config.outputs.template_ref || steps.config.outputs.template_branch }}
path: .template-temp
token: ${{ inputs.token }}
fetch-depth: 0
sparse-checkout: ${{ steps.config.outputs.include }}
sparse-checkout-cone-mode: false
version: "0.9.17"
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded version "0.9.17" for the uv tool should ideally be configurable or use a more flexible version constraint (e.g., "latest" or a version range). This makes it easier to keep dependencies up to date without requiring action updates.

Copilot uses AI. Check for mistakes.

# ------------------------------------------------------------
# Clean template and apply excludes
# Validate configuration
# ------------------------------------------------------------
- name: Clean template and apply excludes
- name: Validate rhiza configuration
shell: bash
working-directory: .template-temp
run: |
rm -rf .git
EXCLUDES="${{ steps.config.outputs.exclude }}"

if [[ -n "$EXCLUDES" ]]; then
echo "$EXCLUDES" | while IFS= read -r item; do
[[ -z "$item" ]] && continue
item="$(echo "$item" | xargs)"
rm -rf "$item" 2>/dev/null || true
done
fi

tree -L 2 || ls -R
run: uvx rhiza validate .

# ------------------------------------------------------------
# Apply template + commit & push
# Materialize + commit changes
# ------------------------------------------------------------
- name: Commit and optionally push changes
id: commit-changes
- name: Sync template
id: sync
shell: bash
env:
TEST_MODE: ${{ inputs.test-mode }}
run: |
cp -R .template-temp/. .
rm -rf .template-temp
set -euo pipefail

git checkout -B "${{ inputs.branch }}"

uvx rhiza materialize .

git add -A

if git diff --cached --quiet; then
echo "changes_detected=false" >> $GITHUB_OUTPUT
echo "No changes."
echo "No changes detected."
echo "changes_detected=false" >> "$GITHUB_OUTPUT"
exit 0
fi

echo "changes_detected=true" >> $GITHUB_OUTPUT
echo "changes_detected=true" >> "$GITHUB_OUTPUT"

if git diff --cached --name-only | grep -q '^\.github/workflows/'; then
echo "⚠️ Workflow files modified — PAT with workflow scope required."
echo "⚠️ Workflow files modified — PAT with workflow scope may be required."
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message change from "PAT with workflow scope required" to "PAT with workflow scope may be required" is less definitive. If workflow files are being modified, the PAT definitely requires workflow scope, not just "may" require it. Consider reverting to the more accurate original message.

Suggested change
echo "⚠️ Workflow files modified — PAT with workflow scope may be required."
echo "⚠️ Workflow files modified — PAT with workflow scope required."

Copilot uses AI. Check for mistakes.
fi

git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -m "${{ inputs.commit-message }}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

if [[ "$TEST_MODE" == "true" ]]; then
echo "🧪 Test mode: skipping push"
exit 0
fi

target_branch="${{ inputs.branch }}"
git push origin "HEAD:$target_branch" --force-with-lease
git commit -m "${{ inputs.commit-message }}"
git push origin "HEAD:${{ inputs.branch }}" --force-with-lease

Comment on lines +89 to 90
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The action now always performs a git push even when create-pr is false. If a user sets create-pr to false but still wants to sync locally without pushing, they have no option. Consider making the push conditional based on whether create-pr is true, or adding a separate input to control pushing.

Suggested change
git push origin "HEAD:${{ inputs.branch }}" --force-with-lease
if [ "${{ inputs.create-pr }}" = "true" ]; then
git push origin "HEAD:${{ inputs.branch }}" --force-with-lease
fi

Copilot uses AI. Check for mistakes.
# ------------------------------------------------------------
# Create Pull Request
# ------------------------------------------------------------
- name: Create Pull Request
id: create-pr
if: ${{ inputs.test-mode != 'true' && steps.commit-changes.outputs.changes_detected == 'true' }}
- name: Create pull request
if: ${{ inputs.create-pr == 'true' && steps.sync.outputs.changes_detected == 'true' }}
uses: peter-evans/create-pull-request@v8
with:
token: ${{ inputs.token }}
branch: ${{ inputs.branch }}
commit-message: ${{ inputs.commit-message }}
delete-branch: false
title: "chore: sync template from ${{ steps.config.outputs.template_repository }}@${{ steps.config.outputs.template_ref || steps.config.outputs.template_branch }}"
title: ${{ inputs.commit-message }}
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit-message input is being used as the PR title. This may not be ideal as commit messages and PR titles often have different conventions and purposes. Consider using a separate input for the PR title or constructing a more descriptive title.

Copilot uses AI. Check for mistakes.
body: |
This PR syncs the template from:
**${{ steps.config.outputs.template_repository }} @ ${{ steps.config.outputs.template_ref || steps.config.outputs.template_branch }}**
This pull request synchronizes the repository with its template.

# ------------------------------------------------------------
# Auto-merge
# ------------------------------------------------------------
- name: Enable auto-merge
if: ${{ inputs.automerge == 'true' && steps.create-pr.outputs.pull-request-number }}
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
run: |
gh pr merge ${{ steps.create-pr.outputs.pull-request-number }} \
--merge \
--auto \
--delete-branch
Changes were generated automatically using **rhiza**.
Loading
Loading