-
Notifications
You must be signed in to change notification settings - Fork 0
Changes from all commits
1b685fe
383b1a9
8005bb4
82f372e
866fe90
1987245
98824f5
b930f70
1188ef2
730d159
9ff2822
7b0ac4f
52dbfa8
b0fbf68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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 | ||||||||||||
|
|
||||||||||||
| 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
|
||||||||||||
|
|
||||||||||||
| 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" | ||||||||||||
|
||||||||||||
|
|
||||||||||||
| # ------------------------------------------------------------ | ||||||||||||
| # 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." | ||||||||||||
|
||||||||||||
| echo "⚠️ Workflow files modified — PAT with workflow scope may be required." | |
| echo "⚠️ Workflow files modified — PAT with workflow scope required." |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
| 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
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.