fatal: could not read Username for 'https://github.com': invalid url - github

I am trying to setup auto merge for my main branch whenever something is pushed into the development branch using gitaction. This is my gitaction file:
name: Auto merge
on:
push:
branches:
- development
env:
# replace "github_username" with your GitHub username
# replace "github.com/username/repo.git" with your GitHub repo path
# do NOT replace ${{secrets.GITHUB_TOKEN}}, GitHub will take care of it
MY_REPO: https://my-username:${{secrets.GITHUB_TOKEN}}#github.com/organisation-username/repo.git
# replace "long-lived_branch_name" with your branch name
MY_BRANCH: development
# replace it with the path to master repo
MAIN_REPO: https://github.com/organisation-username/repo.git
# replace "master" with your master branch name
MAIN_BRANCH: main
jobs:
merge:
runs-on: ubuntu-latest
steps:
- name: Merge with master
run: |
git clone ${{env.MY_REPO}} -b ${{env.MY_BRANCH}} tmp
cd tmp
git config user.name "Automerge Bot"
git config user.email "gcpabia#gmail.com"
git config pull.rebase false
git pull ${{env.MAIN_REPO}} ${{env.MAIN_BRANCH}}
git push
The thing is I belong to the organization as owner, so the repo isn't in my personal account. I keep getting this error:
Run git clone ***github.com/organization-username/repo.git -b development tmp
Cloning into 'tmp'...
fatal: could not read Username for 'https://github.com': No such device or address
Error: Process completed with exit code 1.
My suspicion is that the issues might be the different usernames I am using to carryout this operation and have switched between that of the organization and my personal account with no success.
Any pointers as to what I am missing.

Related

error: pathspec 'main' did not match any file(s) known to git

I have a very simple Yaml code, I am trying to use and it is causing me so much pain but I cannot see an error besides the one i am getting at the end
error: pathspec 'main' did not match any file(s) known to git
[detached HEAD d1f4c36] Work now
Here is the code :
stages:
- stage : Build
jobs:
- job:
displayName: "Build Ripple 3 dataverse Solution"
pool :
vmImage: 'windows-2019'
variables:
- group: "Ripple 3 Core"
steps:
- task: PowerPlatformToolInstaller#2
inputs:
DefaultVersion: true
displayName : "Power Platform Tool Installer"
- task: PowerPlatformExportSolution#2
inputs:
authenticationType: 'PowerPlatformSPN'
PowerPlatformSPN: 'Service Connection'
SolutionName: '$(PowerPlatformSolution)'
SolutionOutputFile: '$(Pipeline.Workspace)\$(PowerPlatformSolution).zip'
- task: PowerPlatformUnpackSolution#2
inputs:
SolutionInputFile: '$(Pipeline.Workspace)\Ripple3Core.zip'
SolutionTargetFolder: '$(Build.SourcesDirectory)\$(PowerPlatformSolution)_unmanaged'
- script: |
git config user.email "xx#xx.com"
git config user.name "Automatic Build"
git checkout main
git add --all
git commit -m "Work now"
git push origin main
Try
git checkout "main"
Also, it may be necessary to checkout before exporting solution :
https://zupimages.net/viewer.php?id=22/40/z330.png
It is also possible to use Publish artifacts component :
https://learn.microsoft.com/en-us/azure/devops/pipelines/artifacts/pipeline-artifacts?view=azure-devops&tabs=yaml
Git is telling you that it does not recognize 'main' as branch nor file. The branches only exist on remote repository unless you checked them out already.
Instead of
git checkout main # there is no local branch called main
Try
git checkout origin/main
Try adding git fetch before your checkout.
git fetch
git checkout main

How to push file to my another repository

