Github Component

This article contains the code for a github component:

repository, (e.g. user/git-repo): rtyley/small-test-repo

directory (e.g. git-repo): a-small-test-repo

ref, (e.g. master): master

secret token:

github-container
Download as Docker image from:
Copy
This image was imported from: eu.gcr.io/nextjournal-com/environment@sha256:dfd750228d7d02f6ae71e03ff75f033aca7b5fc38ca4fa94303ac4938a0f8786
github_token="_"
github_repository="_"
project_dir="_"
git_ref="_"
[ -z "$github_repository" ] && exit 0 || :
[ -z "$git_ref" ] && git_ref="master" || :
if [ -n "$github_token" ]; then
	git_url="https://${github_token}@github.com/${github_repository}"
else
	git_url="https://github.com/${github_repository}"
fi
if [ -d "/volumes/${project_dir}" ] && [ -d "/volumes/${project_dir}/.git" ] && [ -f "/volumes/${project_dir}/.git/config" ] && grep -qe '\s*url' "/volumes/${project_dir}/.git/config"; then
  # if repository changed
  grep -e '\s*url' "/volumes/${project_dir}/.git/config" | grep -q "${github_repository}\$" || mv "/volumes/${project_dir}" "/volumes/${project_dir}-$RANDOM"
fi
mkdir -p "/volumes/${project_dir}"
cd "/volumes/${project_dir}"
if [ -d "/volumes/${project_dir}" ] && [ -d "/volumes/${project_dir}/.git" ]; then
 git fetch 
 git reset --hard HEAD
 git checkout "${git_ref}"
 git reset --hard "origin/${git_ref}" || git reset --hard "${git_ref}"
else
 git clone "${git_url}" .
 git checkout "${git_ref}"
fi
echo "Latest commit:"
git log --pretty=oneline | head -1 || :
1.2s
Bash
github-container
Runtimes (1)