-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from tegonal/gitlab
add .gitlab-ci.yml including script to install and to create MR
- Loading branch information
Showing
7 changed files
with
341 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
.gget-install: | ||
script: &gget-install-script | ||
- ./lib/gget/src/gitlab/install-gget.sh | ||
|
||
.gget-create-mr: | ||
script: &gget-create-mr-script | ||
- ./lib/gget/src/gitlab/create-mr.sh | ||
|
||
.gget-update: | ||
stage: gget | ||
image: tegonal/gitlab-git:latest | ||
rules: | ||
- if: $DO_GGET_UPDATE | ||
variables: | ||
GITBOT_USERNAME: 'gget bot' | ||
GITBOT_EMAIL: '[email protected]' | ||
before_script: | ||
- apk update && apk add bash git gnupg perl coreutils curl && apk upgrade | ||
- tmpDir=$(mktemp -d -t gget-update-XXXXXXXXXX) && cd "$tmpDir" | ||
- source /scripts/clone-current.sh | ||
- export PATH="$PATH:$HOME/.local/bin" | ||
script: | ||
- *gget-install-script | ||
- gget reset --gpg-only true | ||
- gget update | ||
- *gget-create-mr-script | ||
|
||
gget-update: | ||
extends: .gget-update | ||
|
||
.gget-update-stop-pipeline: | ||
stage: gget | ||
image: alpine:latest | ||
rules: | ||
- if: $DO_GGET_UPDATE | ||
needs: [ "gget-update" ] | ||
script: | ||
- apk update && apk add curl | ||
- echo 'stopping the pipeline on purpose...' | ||
- 'curl --request POST --header "PRIVATE-TOKEN: $GGET_UPDATE_API_TOKEN" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/${CI_JOB_ID}/cancel"' | ||
- sleep | ||
- echo 'cancel failed, stopping via exit...' | ||
- exit 1 | ||
gget-update-stop-pipeline: | ||
extends: .gget-update-stop-pipeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# __ __ | ||
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/gget | ||
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / It is licensed under Apache 2.0 | ||
# \__/\__/\_, /\___/_//_/\_,_/_/ Please report bugs and contribute back your improvements | ||
# /___/ | ||
# Version: v0.8.0-SNAPSHOT | ||
# | ||
################################### | ||
set -euo pipefail | ||
shopt -s inherit_errexit | ||
unset CDPATH | ||
|
||
if ! [[ -v dir_of_gget_gitlab ]]; then | ||
dir_of_gget_gitlab="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)" | ||
readonly dir_of_gget_gitlab | ||
fi | ||
source "$dir_of_gget_gitlab/utils.sh" | ||
|
||
# is passed to exitIfEnvVarNotSet by name | ||
# shellcheck disable=SC2034 | ||
declare -a envVars=( | ||
GGET_UPDATE_API_TOKEN | ||
CI_API_V4_URL | ||
CI_PROJECT_ID | ||
) | ||
exitIfEnvVarNotSet envVars | ||
readonly GGET_UPDATE_API_TOKEN CI_API_V4_URL CI_PROJECT_ID | ||
|
||
declare gitStatus | ||
gitStatus=$(git status --porcelain) || { | ||
echo "the following command failed (see above): git status --porcelain" | ||
exit 1 | ||
} | ||
|
||
if [[ $gitStatus == "" ]]; then | ||
echo "No git changes, i.e. no updates found, no need to create a merge request" | ||
exit 0 | ||
fi | ||
|
||
echo "Detected updates, going to push changes to branch gget/update" | ||
|
||
git branch -D "gget/update" 2 &>/dev/null || true | ||
git checkout -b "gget/update" | ||
git add . | ||
git commit -m "Update files pulled via gget" | ||
git push -f --set-upstream origin gget/update || { | ||
echo "could not force push gget/update to origin" | ||
exit 1 | ||
} | ||
|
||
declare data | ||
data=$( | ||
# shellcheck disable=SC2312 | ||
cat <<-EOM | ||
{ | ||
"source_branch": "gget/update", | ||
"target_branch": "main", | ||
"title": "Changes via gget update", | ||
"allow_collaboration": true, | ||
"remove_source_branch": true | ||
} | ||
EOM | ||
) | ||
|
||
echo "Going to create a merge request for the changes" | ||
|
||
curlOutputFile=$(mktemp -t "curl-output-XXXXXXXXXX") | ||
|
||
# passed by name to cleanupTmp | ||
# shellcheck disable=SC2034 | ||
readonly -a tmpPaths=(curlOutputFile) | ||
trap 'cleanupTmp tmpPaths' EXIT | ||
|
||
statusCode=$( | ||
curl --request POST \ | ||
--header "PRIVATE-TOKEN: $GGET_UPDATE_API_TOKEN" \ | ||
--data "$data" --header "Content-Type: application/json" \ | ||
--output "$curlOutputFile" --write-out "%{response_code}" \ | ||
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests" | ||
) || { | ||
echo "could not send the POST request for creating a merge request" | ||
exit 1 | ||
} | ||
if [[ $statusCode = 409 ]] && grep "open merge request" "$curlOutputFile"; then | ||
echo "There is already a merge request, no need to create another (we force pushed, so the MR is updated)" | ||
elif [[ ! "$statusCode" == 2* ]]; then | ||
printf "curl return http status code %s, expected 2xx. Message body:\n" "$statusCode" | ||
cat "$curlOutputFile" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# __ __ | ||
# / /____ ___ ____ ___ ___ _/ / This script is provided to you by https://github.com/tegonal/gget | ||
# / __/ -_) _ `/ _ \/ _ \/ _ `/ / It is licensed under Apache 2.0 | ||
# \__/\__/\_, /\___/_//_/\_,_/_/ Please report bugs and contribute back your improvements | ||
# /___/ | ||
# Version: v0.8.0-SNAPSHOT | ||
# | ||
################################### | ||
set -euo pipefail | ||
shopt -s inherit_errexit | ||
unset CDPATH | ||
if ! [[ -v dir_of_gget_gitlab ]]; then | ||
dir_of_gget_gitlab="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null && pwd 2>/dev/null)" | ||
readonly dir_of_gget_gitlab | ||
fi | ||
source "$dir_of_gget_gitlab/utils.sh" | ||
|
||
# is passed to exitIfEnvVarNotSet by name | ||
# shellcheck disable=SC2034 | ||
declare -a envVars=( | ||
PUBLIC_GPG_KEYS_WE_TRUST | ||
) | ||
exitIfEnvVarNotSet envVars | ||
readonly PUBLIC_GPG_KEYS_WE_TRUST | ||
|
||
# passed by name to cleanupTmp | ||
# shellcheck disable=SC2034 | ||
readonly -a tmpPaths=(tmpDir) | ||
trap 'cleanupTmp tmpPaths' EXIT | ||
|
||
gpg --import - <<<"$PUBLIC_GPG_KEYS_WE_TRUST" | ||
|
||
# see install.doc.sh in https://github.com/tegonal/gget, MODIFY THERE NOT HERE (please report bugs) | ||
currentDir=$(pwd) && \ | ||
tmpDir=$(mktemp -d -t gget-download-install-XXXXXXXXXX) && cd "$tmpDir" && \ | ||
wget "https://raw.githubusercontent.com/tegonal/gget/main/.gget/signing-key.public.asc" && \ | ||
wget "https://raw.githubusercontent.com/tegonal/gget/main/.gget/signing-key.public.asc.sig" && \ | ||
gpg --verify ./signing-key.public.asc.sig ./signing-key.public.asc && \ | ||
echo "public key trusted" && \ | ||
mkdir ./gpg && \ | ||
gpg --homedir ./gpg --import ./signing-key.public.asc && \ | ||
wget "https://raw.githubusercontent.com/tegonal/gget/main/install.sh" && \ | ||
wget "https://raw.githubusercontent.com/tegonal/gget/main/install.sh.sig" && \ | ||
gpg --homedir ./gpg --verify ./install.sh.sig ./install.sh && \ | ||
chmod +x ./install.sh && \ | ||
echo "verification successful" || (echo "verification failed, don't continue"; exit 1) && \ | ||
./install.sh && result=true || (echo "installation failed"; exit 1) && \ | ||
false || cd "$currentDir" && rm -r "$tmpDir" && "${result:-false}" | ||
# end install.doc.sh |
Oops, something went wrong.