From 69beb6f95779ce38b02420fb4a9198214cd932dd Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 11:23:00 +1000 Subject: [PATCH 01/16] Install git within docker container --- .github/workflows/test.yml | 4 +++- Dockerfile | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4d3f7a2..4bc8ff1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: "build-test" +name: "test" on: # rebuild any PRs and main branch changes pull_request: push: @@ -17,3 +17,5 @@ jobs: target_repo_url: git@github.com:net-engine/github-action-repository-sync-test.git source_branch: master target_branch: master +gs +g diff --git a/Dockerfile b/Dockerfile index 681e7b4..75dc74e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM alpine:3.11 +RUN apk update && apk upgrade && \ + apk add --no-cache git openssh + COPY entrypoint.sh /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] From 76a9ecf5f6146b619362f76f4755a7e52163c777 Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 11:23:39 +1000 Subject: [PATCH 02/16] Add local branch while testing --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4bc8ff1..bfc4901 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,6 +4,7 @@ on: # rebuild any PRs and main branch changes push: branches: - master + - add-action-test - 'releases/*' jobs: @@ -17,5 +18,3 @@ jobs: target_repo_url: git@github.com:net-engine/github-action-repository-sync-test.git source_branch: master target_branch: master -gs -g From 7dc904d039f7fe1dc1f61386f08935d057318bb9 Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 11:43:00 +1000 Subject: [PATCH 03/16] Try removing strict host key checking --- Dockerfile | 3 ++- entrypoint.sh | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 75dc74e..a036838 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ FROM alpine:3.11 RUN apk update && apk upgrade && \ - apk add --no-cache git openssh + apk add --no-cache git openssh-client && + echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config COPY entrypoint.sh /entrypoint.sh diff --git a/entrypoint.sh b/entrypoint.sh index d85a19a..2e254f1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,5 +5,6 @@ mkdir ~/.ssh echo "$INPUT_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa +git show-ref git remote add destination "$INPUT_TARGET_REPO_URL" git push destination "$INPUT_SOURCE_BRANCH:$INPUT_TARGET_BRANCH" -f From 073c7f2f71a0c0607838cab4b64c55d979bc495c Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 11:43:52 +1000 Subject: [PATCH 04/16] Fix typo in dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a036838..cc6d83b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM alpine:3.11 RUN apk update && apk upgrade && \ - apk add --no-cache git openssh-client && + apk add --no-cache git openssh-client && \ echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config COPY entrypoint.sh /entrypoint.sh From 7bc604db2adc2e85d9a1bf9b195af4130b64e6cc Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 11:46:06 +1000 Subject: [PATCH 05/16] output git branches --- entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 2e254f1..e58a711 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,6 +5,9 @@ mkdir ~/.ssh echo "$INPUT_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa +echo "Branches" +git branch -a +echo "Refs" git show-ref git remote add destination "$INPUT_TARGET_REPO_URL" git push destination "$INPUT_SOURCE_BRANCH:$INPUT_TARGET_BRANCH" -f From 9e6524c7805b6483ff4a05842135f5d3a01669db Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 11:47:05 +1000 Subject: [PATCH 06/16] Set branch to remote/origin/master --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bfc4901..f022748 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,5 +16,5 @@ jobs: with: ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} target_repo_url: git@github.com:net-engine/github-action-repository-sync-test.git - source_branch: master + source_branch: remotes/origin/master target_branch: master From b767dc31c11f9204ef3507511d00bb77eadf4b52 Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 11:49:42 +1000 Subject: [PATCH 07/16] Refer to variables set via environment --- action.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/action.yml b/action.yml index cdd8126..03fa8ae 100644 --- a/action.yml +++ b/action.yml @@ -19,8 +19,3 @@ inputs: runs: using: 'docker' image: 'Dockerfile' - args: - - ${{ inputs.ssh_private_key }} - - ${{ inputs.source_branch }} - - ${{ inputs.target_branch }} - - ${{ inputs.target_repo_url }} From f8c1e6ae8706f519eeb1d86efbd03ec0892c7cf8 Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 11:59:47 +1000 Subject: [PATCH 08/16] Try debugging ssh connection --- .github/workflows/test.yml | 2 +- entrypoint.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f022748..b6fa75b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: test: # make sure the action works on a clean machine without building runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - uses: ./ with: ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} diff --git a/entrypoint.sh b/entrypoint.sh index e58a711..d5416b9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -9,5 +9,6 @@ echo "Branches" git branch -a echo "Refs" git show-ref +ssh -vT git@github.com git remote add destination "$INPUT_TARGET_REPO_URL" git push destination "$INPUT_SOURCE_BRANCH:$INPUT_TARGET_BRANCH" -f From 095f9748162391b3dfbc3804ee143ceec09e4f85 Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 12:05:37 +1000 Subject: [PATCH 09/16] Properly set up ssh --- action.yml | 4 ---- entrypoint.sh | 11 +++++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index 03fa8ae..4494267 100644 --- a/action.yml +++ b/action.yml @@ -5,10 +5,6 @@ inputs: ssh_private_key: description: SSH private key for ssh connection to the target repository required: false - source_branch: - description: The branch from this repository that you want to push to the remote - required: false - default: master target_branch: description: The branch from the remote repository that you want to push the source_branch to required: false diff --git a/entrypoint.sh b/entrypoint.sh index d5416b9..1046a40 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,9 +1,12 @@ #!/bin/sh -l # Setup SSH -mkdir ~/.ssh -echo "$INPUT_SSH_PRIVATE_KEY" > ~/.ssh/id_rsa -chmod 600 ~/.ssh/id_rsa +mkdir /root/.ssh/id_rsa +echo "$INPUT_SSH_PRIVATE_KEY" > /root/.ssh/id_rsa +chmod 600 /root/.ssh/id_rsa + +mkdir -p ~/.ssh +cp /root/.ssh/* ~/.ssh/ 2> /dev/null || true echo "Branches" git branch -a @@ -11,4 +14,4 @@ echo "Refs" git show-ref ssh -vT git@github.com git remote add destination "$INPUT_TARGET_REPO_URL" -git push destination "$INPUT_SOURCE_BRANCH:$INPUT_TARGET_BRANCH" -f +git push destination "$GITHUB_REF:$INPUT_TARGET_BRANCH" -f From f68513c20935520fa0aa6a32608375fbf7f1a2a0 Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 12:07:42 +1000 Subject: [PATCH 10/16] Pass p option to mkdir --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1046a40..f1c71ef 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh -l # Setup SSH -mkdir /root/.ssh/id_rsa +mkdir -p /root/.ssh echo "$INPUT_SSH_PRIVATE_KEY" > /root/.ssh/id_rsa chmod 600 /root/.ssh/id_rsa From c71650123bbc45277d584d0b17f4dd119e942a09 Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 12:09:49 +1000 Subject: [PATCH 11/16] Try removing extra ssh setup --- entrypoint.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index f1c71ef..9a07ef6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,9 +5,6 @@ mkdir -p /root/.ssh echo "$INPUT_SSH_PRIVATE_KEY" > /root/.ssh/id_rsa chmod 600 /root/.ssh/id_rsa -mkdir -p ~/.ssh -cp /root/.ssh/* ~/.ssh/ 2> /dev/null || true - echo "Branches" git branch -a echo "Refs" From 30aa3438ff2f98486eb6eb476273fc96a37ee192 Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 12:11:21 +1000 Subject: [PATCH 12/16] Fetch the full history --- .github/workflows/test.yml | 2 ++ entrypoint.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b6fa75b..bfcae9b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,6 +12,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 - uses: ./ with: ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} diff --git a/entrypoint.sh b/entrypoint.sh index 9a07ef6..3d02ee7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -11,4 +11,4 @@ echo "Refs" git show-ref ssh -vT git@github.com git remote add destination "$INPUT_TARGET_REPO_URL" -git push destination "$GITHUB_REF:$INPUT_TARGET_BRANCH" -f +git push destination "$GITHUB_REF:$GITHUB_REF" -f From 3f5eaf6daf13f5889fb2dcd1d5a19278267ba687 Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 12:14:35 +1000 Subject: [PATCH 13/16] Sync the current branch by default --- .github/workflows/test.yml | 3 --- action.yml | 4 ---- 2 files changed, 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bfcae9b..fdc34a5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,6 @@ on: # rebuild any PRs and main branch changes branches: - master - add-action-test - - 'releases/*' jobs: test: # make sure the action works on a clean machine without building @@ -18,5 +17,3 @@ jobs: with: ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} target_repo_url: git@github.com:net-engine/github-action-repository-sync-test.git - source_branch: remotes/origin/master - target_branch: master diff --git a/action.yml b/action.yml index 4494267..725008e 100644 --- a/action.yml +++ b/action.yml @@ -5,10 +5,6 @@ inputs: ssh_private_key: description: SSH private key for ssh connection to the target repository required: false - target_branch: - description: The branch from the remote repository that you want to push the source_branch to - required: false - default: master target_repo_url: description: Target git repository URL required: true From 0e00df2bdd72dfa1579e89b4157e2dd51a6df2e6 Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 12:16:37 +1000 Subject: [PATCH 14/16] Remove debugging support --- .github/workflows/test.yml | 3 +-- entrypoint.sh | 5 ----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fdc34a5..38ed4d8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,10 +1,9 @@ name: "test" -on: # rebuild any PRs and main branch changes +on: pull_request: push: branches: - master - - add-action-test jobs: test: # make sure the action works on a clean machine without building diff --git a/entrypoint.sh b/entrypoint.sh index 3d02ee7..84d9b01 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,10 +5,5 @@ mkdir -p /root/.ssh echo "$INPUT_SSH_PRIVATE_KEY" > /root/.ssh/id_rsa chmod 600 /root/.ssh/id_rsa -echo "Branches" -git branch -a -echo "Refs" -git show-ref -ssh -vT git@github.com git remote add destination "$INPUT_TARGET_REPO_URL" git push destination "$GITHUB_REF:$GITHUB_REF" -f From 80950976a7711557e3d06c4dad0815e81c42ace6 Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 13:38:03 +1000 Subject: [PATCH 15/16] README cleanups, add todo --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e1b4b39..05522b6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- typescript-action status + GitHub action build status

