diff --git a/.all-contributorsrc b/.all-contributorsrc index 4309328d..5337f3ba 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -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, diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index ded7682d..aa8d45ea 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -1,9 +1,9 @@ +--- #------------------------------------------------------------------------------------------------------------- # 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: @@ -11,7 +11,7 @@ services: # 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 @@ -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: @@ -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" - diff --git a/.github/workflows/release_please.yml b/.github/workflows/release_please.yml index 939642aa..64869d9a 100644 --- a/.github/workflows/release_please.yml +++ b/.github/workflows/release_please.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6047153..194c6110 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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}" diff --git a/Dockerfile b/Dockerfile index 19752698..375b6ddc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index 969e871e..b782d220 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # actions-template-sync -[![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-) [![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) @@ -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 @@ -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 @@ -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 @@ -721,6 +752,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Brian
Brian

📖 MuriloChianfa
MuriloChianfa

📖 David Snyder
David Snyder

🔬 + Jonathan Østrup
Jonathan Østrup

🤔 💻 + Nat Welch
Nat Welch

🐛 💻 @@ -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 diff --git a/action.yml b/action.yml index 034ac2b5..4487c303 100644 --- a/action.yml +++ b/action.yml @@ -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" @@ -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 }} diff --git a/src/sync_template.sh b/src/sync_template.sh index c82cbc82..984025a3 100755 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -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 ######################################################## @@ -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}") @@ -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 ##################################################### @@ -141,7 +147,6 @@ function check_if_commit_already_in_hist_graceful_exit() { warn "repository is up to date!" exit 0 fi - } ########################################## @@ -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." @@ -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[@]}" } ####################################### @@ -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::" }