- Go 79.7%
- Shell 18.1%
- PowerShell 2.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
* feat: add --default-branch-only flag to pull and sync
Add an optional --default-branch-only flag that limits synchronization to
a repository's single default branch instead of mirroring every branch.
Tags are always synced regardless of the flag.
When set, the initial clone uses ReferenceName: HEAD with SingleBranch so
only the default branch is fetched, and the subsequent fetch only mirrors
tags (+refs/tags/*) rather than all heads (+refs/heads/*). The flag is part
of PullOnlyFlags, so it is available on both the `pull` and `sync` commands.
The progress log now reflects the mode ("fetching tags" vs "fetching all
branches and tags"). The flag only applies on the initial clone into the
cache directory; a repository already cached with all branches keeps them.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: keep default branch up to date on re-sync with --default-branch-only
The fetch step previously used only +refs/tags/* when --default-branch-only
was set, so on re-syncs (where the cached repo exists and the clone is
skipped) the default branch was never updated and went stale.
Instead, refresh the branches already present locally (the single branch the
clone checked out) so the cached default branch stays current, while still
never pulling down additional remote branches. Tags continue to sync via
Tags: git.AllTags.
Adds a regression test covering the repo-already-cached re-sync path and
updates the README to describe the corrected behaviour.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: with --default-branch-only fetch only the default branch via HEAD
Address review feedback. Previously the re-sync fetch refreshed every branch
already present locally, so a repository cached without the flag would still
have all of its branches updated, contradicting the "only the single default
branch" behaviour.
Resolve HEAD to the default branch and build a single refspec for it, so only
the default branch is ever refreshed; any other branches already in the cache
are left as-is (neither updated nor removed). Add Head() to the GitRepository
wrapper to support this.
Tests now use a repository with several branches and a non-default HEAD so
they prove only the default branch is selected (rather than only one branch
existing). Adds a Head-resolution error-path test. README clarifies that the
default branch is always refreshed while extra cached branches are left as-is.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
||
| .github | ||
| .licenses/src/go | ||
| _tools | ||
| cmd | ||
| docs | ||
| script | ||
| src | ||
| test | ||
| vendor | ||
| .dockerignore | ||
| .gitattributes | ||
| .gitignore | ||
| .golangci.yaml | ||
| .goreleaser.yml | ||
| .licensed.yml | ||
| CODE_OF_CONDUCT.md | ||
| CONTRIBUTING.md | ||
| docker-compose.yml | ||
| Dockerfile.cibuild | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| main.go | ||
| README.md | ||
Actions Sync
This is a standalone Go tool to allow you to sync from GitHub to a GitHub Enterprise instance. GitHub Enterprise is referred to as GHES throughout this document.
- Current status: ready for production use
- Download from: releases page
- Build status:
It is designed to work when:
- The GitHub Enterprise instance is separate from the rest of the internet.
- The GitHub Enterprise instance is connected to the rest of the internet.
Note
Thank you for your interest in this GitHub action, however, right now we are not taking contributions.
We continue to focus our resources on strategic areas that help our customers be successful while making developers' lives easier. While GitHub Actions remains a key part of this vision, we are allocating resources towards other areas of Actions and are not taking contributions to this repository at this time. The GitHub public roadmap is the best place to follow along for any updates on features we’re working on and what stage they’re in.
We are taking the following steps to better direct requests related to GitHub Actions, including:
-
We will be directing questions and support requests to our Community Discussions area
-
High Priority bugs can be reported through Community Discussions or you can report these to our support team https://support.github.com/contact/bug-report.
-
Security Issues should be handled as per our security.md
We will still provide security updates for this project and fix major breaking changes during this time.
You are welcome to still raise bugs in this repo.
Connected instances
When there are machines which have access to both the public internet and the GHES instance run actions-sync sync.
Command:
actions-sync sync
Arguments:
cache-dir(required) The directory in which to cache repositories as they are synced. This speeds up re-syncing.destination-url(required) The URL of the GHES instance to sync repositories onto.destination-token(required) A personal access token to authenticate against the GHES instance when uploading repositories. See Destination token scopes below.source-token(optional) A token used to authenticate against the source when pulling private repositories. For a personal access token, thereposcope (read access to the source repositories) is sufficient. For a GitHub App installation token (ghs_*), the installation needs read access to the source repositories' contents; App tokens use installation permissions, not OAuth scopes. Must be used with anhttps://source-url.default-branch-only(optional) Only synchronize the single default branch rather than the default behaviour of syncing all branches. Tags are always synced. The default branch is always refreshed, including on subsequent runs into an existingcache-dir, but no other branches are pulled. If a repository was previously cached without this flag, the extra branches already in thecache-dirare left as-is (they are neither updated nor removed).repo-name(optional) A single repository to be synced. In the format ofowner/repo. Optionally if you wish the repository to be named different on your GHES instance you can provide an alias in the format:upstream_owner/upstream_repo:destination_owner/destination_reporepo-name-list(optional) A comma-separated list of repositories to be synced. Each entry follows the format ofrepo-name.repo-name-list-file(optional) A path to a file containing a newline separated list of repositories to be synced. Each entry follows the format ofrepo-name.actions-admin-user(optional) The name of the Actions admin user, which will be used for updating the chosen action. To use the default user, passactions-admin. If not set, the impersonation is disabled. Note thatsite_adminscope is required in the token for the impersonation to work.github-app-auth(optional) Authenticate using a GitHub App installation token (ghs_*) instead of a personal access token. App tokens have no user context, so the user API call is skipped and repositories are created under the owner taken from the destination repo name, which must be an organization the App is installed on (installation tokens cannot create user-owned repositories). See GitHub App authentication below.batch-size(optional) Number of refs to push in each batch. Default is 0 (no batching). Use a value like 100 if pushing fails for large repositories with many branches and tags.
Example Usage:
actions-sync sync \
--cache-dir "/tmp/cache" \
--destination-token "token" \
--destination-url "https://www.example.com" \
--repo-name actions/setup-node
Not connected instances
When no machine has access to both the public internet and the GHES instance:
actions-sync pullon a machine with public internet access- copy the provided
cache-dirto a machine with access to the GHES instance - run
actions-sync pushon the machine with access to the GHES instance
Command:
actions-sync pull
Arguments:
cache-dir(required) The directory to cache the pulled repositories into.source-token(optional) A token used to authenticate against the source when pulling private repositories. For a personal access token, thereposcope (read access to the source repositories) is sufficient. For a GitHub App installation token (ghs_*), the installation needs read access to the source repositories' contents; App tokens use installation permissions, not OAuth scopes. Must be used with anhttps://source-url.default-branch-only(optional) Only synchronize the single default branch rather than the default behaviour of syncing all branches. Tags are always synced. The default branch is always refreshed, including on subsequent runs into an existingcache-dir, but no other branches are pulled. If a repository was previously cached without this flag, the extra branches already in thecache-dirare left as-is (they are neither updated nor removed).repo-name(optional) A single repository to be synced. In the format ofowner/repo. Optionally if you wish the repository to be named different on your GHES instance you can provide an alias in the format:upstream_owner/upstream_repo:destination_owner/destination_reporepo-name-list(optional) A comma-separated list of repositories to be synced. Each entry follows the format ofrepo-name.repo-name-list-file(optional) A path to a file containing a newline separated list of repositories to be synced. Each entry follows the format ofrepo-name.
Example Usage:
bin/actions-sync pull \
--cache-dir "/tmp/cache" \
--repo-name actions/setup-node
Command:
actions-sync push
Arguments:
cache-dir(required) The directory containing the repositories fetched using thepullcommand.destination-url(required) The URL of the GHES instance to sync repositories onto.destination-token(required) A personal access token to authenticate against the GHES instance when uploading repositories. See Destination token scopes below.repo-name,repo-name-listorrepo-name-list-file(optional) Limit push to specific repositories in the cache directory.actions-admin-user(optional) The name of the Actions admin user, which will be used for updating the chosen action. To use the default user, passactions-admin. If not set, the impersonation is disabled. Note thatsite_adminscope is required in the token for the impersonation to work.github-app-auth(optional) Authenticate using a GitHub App installation token (ghs_*) instead of a personal access token. App tokens have no user context, so the user API call is skipped and repositories are created under the owner taken from the destination repo name, which must be an organization the App is installed on (installation tokens cannot create user-owned repositories). See GitHub App authentication below.batch-size(optional) Number of refs to push in each batch. Default is 0 (no batching). Use a value like 100 if pushing fails for large repositories with many branches and tags.
Example Usage:
bin/actions-sync push \
--cache-dir "/tmp/cache" \
--destination-token "token" \
--destination-url "https://www.example.com"
Destination token scopes
When creating a personal access token include the repo and workflow scopes. Include the site_admin scope (optional) if you want organizations to be created as necessary or you want to use the impersonation logic for the push or sync commands.
GitHub App authentication
Instead of a personal access token you can authenticate push/sync using a GitHub App installation token (ghs_*). This avoids long-lived PATs and aligns with enterprise security practices.
- Create a GitHub App on the destination GHES instance and install it on the target organization(s). The destination owner must be an organization: installation tokens cannot create user-owned repositories (
POST /user/reposrequires user context that App tokens lack), so a user-account installation will not work. - Grant the App these repository permissions:
Administration: Read & write(to create repositories),Contents: Read & writeandMetadata: Read-only. AddWorkflows: Read & writeif the synced repositories contain workflow files. - Generate an installation access token (
ghs_*) for the installation. - Pass the token as
--destination-tokentogether with the--github-app-authflag:
actions-sync push \
--cache-dir "/tmp/cache" \
--destination-token "ghs_xxxxxxxxxxxxxxxxxxxx" \
--destination-url "https://www.example.com" \
--github-app-auth
Notes:
- App installation tokens have no user context, so
--github-app-authskips theGET /usercall and creates repositories under the owner taken from the destination repo name (owner/repo) viaPOST /orgs/{owner}/repos. The owner must therefore be an organization the App is installed on; user-owned destinations are not supported because installation tokens cannot create user-owned repositories. - Organization auto-creation and user-impersonation (
--actions-admin-user) rely on user/site-admin context and are not used with App auth.