Skip to content
This repository was archived by the owner on Dec 25, 2025. It is now read-only.

Commit 6fefeb8

Browse files
committed
fixing integration test?
1 parent 4fa016d commit 6fefeb8

File tree

2 files changed

+47
-26
lines changed

2 files changed

+47
-26
lines changed

README.md

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ on:
1616
jobs:
1717
sync:
1818
runs-on: ubuntu-latest
19+
# Optional: Add permissions for the default GITHUB_TOKEN
20+
# permissions:
21+
# contents: write
22+
# workflows: write # Required to modify workflow files
1923
steps:
2024
- name: Checkout
2125
uses: actions/checkout@v5
@@ -34,21 +38,18 @@ jobs:
3438
exclude: |
3539
README.md
3640
LICENSE
37-
env:
38-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
# Option 1: Use default GITHUB_TOKEN (won't work for workflow files unless permissions are set above)
42+
token: ${{ secrets.GITHUB_TOKEN }}
43+
44+
# Option 2: Use a PAT with workflow permissions (recommended for syncing workflow files)
45+
# token: ${{ secrets.PAT_WITH_WORKFLOW_SCOPE }}
3946
```
4047

4148
## Inputs
4249

4350
| Input | Description | Required | Default |
4451
|-------|-------------|----------|---------|
45-
| `template-repository` | Repository to sync from | Yes | - |
46-
| `template-branch` | Branch to sync from in the template repo | No | `main` |
47-
| `branch` | Branch to sync changes to in the target repo | No | `sync/update-configs` |
48-
| `commit-message` | Commit message for sync | No | `chore: sync template` |
49-
| `include` | List of files and folders to include (multi-line) | No | See action.yml |
50-
| `exclude` | List of files and folders to exclude (multi-line) | No | See action.yml |
51-
| `token` | Token to use for authentication | No | `${{ github.token }}` |
52+
5253

5354
## How It Works
5455

@@ -58,8 +59,33 @@ This action performs the following steps:
5859
2. Removes excluded files/folders from the template
5960
3. Copies the template files into the target repository
6061
4. Commits and pushes the changes to the specified branch in the target repository
62+
5. Optionally creates a pull request for the changes
63+
64+
The action uses sparse checkout to minimize the amount of data that needs to be downloaded, making it efficient even with large template repositories.
65+
66+
The pull request creation step uses GitHub's REST API to check if a PR already exists for the branch and creates one if needed. This ensures that multiple workflow runs don't create duplicate PRs.
67+
68+
### GitHub Token Permissions
69+
70+
When using this action to sync workflow files (files in `.github/workflows/`), you need to be aware of GitHub's token permission restrictions:
71+
72+
1. **Default `GITHUB_TOKEN`**: Does not have permission to update workflow files in a repository. If you try to sync workflow files using the default token, you'll get an error like:
73+
```
74+
! [remote rejected] HEAD -> sync/update (refusing to allow a GitHub App to create or update workflow without `workflows` permission)
75+
```
76+
77+
2. **Personal Access Token (PAT)**: To sync workflow files, you must use a PAT with the `workflow` scope. Configure this in your workflow:
78+
```yaml
79+
with:
80+
token: ${{ secrets.PAT_WITH_WORKFLOW_SCOPE }}
81+
```
82+
83+
3. **Repository Settings**: Alternatively, you can modify the default token permissions in your repository settings:
84+
- Go to Settings > Actions > General
85+
- Under "Workflow permissions", select "Read and write permissions"
86+
- Check "Allow GitHub Actions to create and approve pull requests"
6187
62-
The action uses sparse checkout to minimize the amount of data that needs to be downloaded, making it efficient even with large template repositories.
88+
The action will automatically detect when workflow files are being modified and provide appropriate warnings.
6389
6490
### Include and Exclude Parameters
6591
@@ -100,9 +126,8 @@ Example:
100126
uses: jebel-quant/sync_template@main
101127
with:
102128
template-repository: 'organization/template-repo'
103-
env:
104-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105-
TEST_MODE: "true"
129+
token: ${{ secrets.GITHUB_TOKEN }}
130+
test-mode: "true"
106131
```
107132

108133
### Running Tests Locally

action.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,21 @@ runs:
7474
exit 0
7575
fi
7676
77-
# Check if workflow files are being modified
77+
# Warn if workflow files are modified
7878
if git diff --cached --name-only | grep -q "^\.github/workflows/"; then
79-
echo "⚠️ Warning: Workflow files (.github/workflows/) are being modified."
80-
echo " The default GITHUB_TOKEN does not have permission to update workflow files."
81-
echo " You need to use a Personal Access Token (PAT) with 'workflow' scope."
82-
echo " See: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token"
79+
echo "⚠️ Workflow files detected. Use PAT with 'workflow' scope."
8380
fi
8481
8582
git config user.name "github-actions[bot]"
8683
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
8784
git commit -m "${{ inputs.commit-message }}"
8885
86+
# Configure remote with token
8987
git remote set-url origin "https://x-access-token:${{ inputs.token }}@github.com/${{ github.repository }}.git"
90-
git remote -v
91-
git branch -vv
9288
9389
echo "✅ Remote after reset (masked):"
9490
git remote -v | sed -E 's@(https://)[^@]+@\\1****@g'
95-
91+
9692
echo "🔁 Testing ls-remote with this token..."
9793
git ls-remote --heads origin || echo "❌ ls-remote failed"
9894
@@ -104,19 +100,19 @@ runs:
104100
echo "✅ Sync complete"
105101
else
106102
echo "⚠️ Push failed. Check permissions."
107-
echo " If you're updating workflow files, you need a PAT with 'workflow' scope."
108103
exit 1
109104
fi
110105
fi
111106
112-
- name: Create Pull Request (if branch exists)
107+
- name: Create Pull Request (if not in test mode)
108+
if: ${{ inputs.test-mode != 'true' }}
113109
uses: peter-evans/create-pull-request@v7
114110
with:
115111
token: ${{ inputs.token }}
116112
branch: ${{ inputs.branch }}
117-
base: main
113+
commit-message: ${{ inputs.commit-message }}
118114
title: "chore: sync template from ${{ inputs.template-repository }}@${{ inputs.template-branch }}"
119-
commit-message: "chore: sync template from ${{ inputs.template-repository }}@${{ inputs.template-branch }}"
120115
body: |
121-
This PR updates configuration files from `${{ inputs.template-repository }}@${{ inputs.template-branch }}`.
116+
This PR updates configuration files from
117+
[${{ inputs.template-repository }}@${{ inputs.template-branch }}](https://github.com/${{ inputs.template-repository }}/tree/${{ inputs.template-branch }}).
122118
delete-branch: true

0 commit comments

Comments
 (0)