# Git Repository Sync Action @@ -17,9 +17,12 @@ Inspired by the following actions **Required** The name of the person to greet. Default `"World"`. - ## Example usage uses: actions/hello-world-docker-action@v1 with: who-to-greet: 'Mona the Octocat' + +## TODO + +* Support for any branch, similar to [actions/checkout@v2](https://github.com/actions/checkout) From bfe78220fdbac9b941e471dfe41b2d273c424fce Mon Sep 17 00:00:00 2001 From: Martin Bjeldbak Madsen Date: Tue, 11 Feb 2020 13:48:27 +1000 Subject: [PATCH 16/16] README updates --- .github/workflows/test.yml | 2 +- README.md | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 38ed4d8..530b679 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,4 +15,4 @@ jobs: - uses: ./ with: ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} - target_repo_url: git@github.com:net-engine/github-action-repository-sync-test.git + target_repo_url: git@github.com:net-engine/github-repository-sync-action-test.git diff --git a/README.md b/README.md index 05522b6..ab30398 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@

- GitHub action build status + GitHub action build status

# Git Repository Sync Action A [GitHub action](https://github.com/features/actions) to push changes to a branch in a current GitHub repository to any remote repository, i.e. another GitHub, GitLab, AWS CodeCommit repository. +Check out a [sample workflow](https://github.com/net-engine/github-repository-sync-action/blob/master/.github/workflows/test.yml). + Inspired by the following actions * [wei/git-sync](https://github.com/wei/git-sync) @@ -13,16 +15,21 @@ Inspired by the following actions ## Inputs -### `who-to-greet` +### `ssh_private_key` + +**Required** The SSH private key for SSH connection to the target repository. We strongly recommend saving this value within [GitHub secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets). + +### `target_repo_url` -**Required** The name of the person to greet. Default `"World"`. +**Required** The SSH-based URL to the target repository, e.g. `git@github.com:net-engine/github-repository-sync-action.git` ## Example usage -uses: actions/hello-world-docker-action@v1 +uses: netengine/github-repository-sync-action with: who-to-greet: 'Mona the Octocat' ## TODO -* Support for any branch, similar to [actions/checkout@v2](https://github.com/actions/checkout) +* Support for any to and from branch, similar to [actions/checkout@v2](https://github.com/actions/checkout) +* Make SSH key-based authentication optional to support username/password authentication