I have a private repository store my code, and run these code on github action everyday.
Recently, I need to create a new public repository to show people my data, lets say 'Kow.csv'
So, I was wondering is there a way to copy this file to this public repository on github action everyday? which mean, I run my code in my private repo and publish my data in my public repo.
Below is the code im using right now, but failed
name: test
'on':
schedule:
- cron: '0 22 * * *'
workflow_dispatch:
jobs:
craw_process_bot:
runs-on: ubuntu-latest
steps:
- name: check_code
uses: actions/checkout#master
- name: set up Python 3.8
uses: actions/setup-Python#v2
with:
python-version: '3.8'
- name: install requirements
run: |
python -m pip install --upgrade pip
pip install pandas
...
pip install pyautogui
- name: process data
run: python ./code/global_code/all_process.py
- name: commit and push if it changed
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}#users.noreply.github.com"
git add -A
timestamp=$(date -u)
git commit -m "Last updated on: ${timestamp}" || exit 0
git remote add origin https://github.com/###/###.git # address of the public repo
git push -u origin master
the error is:
error: remote origin already exists.
The default default remote repository is origin. Therefore, when adding a new repository to a cloned repository in GitHub Actions, you need to use a different name. For the purpose of your action, you could name it public.
Here is the part that needs to be changed:
git remote add public https://github.com/abc/xyz.git # address of the public repo
git push -u public master
Depending on the security settings and ownership, you might need to authenticate with the remote public.

Github action to copy specific folders from one branch to another in the same repo

