s0 / git-publish-subdir-action

GitHub Action to push a subdirectory as a branch to any git repo (e.g. for GitHub Pages)
https://github.com/marketplace/actions/push-git-subdirectory-as-branch
MIT License
208 stars 36 forks source link

fails to push to private gitlab repo #79

Open bruvio opened 1 year ago

bruvio commented 1 year ago

I have a github repo where I am using this workflow that is setup like this:

name: Push to gitlab repo
on:
  schedule:
    - cron: '30 4 * * *'
  workflow_dispatch:

jobs:
  push-to-gitlab:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Setup SSH Keys and known_hosts
        env:
          SSH_AUTH_SOCK: /tmp/ssh_agent.sock
        run: |
          mkdir -p ~/.ssh
          ssh-keyscan git.domain  >> ~/.ssh/known_hosts
          ssh-agent -a ${{ env.SSH_AUTH_SOCK }} > /dev/null
          ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"
      - name: setup git and push to remote
        env:
          SSH_AUTH_SOCK: /tmp/ssh_agent.sock
        run: |
          git config --global user.name "github-actions[bot]"
          git config --global user.email "${{ secrets.GH_MAIL }}"
          git remote add gitlab git@domain:owner/repo

    # Deploy to another repo
      - name: Push to gitlab 
        uses: s0/git-publish-subdir-action@develop
        env:
          SSH_AUTH_SOCK: /tmp/ssh_agent.sock
          REPO: git@domain:owner/repo
          BRANCH: develop
          FOLDER: .
          SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
          KNOWN_HOSTS_FILE:  ./known_hosts

the workflow passes but does not push anything to remote as thinks the branch is up to date, because is pushing to the same repo on github


##[info] Checking if branch develop exists already
data * develop

Already on 'develop'

data Your branch is up to date with 'origin/develop'.

##[info] Updating branch develop
##[info] Removing all files from target branch
##[info] Copying all files from /home/runner/work/repo/folder
##[info] Pushing
**_To https://github.com/owner/repo_**
   2ca6706..8d4e69a  develop -> develop

##[info] Deployment Successful
##[info] Killing ssh-agent
data unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 1663 killed;

so in the end I get an extra commit in the remote repo on github and nothing is pushed to gitlab.

The ssh key is correct.

Any advice on how to solve this?

s0 commented 1 year ago

So you shouldn't need to have those other steps beforehand, as the ssh agent and key etc... is all handled automatically by the action, I wonder if they're somehow interfering with the internal functionality. The only thing you would need to do to use gitlab is provide the known_hosts file, so that should only be a single line of code.

Is this a private gitlab instance that you're pushing to? or the public one? It's a bit difficult to determine why it's pushing to github and not gitlab if all the URLs are obscured :)

bruvio commented 1 year ago

I cleared the workflow file to be like this:

name: Push to  repo
on:
  schedule:
    - cron: '30 4 * * *'
  workflow_dispatch:
    inputs:
      branch:

        description: 'branch to push'
        required: true

jobs:
  push-to-ccfe:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
    # Deploy to another repo
      - name: Push to kg1 group
        uses: s0/git-publish-subdir-action@develop
        env:
          REPO: git@git.domain.ac.uk:myusername/myprivaterepo
          BRANCH: ${{ github.event.inputs.branch }}
          FOLDER: .
          SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
          KNOWN_HOSTS_FILE:  ./known_hosts

from the logs is all good and again the workflow passes, but data is still being pushed to the same repo (the ones that triggers the workflow)

this is an extract from the logs:

