Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
xesrevinu committed Oct 29, 2024
2 parents 986fafe + 7564a8f commit 8568a80
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 16 deletions.
20 changes: 20 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,26 @@
"contributions": [
"research"
]
},
{
"login": "TechnicallyJoe",
"name": "Jonathan Østrup",
"avatar_url": "https://avatars.githubusercontent.com/u/7877957?v=4",
"profile": "https://github.com/technicallyjoe",
"contributions": [
"ideas",
"code"
]
},
{
"login": "icco",
"name": "Nat Welch",
"avatar_url": "https://avatars.githubusercontent.com/u/20201?v=4",
"profile": "https://natwelch.com",
"contributions": [
"bug",
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
9 changes: 4 additions & 5 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

version: '3.7'
services:
# Update this to the name of the service you want to work with in your docker-compose.yml file
dev:
# You may want to add a non-root user to your Dockerfile and uncomment the line below
# to cause all processes to run as this user. Once present, you can also simply
# use the "remoteUser" property in devcontainer.json if you just want VS Code and
# its sub-processes (terminals, tasks, debugging) to execute as the user. On Linux,
# you may need to ensure the UID and GID of the container user you create matches your
# you may need to ensure the UID and GID of the container user you create matches your
# local user. See https://aka.ms/vscode-remote/containers/non-root for details.
# user: vscode

Expand All @@ -23,13 +23,13 @@ services:
# Uncomment if you want to expose any additional ports. The snippet below exposes port 3000.
# ports:
# - 3000:3000

volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- .:/workspace:cached

# Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-in-docker-compose for details.
# - /var/run/docker.sock:/var/run/docker.sock
# - /var/run/docker.sock:/var/run/docker.sock

# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
# cap_add:
Expand All @@ -39,4 +39,3 @@ services:

# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"

2 changes: 1 addition & 1 deletion .github/workflows/release_please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: google-github-actions/release-please-action@v4
- uses: googleapis/release-please-action@v4
id: release
with:
release-type: simple
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,24 @@ jobs:
env:
FORMER_OUTPUT_PR_BRANCH: ${{ steps.test.outputs.pr_branch }}
run: echo "pr_branch ${FORMER_OUTPUT_PR_BRANCH}"

test-implementation-job-no-dry-run:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
# To use this repository's private action, you must check out the repository
- name: Checkout
uses: actions/checkout@v4
- name: Test action step
id: test
uses: ./ # Uses an action in the root directory
with:
source_repo_path: AndreasAugustin/template.git
is_dry_run: false
is_force_push_pr: true
- name: print output
env:
FORMER_OUTPUT_PR_BRANCH: ${{ steps.test.outputs.pr_branch }}
run: echo "pr_branch ${FORMER_OUTPUT_PR_BRANCH}"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ENTRYPOINT ["/bin/zsh"]
#######################################
# image for creating the documentation
######################################
FROM node:22.9.0-alpine AS docs
FROM node:23.0.0-alpine AS docs

# install packages
RUN apk add --update --no-cache bash make git zsh curl tmux
Expand Down
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# actions-template-sync
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-33-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-35-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

[![actions-template-sync](https://github.com/AndreasAugustin/actions-template-sync/actions/workflows/actions_template_sync.yml/badge.svg)](https://github.com/AndreasAugustin/actions-template-sync/actions/workflows/actions_template_sync.yml)
Expand Down Expand Up @@ -269,6 +269,8 @@ jobs:
| gpg_private_key | `[optional]` set if you want to sign commits | `false` | |
| gpg_passphrase | `[optional]` set if your optionial gpg private key has a passphrase | `false` | |
| steps | `[optional] add the steps you want to execute within the action` | `false` | all steps will be executed |
| template_sync_ignore_file_path | `[optional] set the path to the ignore file.` | false |`.templatesyncignore` |
| is_with_tags | `[optional]` set to `true` if tags should be synced | `false` | `false` |

### Action Outputs

Expand Down Expand Up @@ -315,6 +317,11 @@ in defining the files and folders that should be excluded from syncing with the

It can also be stored inside `.github` folder.

The `template_sync_ignore_file_path` parameter allows you to specify a path to an ignore file. This variable defaults to `.templatesyncignore`.
Changing this allows you to support template sync with more than one repository using different ignore files.

The action will look for the path specified within `.` or `.github/`

_Note: It is not possible to sync also the `.templatesyncignore` itself. Any changes from the template repository will be restored automatically._

**Remark** reading the [gitglossary][git-glossary] (_pathspec_ section) you see a slight difference to the `.gitignore` file
Expand Down Expand Up @@ -568,6 +575,30 @@ This feature will force delete files if those are deelted within the source repo
:warning: it is highly related to the `git_remote_pull_params` config parameter and won't work with the default.
You need to change the default one e.g. to `git_remote_pull_params: --allow-unrelated-histories --strategy=recursive --no-edit`.

## GHES and custom runners

Some notes if you use GitHub Enterprise Server (GHES) and/or custom runners.
The action script is based on bash. That means your runner must be able to run bash scripts.
Furthermore you need to have the following command line tools installed:

* ssh
* [GitHub cli][gh-cli]
* git
* optional (dependent the features you are using)
* [git lfs][git-lfs] if you are using the lfs functionality
* [yq][yq] if you are using the hook functionality
* gpg if you are using the git signing functionality

Furthermore most likely you have a custom domain name. Therefore you should configure the `hostname` GitHub action parameter.

### Remark

:whale: There is also a docker image available which has all needed tools installed. This is helpful e.g. if you are not able to use a remote action.
The idea is to use the [docker action][action-docker]

* [GitHub registry][github-repo]
* [Dockerhub registry][dockerhub-repo]

## Troubleshooting

* refusing to allow a GitHub App to create or update workflow `.github/workflows/******.yml` without `workflows` permission
Expand Down Expand Up @@ -721,6 +752,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/brian6932"><img src="https://avatars.githubusercontent.com/u/18603393?v=4?s=100" width="100px;" alt="Brian"/><br /><sub><b>Brian</b></sub></a><br /><a href="https://github.com/AndreasAugustin/actions-template-sync/commits?author=brian6932" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/MuriloChianfa"><img src="https://avatars.githubusercontent.com/u/60560085?v=4?s=100" width="100px;" alt="MuriloChianfa"/><br /><sub><b>MuriloChianfa</b></sub></a><br /><a href="https://github.com/AndreasAugustin/actions-template-sync/commits?author=MuriloChianfa" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/davidsnyder"><img src="https://avatars.githubusercontent.com/u/229108?v=4?s=100" width="100px;" alt="David Snyder"/><br /><sub><b>David Snyder</b></sub></a><br /><a href="#research-davidsnyder" title="Research">🔬</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/technicallyjoe"><img src="https://avatars.githubusercontent.com/u/7877957?v=4?s=100" width="100px;" alt="Jonathan Østrup"/><br /><sub><b>Jonathan Østrup</b></sub></a><br /><a href="#ideas-TechnicallyJoe" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/AndreasAugustin/actions-template-sync/commits?author=TechnicallyJoe" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://natwelch.com"><img src="https://avatars.githubusercontent.com/u/20201?v=4?s=100" width="100px;" alt="Nat Welch"/><br /><sub><b>Nat Welch</b></sub></a><br /><a href="https://github.com/AndreasAugustin/actions-template-sync/issues?q=author%3Aicco" title="Bug reports">🐛</a> <a href="https://github.com/AndreasAugustin/actions-template-sync/commits?author=icco" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -760,3 +793,6 @@ specification. Contributions of any kind are welcome!
[github-create-secret]: https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository
[github-create-gpg-key]: https://docs.github.com/en/authentication/managing-commit-signature-verification/generating-a-new-gpg-key
[github-gh-cli-pr-edit]: https://cli.github.com/manual/gh_pr_edit
[gh-cli]: https://github.com/cli/cli
[yq]: https://github.com/mikefarah/yq
[git-lfs]: https://github.com/git-lfs/git-lfs
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ inputs:
description: "[optional] set if your private gpg key has a password"
steps:
description: "[optional] set the steps to execute within the action"
template_sync_ignore_file_path:
description: "[optional] set the path to the ignore file"
default: ".templatesyncignore"
is_with_tags:
description: "[optional] set to true if tags should be synced"
default: "false"
outputs:
pr_branch:
description: "The name of the PR branch"
Expand Down Expand Up @@ -119,3 +125,5 @@ runs:
GPG_PRIVATE_KEY: ${{ inputs.gpg_private_key }}
GPG_PASSPHRASE: ${{ inputs.gpg_passphrase }}
STEPS: ${{ inputs.steps }}
TEMPLATE_SYNC_IGNORE_FILE_PATH: ${{ inputs.template_sync_ignore_file_path }}
IS_WITH_TAGS: ${{ inputs.is_with_tags }}
30 changes: 22 additions & 8 deletions src/sync_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ if ! [ -x "$(command -v gh)" ]; then
exit 1;
fi

if [[ -z "${TEMPLATE_SYNC_IGNORE_FILE_PATH}" ]]; then
err "Missing env variable 'TEMPLATE_SYNC_IGNORE_FILE_PATH'";
exit 1;
fi

########################################################
# Variables
########################################################
Expand All @@ -42,11 +47,12 @@ if [[ -n "${SRC_SSH_PRIVATEKEY_ABS_PATH}" ]]; then
export GIT_SSH_COMMAND="ssh -i ${SRC_SSH_PRIVATEKEY_ABS_PATH}"
fi

TEMPLATE_SYNC_IGNORE_FILE_PATH="${TEMPLATE_SYNC_IGNORE_FILE_PATH:-".templatesyncignore"}"
IS_WITH_TAGS="${IS_WITH_TAGS:-"false"}"
IS_FORCE_PUSH_PR="${IS_FORCE_PUSH_PR:-"false"}"
IS_KEEP_BRANCH_ON_PR_CLEANUP="${IS_KEEP_BRANCH_ON_PR_CLEANUP:-"false"}"
GIT_REMOTE_PULL_PARAMS="${GIT_REMOTE_PULL_PARAMS:---allow-unrelated-histories --squash --strategy=recursive -X theirs}"

TEMPLATE_SYNC_IGNORE_FILE_PATH=".templatesyncignore"
TEMPLATE_REMOTE_GIT_HASH=$(git ls-remote "${SOURCE_REPO}" HEAD | awk '{print $1}')
SHORT_TEMPLATE_GIT_HASH=$(git rev-parse --short "${TEMPLATE_REMOTE_GIT_HASH}")

Expand Down Expand Up @@ -74,7 +80,7 @@ debug "PR_BODY ${PR_BODY}"
# Check if the Ignore File exists inside .github folder or if it doesn't exist at all
if [[ -f ".github/${TEMPLATE_SYNC_IGNORE_FILE_PATH}" || ! -f "${TEMPLATE_SYNC_IGNORE_FILE_PATH}" ]]; then
debug "using ignore file as in .github folder"
TEMPLATE_SYNC_IGNORE_FILE_PATH=".github/${TEMPLATE_SYNC_IGNORE_FILE_PATH}"
TEMPLATE_SYNC_IGNORE_FILE_PATH=".github/${TEMPLATE_SYNC_IGNORE_FILE_PATH}"
fi

#####################################################
Expand Down Expand Up @@ -141,7 +147,6 @@ function check_if_commit_already_in_hist_graceful_exit() {
warn "repository is up to date!"
exit 0
fi

}

##########################################
Expand Down Expand Up @@ -231,7 +236,7 @@ function pull_source_changes() {
local source_repo=$1
local git_remote_pull_params=$2

eval "git pull ${source_repo} ${git_remote_pull_params}" || pull_has_issues=true
eval "git pull ${source_repo} --tags ${git_remote_pull_params}" || pull_has_issues=true

if [ "$pull_has_issues" == true ] ; then
warn "There had been some git pull issues."
Expand Down Expand Up @@ -280,18 +285,27 @@ function eventual_create_labels () {
# Arguments:
# branch
# is_force
# is_with_tags
##############################
function push () {
info "push changes"
local branch=$1
local is_force=$2
local is_with_tags=$3

args=(--set-upstream origin "${branch}")

if [ "$is_force" == true ] ; then
warn "forcing the push."
git push --force --set-upstream origin "${branch}"
else
git push --set-upstream origin "${branch}"
args+=(--force)
fi

if [ "$is_with_tags" == true ] ; then
warn "include tags."
args+=(--tags)
fi

git push "${args[@]}"
}

#######################################
Expand Down Expand Up @@ -477,7 +491,7 @@ function arr_push() {
return 0
fi
cmd_from_yml "prepush"
push "${PR_BRANCH}" "${IS_FORCE_PUSH_PR}"
push "${PR_BRANCH}" "${IS_FORCE_PUSH_PR}" "${IS_WITH_TAGS}"
echo "::endgroup::"
}

Expand Down

0 comments on commit 8568a80

Please sign in to comment.