Is there a github action which allows me to copy specific folders (.eg. dist and static) from one branch to another in the same private repo. I appreciate any help.
here is what was trying to get it to work using Copycat action.
name: Copying static files
on:
push:
branches:
- src # Set a branch name to trigger deployment
jobs:
copy:
runs-on: ubuntu-latest
steps:
- name: Copycat
uses: andstor/copycat-action#v3
with:
personal_token: ${{ secrets.PERSONAL_TOKEN }}
src_path: static.
dst_path: /static/
dst_owner: CompanyX
dst_repo_name: MyRepo
dst_branch: dest
src_branch: src
src_wiki: false
dst_wiki: false
- name: Copycat2
uses: andstor/copycat-action#v3
with:
personal_token: ${{ secrets.PERSONAL_TOKEN }}
src_path: dist.
dst_path: /dist/
dst_owner: CompanyX
dst_repo_name: MyRepo
dst_branch: des
src_branch: src
src_wiki: false
dst_wiki: false
but I'm getting this error even though I have personal token setup in my profile.
fatal: could not read Password for 'https://github.com': No such device or address
If you want to commit to the same repository, you don't have to specify a personal token, just use actions/checkout#v2 (see this)
One solution to copy files between branch is to use git checkout [branch] -- $files, see this post
The following workflow copy files from directory named static on source branch to branch named dest:
name: Copy folder to other branch
on: [push]
jobs:
copy:
name: Copy my folder
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: copy
env:
SRC_FOLDER_PATH: 'static'
TARGET_BRANCH: 'dest'
run: |
files=$(find $SRC_FOLDER_PATH -type f) # get the file list
git config --global user.name 'GitHub Action'
git config --global user.email 'action#github.com'
git fetch # fetch branches
git checkout $TARGET_BRANCH # checkout to your branch
git checkout ${GITHUB_REF##*/} -- $files # copy files from the source branch
git add -A
git diff-index --quiet HEAD || git commit -am "deploy files" # commit to the repository (ignore if no modification)
git push origin $TARGET_BRANCH # push to remote branch

Git on Azure self hosted agent pipelines

I am building an Azure pipeline for a GitHub web site to run on Windows Self-Hosted agents.
The default branch for the GitHub project is develop, all developers commit to this branch. I want a script that will merge develop to release for the time where a version is on tests and merge release to master once in production.
I'm new with git commands, I know the pipeline runs under a service account on the agent, behind a proxy and the pipeline impersonate somehow to another account to connect to GitHub.
To test my script, I logged onto the server as the service account and ran the following commands:
REM At start, the pipeline is on the develop branch so I move to release branch
C:\Agent\_work\29\s> git checkout release
>Updating files: 100% (928/928), done.
>Previous HEAD position was a62***: *comment*
>Switched to a new branch 'release'
>Branch 'release' set up to track remote branch 'release' from 'origin'.
C:\Agent\_work\29\s>git tag "branchTests"
C:\Agent\_work\29\s>git status
>On branch release
>Your branch is up to date with 'origin/release'.
>
>nothing to commit, working tree clean
REM I understood I had to first get the release branch and then pull the develop branch over it before pushing it all back
C:\Agent\_work\29\s>git pull origin develop
fatal: could not read Username for 'https://github.com': No such file or directory
C:\Agent\_work\29\s>git push --verbose --repo=release --set-upstream release
>Pushing to release
>fatal: 'release' does not appear to be a git repository
>fatal: Could not read from remote repository.
>
>Please make sure you have the correct access rights and the repository exists.
I have two questions:
Is my script correct in that context ?
Can this username error come from that I use the service account ? I should impersonate somehow as the same account the pipeline does ?
Thanks.
########## Update 1
I noticed that I don't need to add this if I don't disable the checkout in the pipeline
git config --global user.email "you#example.com"
git config --global user.name "xxx"
git remote set-url origin https://user:{GitHubPAT}#github.com/xxx/xxx.git
I have two files:
stages:
- stage: InitRelease
jobs:
- job: Branch
steps:
- checkout: self
clean: true
persistCredentials: true
- template: git-branch-source-2-target.yml#templates
parameters:
Tag: '${{ variables.projectName }}_${{ variables.buildId }}'
git-branch-source-2-target.yml
parameters:
- name: 'SourceBranch'
default: 'develop'
type: string
- name: 'TargetBranch'
default: 'release'
type: string
- name: 'Tag'
default: ''
type: string
steps:
- task: CmdLine#2
enabled: true
displayName: 'GIT Release'
inputs:
script: |
git checkout ${{parameters.SourceBranch}}
git pull origin
git checkout ${{parameters.TargetBranch}}
git pull origin
git tag ${{parameters.Tag}}
git push --tags
git merge ${{parameters.SourceBranch}}
git push origin --all --verbose
Thanks !
Run the following command in the cmd task of the pipeline:
git config --global user.email "you#example.com"
git config --global user.name "xxx"
git remote set-url origin https://user:{GitHubPAT}#github.com/xxx/xxx.git
git checkout develop
git pull origin
git checkout release
git merge develop
git push origin --all

Git Submodule update on pipelines with hosted agent

I have a self hosted agent and have a git repository with submodules. URLs in .gitmodules are http://
When I try to initialize a job it fails to update submodules.
git submodule sync
git submodule update --init --force
Cloning into 'foo-dev-common'...
Submodule 'foo-dev-common' (https://MY_ORG#dev.azure.com/MY_ORG/PInC/_git/foo-dev-common) registered for path 'foo-dev-common'
fatal: could not read Password for 'https://MY_ORG#dev.azure.com': terminal prompts disabled
fatal: clone of 'https://MY_ORG#dev.azure.com/MY_ORG/PInC/_git/foo-dev-common' into submodule path 'foo-dev-common' failed
##[error]Git submodule update failed with exit code: 128
Finishing: Checkout foo-rose-identity-service#submod_bd_mahesh to s/foo-rose-identity-service
I have also tried adding repository self and
steps:
- checkout: self
submodules: true
persistCredentials: true
forvaidya's answer didn't work for me (though it is now 4 years later).
(Relative URLs in .gitmodules are resolved to full URLs in .git/config by git submodule sync.)
persistCredentials: true will keep the authorization header available in git config for future steps, but it is keyed by your main repo URL. As long as the submodule repo(s) are in the same organization, you can reuse the header, though - e.g. in a pipeline Powershell script:
steps:
- checkout: self
submodules: false
persistCredentials : true
- powershell: |
$header = $(git config --get-all http.$(Build.Repository.Uri).extraheader)
git -c http.extraheader="$header" submodule sync
git -c http.extraheader="$header" submodule update --init --force --depth=1
(I gleaned these details from the logs of the standard checkout step. Note the reference to the Build.Repository.Uri pipeline variable.)
The above will accomplish a full ("unshallow") checkout of the main repo (useful for e.g. GitVersion), without submodules, and a shallow checkout of any submodules.
Edit: The documented way to get the authorization header is
$header = "AUTHORIZATION: bearer $(System.AccessToken)"
After making git submodule relative path it worked
url= ../foo-dev-common
instead of
url=https://MY_ORG#dev.azure.com/MY_ORG/PInC/_git/foo-dev-common