* [new ref] d4b50af92521bcb24029b82e82264295e16b6d72 -> origin/develop 2022-10-12T06:10:44.1124015Z ##[endgroup] 2022-10-12T06:10:44.1125234Z ##[group]Determining the checkout info 2022-10-12T06:10:44.1126384Z ##[endgroup] 2022-10-12T06:10:44.1127173Z ##[group]Checking out the ref 2022-10-12T06:10:44.1128452Z [command]/usr/bin/git checkout --progress --force -B develop refs/remotes/origin/develop 2022-10-12T06:10:44.1709597Z Switched to a new branch 'develop' 2022-10-12T06:10:44.1710568Z branch 'develop' set up to track 'origin/develop'. 2022-10-12T06:10:44.1734768Z ##[endgroup] 2022-10-12T06:10:44.1798229Z [command]/usr/bin/git log -1 --format='%H' 2022-10-12T06:10:44.1834239Z 'd4b50af92521bcb24029b82e82264295e16b6d72' 2022-10-12T06:10:44.2245755Z ##[group]Run s0/git-publish-subdir-action@develop 2022-10-12T06:10:44.2246269Z env: 2022-10-12T06:10:44.2246694Z REPO: git@myotherdomain:owner/myprivaterepo 2022-10-12T06:10:44.2247218Z BRANCH: develop 2022-10-12T06:10:44.2247582Z FOLDER: . 2022-10-12T06:10:44.2249417Z SSH_PRIVATE_KEY: *** 2022-10-12T06:10:44.2249926Z KNOWN_HOSTS_FILE: ./known_hosts 2022-10-12T06:10:44.2250321Z ##[endgroup] 2022-10-12T06:10:44.4813750Z Setting up ssh-agent on /tmp/git-publish-subdir-action-Usq3n1/ssh_agent.sock 2022-10-12T06:10:44.4914749Z data SSH_AUTH_SOCK=/tmp/git-publish-subdir-action-Usq3n1/ssh_agent.sock; export SSH_AUTH_SOCK; 2022-10-12T06:10:44.4915724Z SSH_AGENT_PID=1638; export SSH_AGENT_PID; 2022-10-12T06:10:44.4917012Z echo Agent pid 1638; 2022-10-12T06:10:44.4917468Z 2022-10-12T06:10:44.4918663Z Adding private key to ssh-agent at /tmp/git-publish-subdir-action-Usq3n1/ssh_agent.sock 2022-10-12T06:10:44.4988765Z Identity added: (stdin) (theotherdomain) 2022-10-12T06:10:44.4989109Z 2022-10-12T06:10:44.4993814Z Private key added 2022-10-12T06:10:44.5058895Z Cloning into '/tmp/git-publish-subdir-action-Usq3n1/repo'... 2022-10-12T06:10:44.5059450Z 2022-10-12T06:10:45.1981191Z Warning: Permanently added the ECDSA host key for IP address '1.2.3.4' to the list of known hosts. 2022-10-12T06:10:45.1981895Z 2022-10-12T06:10:45.5580485Z ssh keys are required, see https://theotherdomain/profile/keys . Do not type your password here. 2022-10-12T06:10:45.5582583Z 2022-10-12T06:10:56.6256022Z ssh keys are required, see https://git.theotherdomain/profile/keys . Do not type your password here. 2022-10-12T06:10:56.6257567Z 2022-10-12T06:10:57.5364903Z ##[info] Checking if branch develop exists already 2022-10-12T06:10:57.5422528Z data * develop 2022-10-12T06:10:57.5422947Z 2022-10-12T06:10:57.5960762Z Already on 'develop' 2022-10-12T06:10:57.5961449Z 2022-10-12T06:10:57.5970598Z data Your branch is up to date with 'origin/develop'. 2022-10-12T06:10:57.5971176Z 2022-10-12T06:10:57.5972026Z ##[info] Updating branch develop 2022-10-12T06:10:57.6018363Z ##[info] Removing all files from target branch 2022-10-12T06:10:57.6442571Z ##[info] Copying all files from /home/runner/work/myprivaterepo/myprivaterepo 2022-10-12T06:10:57.8206590Z ##[info] Pushing 2022-10-12T06:10:58.4731820Z To https://github.com/owner/myprivaterepo 2022-10-12T06:10:58.4736832Z d4b50af..449222a develop -> develop 2022-10-12T06:10:58.4737718Z 2022-10-12T06:10:58.4789058Z 2022-10-12T06:10:58.4789918Z ##[info] Deployment Successful 2022-10-12T06:10:58.4790514Z ##[info] Killing ssh-agent 2022-10-12T06:10:58.4861769Z data unset SSH_AUTH_SOCK; 2022-10-12T06:10:58.4862373Z unset SSH_AGENT_PID; 2022-10-12T06:10:58.4862792Z echo Agent pid 1638 killed; 2022-10-12T06:10:58.4863073Z

here when I use theotherdomain is gitlab. as you can see at

2022-10-12T06:10:58.4731820Z To https://github.com/owner/myprivaterepo

is pushing to github (the repo that triggers the workflow)

instead I want to push to the repo specified in the input parameters:

git@myotherdomain:owner/myprivaterepo

SecPhases commented 1 year ago

same problem,when i push the folder,it will push to the local repo config: env: REPO: git@github.com:VaLueS6655/Genshin_Impact_Teleport_Files.git BRANCH: Raw FOLDER: zips SSH_PRIVATE_KEY: *** SQUASH_HISTORY: true the log: `

[info] Pushing

remote: Permission to VaLueS6655/Genshin_Impact_Teleport.git denied to github-actions[bot]. fatal: unable to access 'https://github.com/VaLueS6655/Genshin_Impact_Teleport/': The requested URL returned error: 403

Error: Process exited with code: 128: remote: Permission to VaLueS6655/Genshin_Impact_Teleport.git denied to github-actions[bot]. fatal: unable to access 'https://github.com/VaLueS6655/Genshin_Impact_Teleport/': The requested URL returned error: 403

`

and i fixed it with remove .git folder the workflow seems like this:

`

  - name: Checkout from ${{ github.repository }}/commit/${{ github.sha }}
    uses: actions/checkout@v3

  - run: rm -rf .git

  - name: Push to Remote Repo
    uses: s0/git-publish-subdir-action@develop
    env: 
      REPO: git@github.com:Owner/Repo.git
      BRANCH: BRANCH
      FOLDER: ./
      SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_PRIVATE_KEY }}
      SQUASH_HISTORY: true

` and now it works