From 8cdaa04043f6707e2f3df6671a0373e5781f3aeb Mon Sep 17 00:00:00 2001 From: andy Augustin Date: Mon, 19 Jun 2023 22:40:01 +0200 Subject: [PATCH] :sparkles: (#338) use upstream default branch instead of configured (#351) --- .github/workflows/test.yml | 9 ++----- README.md | 5 ++-- action.yml | 52 ++++++++++++++++++-------------------- src/sync_template.sh | 10 ++++---- 4 files changed, 35 insertions(+), 41 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a7973e9b..047d0bee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,21 +7,16 @@ on: workflow_dispatch: jobs: - test-implementation-job: - runs-on: ubuntu-latest steps: # To use this repository's private action, you must check out the repository - - - name: Checkout + - name: Checkout uses: actions/checkout@v3 - - - name: Test action step + - name: Test action step uses: ./ # Uses an action in the root directory with: github_token: ${{ secrets.GITHUB_TOKEN }} source_repo_path: AndreasAugustin/template.git - upstream_branch: main is_dry_run: true diff --git a/README.md b/README.md index 2de91aae..9977a452 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ jobs: |----|----|----|----| | github_token | Token for the repo. Can be passed in using `$\{{ secrets.GITHUB_TOKEN }}` | `true` | | | source_repo_path | Repository path of the template | `true` | | -| upstream_branch | The target branch | `true` | `main` | +| upstream_branch | The target branch | `false` | `` | | 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` | @@ -305,7 +305,8 @@ under the `Workflow permissions` section. ## Release Updates -starting with version v0.5.2-draft the `templateversionrc` file is not needed anymore. You can delete that file from the target repositories. +* :warning: starting with version v1.0.0 the `upstream_branch` variable default ist not `main` anymore. It is now set to the remote default branch. +* starting with version v0.5.2-draft the `templateversionrc` file is not needed anymore. You can delete that file from the target repositories. ## Debug diff --git a/action.yml b/action.yml index e0bb5319..9d7bc96f 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,6 @@ -name: 'actions-template-sync' -description: 'Synchronises changes of the template repository' -author: 'AndreasAugustin' +name: "actions-template-sync" +description: "Synchronises changes of the template repository" +author: "AndreasAugustin" branding: icon: cloud color: green @@ -9,45 +9,43 @@ inputs: description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}' required: true source_repo_path: - description: 'Repository path of the template' + description: "Repository path of the template" required: true upstream_branch: - description: 'The target branch' - required: true - default: 'main' + description: "The target branch" source_repo_ssh_private_key: - description: '[optional] private ssh key for the source repository. E.q. useful if using a private template repository.' + description: "[optional] private ssh key for the source repository. E.q. useful if using a private template repository." pr_branch_name_prefix: - description: '[optional] the prefix of branches created by this action' - default: 'chore/template_sync' + description: "[optional] the prefix of branches created by this action" + default: "chore/template_sync" pr_title: - description: '[optional] the title of PRs opened by this action' - default: 'upstream merge template repository' + description: "[optional] the title of PRs opened by this action" + default: "upstream merge template repository" pr_labels: - description: '[optional] comma separated list of pull request labels' + description: "[optional] comma separated list of pull request labels" pr_commit_msg: - description: '[optional] the commit message of the template merge' - default: 'chore(template): merge template changes :up:' + description: "[optional] the commit message of the template merge" + default: "chore(template): merge template changes :up:" hostname: - description: '[optional] the hostname of the GitHub repository' - default: 'github.com' + description: "[optional] the hostname of the GitHub repository" + default: "github.com" is_dry_run: - description: '[optional] set to true if you do not want to push the changes and not want to create a PR' + description: "[optional] set to true if you do not want to push the changes and not want to create a PR" is_allow_hooks: - description: '[optional] set to true if you want to allow hooks. Use this functionality with caution!' - default: 'false' + description: "[optional] set to true if you want to allow hooks. Use this functionality with caution!" + default: "false" is_not_source_github: - description: '[optional] set to true if the source repository is not a github related repository. Useful e.q. if the source is GitLab' - default: 'false' + description: "[optional] set to true if the source repository is not a github related repository. Useful e.q. if the source is GitLab" + default: "false" git_user_name: - description: '[optional] set the committer git user.name for the merge commit' + description: "[optional] set the committer git user.name for the merge commit" git_user_email: - description: '[optional] set the committer git user.email for the merge commit' + description: "[optional] set the committer git user.email for the merge commit" git_remote_pull_params: - description: '[optional] set the pull parameters for the remote repository' + description: "[optional] set the pull parameters for the remote repository" runs: - using: 'docker' - image: 'src/Dockerfile' + using: "docker" + image: "src/Dockerfile" env: GITHUB_TOKEN: ${{ inputs.github_token }} SOURCE_REPO_PATH: ${{ inputs.source_repo_path }} diff --git a/src/sync_template.sh b/src/sync_template.sh index feb9e132..3b159e47 100644 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -17,16 +17,16 @@ if [[ -z "${SOURCE_REPO}" ]]; then exit 1; fi -if [[ -z "${UPSTREAM_BRANCH}" ]]; then - err "Missing env variable 'UPSTREAM_BRANCH'"; - exit 1; -fi - if ! [ -x "$(command -v gh)" ]; then err "github-cli gh is not installed. 'https://github.com/cli/cli'"; exit 1; fi +if [[ -z "${UPSTREAM_BRANCH}" ]]; then + UPSTREAM_BRANCH="$(git remote show origin | awk '/HEAD branch/ {print $NF}')" + info "Missing env variable 'UPSTREAM_BRANCH' setting to remote default ${UPSTREAM_BRANCH}"; +fi + if [[ -n "${SRC_SSH_PRIVATEKEY_ABS_PATH}" ]]; then debug "using ssh private key for private source repository" export GIT_SSH_COMMAND="ssh -i ${SRC_SSH_PRIVATEKEY_ABS_PATH}"