Skip to content

Commit

Permalink
Merge branch 'main' into feat/gpg_sign_pwd
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasAugustin committed Mar 5, 2024
2 parents e28f14d + 5a3b946 commit 21ac0d2
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@
"profile": "https://kevin.deldycke.com",
"contributions": [
"bug",
"ideas"
"ideas",
"code"
]
}
],
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/greetings.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
id: test
uses: ./ # Uses an action in the root directory
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_repo_path: AndreasAugustin/template.git
is_dry_run: true
- name: print output
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test_hooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
env:
MY_VAR: "bar"
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_repo_path: AndreasAugustin/template.git
upstream_branch: main
is_dry_run: true
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [1.9.0](https://github.com/AndreasAugustin/actions-template-sync/compare/v1.8.1...v1.9.0) (2024-03-05)


### Features

* :sparkles: Set token to the default provided by GitHub workflow ([#483](https://github.com/AndreasAugustin/actions-template-sync/issues/483)) ([c1e7561](https://github.com/AndreasAugustin/actions-template-sync/commit/c1e756148de0343df66fda1a2380382ef06c16d7))
* **#477:** :sparkles: add input parameter for pr body ([#488](https://github.com/AndreasAugustin/actions-template-sync/issues/488)) ([481cc21](https://github.com/AndreasAugustin/actions-template-sync/commit/481cc21550d858dfc12c49f4dfb7605ac744a091))

## [1.8.1](https://github.com/AndreasAugustin/actions-template-sync/compare/v1.8.0...v1.8.1) (2024-03-02)


### Bug Fixes

* **#476:** :bug: output variable edge cases ([#479](https://github.com/AndreasAugustin/actions-template-sync/issues/479)) ([ab4153b](https://github.com/AndreasAugustin/actions-template-sync/commit/ab4153bb937a2d7ad996f0693977cb943443e8b3))

## [1.8.0](https://github.com/AndreasAugustin/actions-template-sync/compare/v1.7.0...v1.8.0) (2024-02-29)


Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ jobs:
- name: actions-template-sync
uses: AndreasAugustin/actions-template-sync@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_repo_path: <owner/repo>
upstream_branch: <target_branch> # defaults to main
pr_labels: <label1>,<label2>[,...] # defaults to template_sync
Expand Down Expand Up @@ -232,14 +231,15 @@ jobs:

### Action Inputs

| Variable | Description | Required | `[Default]` |
| Variable | Description | Required | Default |
|-----------------------------|---------------------------------------------------------------------------------------------------------------|----------|-----------------------------------------------------------------------|
| github_token | Token for the repo. Can be passed in using `$\{{ secrets.GITHUB_TOKEN }}` | `true` | |
| github_token | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}` | `true` | `${{ github.token }}` |
| source_repo_path | Repository path of the template | `true` | |
| upstream_branch | The target branch | `false` | `<The_remote_default>` |
| upstream_branch | The target branch | `false` | The remote's default (usually `main`) |
| source_repo_ssh_private_key | `[optional]` private ssh key for the source repository. [see](#private-template-repository) | `false` | |
| pr_branch_name_prefix | `[optional]` the prefix of branches created by this action | `false` | `chore/template_sync` |
| pr_title | `[optional]` the title of PRs opened by this action. Must be already created. | `false` | `upstream merge template repository` |
| pr_body | `[optional]` the body of PRs opened by this action. | `false` | `Merge ${SOURCE_REPO_PATH} ${TEMPLATE_GIT_HASH}` |
| pr_labels | `[optional]` comma separated list. [pull request labels][pr-labels]. | `false` | `sync_template` |
| pr_reviewers | `[optional]` comma separated list of pull request reviewers. | `false` | |
| pr_commit_msg | `[optional]` commit message in the created pull request | `false` | `chore(template): merge template changes :up:` |
Expand All @@ -263,6 +263,13 @@ jobs:
| ------ | ----------- |
| pr_branch | The name of the branch used for the pull request |

**Remarks** Please consider following edge cases

* **pr_branch**
* If PR branch already exists (e.g. after a 2nd run) the action won't update the branch but will still output the branch name
* If the remote repository already contains the source repository changes the action will exit and the output variable will be undefined
* If there are no changes the action will exit and the output variable will be undefined

### Docker

There are docker images available. Please checkout [How to use docker](docs/DOCKER.md) for details.
Expand Down Expand Up @@ -583,7 +590,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="http://www.xontab.com"><img src="https://avatars.githubusercontent.com/u/4987684?v=4?s=100" width="100px;" alt="Shaun Tabone"/><br /><sub><b>Shaun Tabone</b></sub></a><br /><a href="https://github.com/AndreasAugustin/actions-template-sync/commits?author=xontab" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kevin-aude"><img src="https://avatars.githubusercontent.com/u/98819045?v=4?s=100" width="100px;" alt="Kevin AUDE"/><br /><sub><b>Kevin AUDE</b></sub></a><br /><a href="#ideas-kevin-aude" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/AndreasAugustin/actions-template-sync/commits?author=kevin-aude" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Jnig"><img src="https://avatars.githubusercontent.com/u/3729585?v=4?s=100" width="100px;" alt="Jakob"/><br /><sub><b>Jakob</b></sub></a><br /><a href="https://github.com/AndreasAugustin/actions-template-sync/pulls?q=is%3Apr+reviewed-by%3Ajnig" title="Reviewed Pull Requests">👀</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://kevin.deldycke.com"><img src="https://avatars.githubusercontent.com/u/159718?v=4?s=100" width="100px;" alt="Kevin Deldycke"/><br /><sub><b>Kevin Deldycke</b></sub></a><br /><a href="https://github.com/AndreasAugustin/actions-template-sync/issues?q=author%3Akdeldycke" title="Bug reports">🐛</a> <a href="#ideas-kdeldycke" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://kevin.deldycke.com"><img src="https://avatars.githubusercontent.com/u/159718?v=4?s=100" width="100px;" alt="Kevin Deldycke"/><br /><sub><b>Kevin Deldycke</b></sub></a><br /><a href="https://github.com/AndreasAugustin/actions-template-sync/issues?q=author%3Akdeldycke" title="Bug reports">🐛</a> <a href="#ideas-kdeldycke" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/AndreasAugustin/actions-template-sync/commits?author=kdeldycke" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ inputs:
github_token:
description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
required: true
default: ${{ github.token }}
source_repo_path:
description: "Repository path of the template"
required: true
Expand All @@ -21,6 +22,8 @@ inputs:
pr_title:
description: "[optional] the title of PRs opened by this action"
default: "upstream merge template repository"
pr_body:
description: "[optional] the body of PRs opened by this action"
pr_labels:
description: "[optional] comma separated list of pull request labels"
default: "template_sync"
Expand Down Expand Up @@ -66,6 +69,7 @@ runs:
SSH_PRIVATE_KEY_SRC: ${{ inputs.source_repo_ssh_private_key }}
PR_BRANCH_NAME_PREFIX: ${{ inputs.pr_branch_name_prefix }}
PR_TITLE: ${{ inputs.pr_title }}
PR_BODY: ${{ inputs.pr_body }}
PR_LABELS: ${{ inputs.pr_labels }}
PR_REVIEWERS: ${{ inputs.pr_reviewers }}
PR_COMMIT_MSG: ${{ inputs.pr_commit_msg }}
Expand Down
27 changes: 15 additions & 12 deletions src/sync_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,29 @@ TEMPLATE_SYNC_IGNORE_FILE_PATH=".templatesyncignore"
TEMPLATE_REMOTE_GIT_HASH=$(git ls-remote "${SOURCE_REPO}" HEAD | awk '{print $1}')
NEW_TEMPLATE_GIT_HASH=$(git rev-parse --short "${TEMPLATE_REMOTE_GIT_HASH}")
NEW_BRANCH="${PR_BRANCH_NAME_PREFIX}_${NEW_TEMPLATE_GIT_HASH}"
PR_BODY="${PR_BODY:-Merge ${SOURCE_REPO_PATH} ${NEW_TEMPLATE_GIT_HASH}}"
debug "new Git HASH ${NEW_TEMPLATE_GIT_HASH}"

echo "::group::Check new changes"

function set_github_action_outputs() {
echo "::group::set gh action outputs"
if [[ -z "${GITHUB_RUN_ID}" ]]; then
info "env var 'GITHUB_RUN_ID' is empty -> no github action workflow"
else
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
echo "pr_branch=${NEW_BRANCH}" >> "$GITHUB_OUTPUT"
fi
echo "::endgroup::"
}


function check_branch_remote_existing() {
git ls-remote --exit-code --heads origin "${NEW_BRANCH}" || BRANCH_DOES_NOT_EXIST=true

if [[ "${BRANCH_DOES_NOT_EXIST}" != true ]]; then
warn "Git branch '${NEW_BRANCH}' exists in the remote repository"
set_github_action_outputs
exit 0
fi
}
Expand Down Expand Up @@ -221,7 +235,7 @@ function push () {
function create_pr () {
gh pr create \
--title "${PR_TITLE}" \
--body "Merge ${SOURCE_REPO_PATH} ${NEW_TEMPLATE_GIT_HASH}" \
--body "${PR_BODY}" \
--base "${UPSTREAM_BRANCH}" \
--label "${PR_LABELS}" \
--reviewer "${PR_REVIEWERS}"
Expand All @@ -240,15 +254,4 @@ fi

echo "::endgroup::"

function set_github_action_outputs() {
echo "::group::set gh action outputs"
if [[ -z "${GITHUB_RUN_ID}" ]]; then
info "env var 'GITHUB_RUN_ID' is empty -> no github action workflow"
else
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
echo "pr_branch=${NEW_BRANCH}" >> "$GITHUB_OUTPUT"
fi
echo "::endgroup::"
}

set_github_action_outputs

0 comments on commit 21ac0d2

Please sign in to comment.