From 397291ded82468b58bd75c92106ae232fc32b897 Mon Sep 17 00:00:00 2001 From: andy Augustin Date: Sun, 12 Feb 2023 16:46:58 +0100 Subject: [PATCH] bug fix version bump 0.7.1-draft (#305) * feat :rocket: add test for gitlab repo (#278) * feat :rocket: add test for gitlab repo (#278) * feat :rocket: add test for gitlab repo (#278) * doc: :memo: document the usage of other git providers (#278) * release(v0.7.1-draft): :rocket: bug fix release (#278) --- .github/workflows/actions_template_sync.yml | 2 +- .github/workflows/test_ssh_gitlab.yml | 28 +++++++++++++++++++++ README.md | 17 +++++++------ action.yml | 4 +++ src/entrypoint.sh | 10 ++++++-- 5 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/test_ssh_gitlab.yml diff --git a/.github/workflows/actions_template_sync.yml b/.github/workflows/actions_template_sync.yml index e69b9d05..b933a057 100644 --- a/.github/workflows/actions_template_sync.yml +++ b/.github/workflows/actions_template_sync.yml @@ -16,7 +16,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: actions-template-sync - uses: AndreasAugustin/actions-template-sync@v0.7.0-draft + uses: AndreasAugustin/actions-template-sync@v0.7.1-draft with: github_token: ${{ secrets.GITHUB_TOKEN }} source_repo_path: AndreasAugustin/template diff --git a/.github/workflows/test_ssh_gitlab.yml b/.github/workflows/test_ssh_gitlab.yml new file mode 100644 index 00000000..ab8eb76e --- /dev/null +++ b/.github/workflows/test_ssh_gitlab.yml @@ -0,0 +1,28 @@ +name: test-ssh-gitlab + +on: + pull_request: + push: + # manual trigger + 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 + uses: actions/checkout@v3 + - + name: Test action step ssh + uses: ./ # Uses an action in the root directory + with: + hostname: ${{ secrets.SOURCE_REPO_GITLAB_HOSTNAME }} + github_token: ${{ secrets.GITHUB_TOKEN }} + source_repo_path: ${{ secrets.SOURCE_REPO_GITLAB_PATH }} # , should be within secrets + source_repo_ssh_private_key: ${{ secrets.SOURCE_REPO_GITLAB_SSH_PRIVATE_KEY }} # contains the private ssh key of the private repository + is_dry_run: true + is_not_source_github: true diff --git a/README.md b/README.md index 6076159b..92226cca 100644 --- a/README.md +++ b/README.md @@ -32,13 +32,10 @@ This GitHub action will help you to keep track of the template changes. * Ignore files and folders from syncing using a `.templatesyncignore` file * many configuration options * different lifecycle hooks are supported +* different git provider. Default is GitHub, GitLab is also tested. See [.github/workflows/test_ssh_gitlab.yml] for an example. ## Usage -### Update - -starting with version v0.5.2-draft the `templateversionrc` file is not needed anymore. You can delete that file from the target repositories. - ### Public template repository Add this configuration to your github action @@ -61,7 +58,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: actions-template-sync - uses: AndreasAugustin/actions-template-sync@v0.7.0-draft + uses: AndreasAugustin/actions-template-sync@v0.7.1-draft with: github_token: ${{ secrets.GITHUB_TOKEN }} source_repo_path: @@ -94,7 +91,7 @@ jobs: private_key: ${{ secrets.PRIVATE_KEY }} - name: actions-template-sync - uses: AndreasAugustin/actions-template-sync@v0.7.0-draft + uses: AndreasAugustin/actions-template-sync@v0.7.1-draft with: github_token: ${{ steps.generate_token.outputs.token }} source_repo_path: @@ -109,6 +106,7 @@ An example are [deployment keys][deployment-keys]. For our use case write permis Within the repository where the GitHub action is enabled add a secret (e.q. `SOURCE_REPO_SSH_PRIVATE_KEY`) with the content of your private SSH key. Make sure that the read permissions of that secret fulfil your use case. Set the optional `source_repo_ssh_private_key` input parameter. +It is also possible to use a different git provider, e.g. GitLab. ```yaml jobs: @@ -120,7 +118,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: actions-template-sync - uses: AndreasAugustin/actions-template-sync@v0.7.0-draft + uses: AndreasAugustin/actions-template-sync@v0.7.1-draft with: github_token: ${{ secrets.GITHUB_TOKEN }} source_repo_path: ${{ secrets.SOURCE_REPO_PATH }} # , should be within secrets @@ -144,6 +142,7 @@ jobs: | hostname | `[optional]` the hostname of the repository | `false` | `github.com` | | is_dry_run | `[optional]` set to `true` if you do not want to push the changes and not want to create a PR | `false` | | | is_allow_hooks | `[optional]` set to `true` if you want to enable lifecycle hooks. Use this with caution! | `false` | `false` | +| is_not_source_github | `[optional]` set to `true` if the source git provider is not GitHub | `false` | `false` | ### Example @@ -220,6 +219,10 @@ To ignore those, simply create a file in the root directory named `.templatesync Open your project `Settings > Actions > General` and select the checkbox `Allow Github Actions to create and approve pull requests` 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. + ## Debug You must create a secret named `ACTIONS_STEP_DEBUG` with the value `true` to see the debug messages set by this command in the log. diff --git a/action.yml b/action.yml index f3beecfe..11bcbdf0 100644 --- a/action.yml +++ b/action.yml @@ -36,6 +36,9 @@ inputs: is_allow_hooks: 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' runs: using: 'docker' image: 'src/Dockerfile' @@ -51,3 +54,4 @@ runs: HOSTNAME: ${{ inputs.hostname }} IS_DRY_RUN: ${{ inputs.is_dry_run }} IS_ALLOW_HOOKS: ${{ inputs.is_allow_hooks }} + IS_NOT_SOURCE_GITHUB: ${{ inputs.is_not_source_github }} diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 0716e038..cf0781c3 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -58,8 +58,14 @@ function git_init() { git config --global --add safe.directory /github/workspace git lfs install - gh auth setup-git --hostname "${SOURCE_REPO_HOSTNAME}" - gh auth status --hostname "${SOURCE_REPO_HOSTNAME}" + if [[ -n "${IS_NOT_SOURCE_GITHUB}" ]]; then + info "the source repository is not located within GitHub." + ssh-keyscan -t rsa "${SOURCE_REPO_HOSTNAME}" >> /root/.ssh/known_hosts + else + info "the source repository is located within GitHub." + gh auth setup-git --hostname "${SOURCE_REPO_HOSTNAME}" + gh auth status --hostname "${SOURCE_REPO_HOSTNAME}" + fi echo "::endgroup::" }