diff --git a/.woodpecker.yml b/.woodpecker.yml index 69e3dff..b489158 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -8,4 +8,4 @@ pipeline: - make - ls -lah && find scripts && cat scripts/ci.sh - make ci-deploy - secrets: [ pages_deploy_secret, hostea_write_deploy_key] + secrets: [ pages_deploy_secret, hostea_write_deploy_key ] diff --git a/scripts/ci.sh b/scripts/ci.sh index 8a15fc3..4c9f540 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -15,10 +15,11 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -set -xEeuo pipefail +set -xEeuo pipefail #source $(pwd)/scripts/lib.sh readonly SSH_ID_FILE=/tmp/ci-ssh-id +readonly SSH_REMOTE_NAME=origin-ssh match_arg() { if [ $1 == $2 ] || [ $1 == $3 ] @@ -48,6 +49,15 @@ write_ssh(){ echo $1 > $SSH_ID_FILE } +set_ssh_remote() { + http_remote_url=$(git remote get-url origin) + remote_hostname=$(echo $http_remote_url | cut -d '/' -f 3) + repository_owner=$(echo $http_remote_url | cut -d '/' -f 4) + repository_name=$(echo $http_remote_url | cut -d '/' -f 5) + ssh_remote="git@$remote_hostname:$repository_owner/$repository_name" + git remote add $SSH_REMOTE_NAME $ssh_remote || true +} + clean() { if [ -f $SSH_ID_FILE ] then @@ -63,7 +73,7 @@ deploy() { then help else - git -c core.sshCommand="/usr/bin/ssh -i $SSH_ID_FILE" push origin $2 + git -c core.sshCommand="/usr/bin/ssh -i $SSH_ID_FILE" push $SSH_REMOTE_NAME $2 curl -vv --location --request \ POST "https://hostea.org:5000/api/v1/update"\ --header 'Content-Type: application/json' \ @@ -87,6 +97,7 @@ then help exit -1 fi + set_ssh_remote write_ssh $2 elif match_arg $1 '-c' '--clean' then