diff --git a/Makefile b/Makefile index 5074e2f..3e0615c 100644 --- a/Makefile +++ b/Makefile @@ -9,10 +9,9 @@ ci-deploy: ## Deploy from CI/CD. Only call from within CI then echo "Only call from within CI. Will re-write your local Git configuration. To override, set export CI=woodpecker"; \ exit 1; \ fi - git config --global user.email "${CI_COMMIT_AUTHOR_EMAIL}" - git config --global user.name "${CI_COMMIT_AUTHOR}" ./scripts/ci.sh --init "$$GITEA_WRITE_DEPLOY_KEY" - ./scripts/ci.sh --deploy librepages dist + ./scripts/ci.sh --deploy librepages dist "${CI_COMMIT_AUTHOR} <${CI_COMMIT_AUTHOR_EMAIL}>" + #./scripts/ci.sh --deploy librepages dist ./scripts/ci.sh --clean diff --git a/scripts/ci.sh b/scripts/ci.sh index 4ffb86d..4277fec 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -69,8 +69,10 @@ clean() { fi } + # $1: branch name # $2: directory containing build assets +# $3: Author in format write_to_branch() { readonly PROJECT_ROOT=$(pwd) cd $PROJECT_ROOT @@ -87,6 +89,8 @@ write_to_branch() { git fetch origin $1 git switch $1 fi + + cd .. git rm -rf . /bin/rm -rf * cp -r $tmp_dir/* . @@ -95,6 +99,40 @@ write_to_branch() { then echo "[*] Repository has changed, committing changes" git commit \ + --author="$3" \ + --message="new deploy: $(date --iso-8601=seconds)" + fi + git checkout $original_branch + find +} + +# $1: branch name +# $2: directory containing build assets +# $3: Author in format +write_to_branch() { + original_branch=$(git branch --show-current) + tmp_dir=$(mktemp -d) + cp -r $2/* $tmp_dir + + if [[ -z $(git ls-remote --heads origin ${1}) ]] + then + echo "[*] Creating deployment branch $1" + git checkout --orphan $1 + else + echo "[*] Deployment branch $1 exists, pulling changes from remote" + git fetch origin $1 + git status + git switch $1 + fi + git rm -rf . + /bin/rm -rf * + cp -r $tmp_dir/* . + git add --all + if [ $(git status --porcelain | xargs | sed '/^$/d' | wc -l) -gt 0 ]; + then + echo "[*] Repository has changed, committing changes" + git commit \ + --author="$3" \ --message="new deploy: $(date --iso-8601=seconds)" fi git checkout $original_branch @@ -144,7 +182,7 @@ then help exit -1 fi - write_to_branch $2 $3 + write_to_branch $2 $3 $4 deploy $2 clean elif match_arg $1 '-h' '--help'