Skip to content
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
71 changes: 71 additions & 0 deletions .github/workflows/sync-files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
name: Sync Files

on:
push:

jobs:
sync:
runs-on: ubuntu-latest
strategy:
matrix:
repository:
- .github
steps:
- name: Checkout source repository
uses: actions/checkout@v5
with:
path: source

- name: Create GitHub App token
uses: actions/create-github-app-token@v2
id: gh-app-token
with:
app-id: ${{ vars.GH_APP_SEM_REL_ID }}
private-key: ${{ secrets.GH_APP_SEM_REL_PEM_FILE }}
owner: ${{ github.ref == 'refs/heads/main' && 'xebis' || 'xebis-test' }}
repositories: ${{ matrix.repository }}

- name: Checkout target repository
uses: actions/checkout@v5
with:
repository: ${{ format('{0}/{1}', github.ref == 'refs/heads/main' && 'xebis' || 'xebis-test', matrix.repository) }}
path: target
token: ${{ steps.gh-app-token.outputs.token }}

- name: Copy files
run: |
yq -r '.copy[]' target/.github/sync.yaml | while IFS= read -r file; do
source_file="source/$file"
target_file="target/$file"
mkdir -p "$(dirname "$target_file")"
cp "$source_file" "$target_file"
done

- name: Detect sync updates
id: updates
working-directory: target
run: |
if output=$(git status --porcelain) && [ -n "$output" ]; then
echo "updated=true" >> "$GITHUB_OUTPUT"
else
echo "updated=false" >> "$GITHUB_OUTPUT"
fi

- name: Output short commit SHA
if: steps.updates.outputs.updated == 'true'
id: sha
working-directory: target
run: |
echo "short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Create Pull Request with applied automatic fixes
if: steps.updates.outputs.updated == 'true'
uses: peter-evans/create-pull-request@v7
with:
path: target
token: ${{ steps.gh-app-token.outputs.token }}
branch: "feature/sync-files-for-${{ steps.sha.outputs.short }}"
commit-message: "chore: [sync-files] sync files"
title: "[Sync Files] Sync Files"
labels: bot
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A collection of GitHub composite actions and reusable workflows.

- [Reusable Megalinter Workflow](#reusable-megalinter-workflow)
- [Reusable Semantic Release Workflow](#reusable-semantic-release-workflow)
- [Sync Files Workflow](#sync-files-workflow)

### Reusable Megalinter Workflow

Expand Down Expand Up @@ -92,6 +93,22 @@ plugins:
- semantic-release-major-tag
```

### Sync Files Workflow

[Sync Files Workflow](.github/workflows/sync-files.yaml) synchronizes the repository contents by creating a pull request to the target repositories.

Configure target repositories:

- Target repositories are specified at the source repository [Sync Files Workflow](.github/workflows/sync-files.yaml) in the matrix.
- Files to sync are specified in the target repository file `.github/sync.yaml`:

```yaml
---
copy:
- .github/workflows/semantic-release.yaml
- .releaserc.yaml
```

## Credits and Acknowledgments

- Martin Bružina - Author
Expand Down