initial commit
This commit is contained in:
12
scripts/commit-and-push-changes.sh
Normal file
12
scripts/commit-and-push-changes.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
#%%MULTILINE_YAML_START
|
||||
# commit and push changes in job-templates.yml (if any)
|
||||
git config user.name "DeveloperDurpBot"
|
||||
git config user.email "DeveloperDurp@durp.info"
|
||||
git add -A
|
||||
git commit --untracked-files=no -m "ci: render" -m "Rendered by $CI_PIPELINE_URL" || exit 0
|
||||
echo "Pushing to branch $CI_COMMIT_BRANCH"
|
||||
# just using -o ci.skip would create a "skipped" pipeline in the list of pipelines, preventing a merge!
|
||||
# passing down CI_SCRIPTS_SKIP_PIPELINE and using this in workflow:rules is better, as it does not create a pipeline at all!
|
||||
git push -o ci.variable="CI_SCRIPTS_SKIP_PIPELINE=true" "https://oauth2:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" "HEAD:$CI_COMMIT_BRANCH"
|
||||
curl --silent --fail --request POST --form token="$CI_JOB_TOKEN" --form ref="$CI_COMMIT_BRANCH" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/trigger/pipeline" >/dev/null
|
||||
5
scripts/docker-build.sh
Normal file
5
scripts/docker-build.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#%%MULTILINE_YAML_START
|
||||
#Build Docker Container
|
||||
docker build -t $CI_REGISTRY/$CI_PROJECT_PATH:$DOCKERTAG -t $CI_REGISTRY/$CI_PROJECT_PATH:latest .
|
||||
docker push "$CI_REGISTRY/$CI_PROJECT_PATH:latest"
|
||||
5
scripts/docker-login.sh
Normal file
5
scripts/docker-login.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#%%MULTILINE_YAML_START
|
||||
#login to docker
|
||||
|
||||
docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY/$CI_PROJECT_PATH
|
||||
5
scripts/install-curl.sh
Normal file
5
scripts/install-curl.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#%%MULTILINE_YAML_START
|
||||
#Install curl
|
||||
|
||||
apt update && apt install curl -y
|
||||
5
scripts/install-git.sh
Normal file
5
scripts/install-git.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#%%MULTILINE_YAML_START
|
||||
#Install git
|
||||
|
||||
apt update && apt install git -y
|
||||
8
scripts/install-yq.sh
Normal file
8
scripts/install-yq.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
#%%MULTILINE_YAML_START
|
||||
#Install YQ
|
||||
|
||||
export YQ_VERSION=4.27.2
|
||||
export YQ_ARCH=linux_amd64
|
||||
curl -fsSL "https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_${YQ_ARCH}" -o yq
|
||||
chmod +x yq
|
||||
43
scripts/render-job-templates.sh
Normal file
43
scripts/render-job-templates.sh
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
#%%MULTILINE_YAML_START
|
||||
# render job-templates.yml from job-templates.tpl.yml
|
||||
set -euo pipefail
|
||||
for script in scripts/*.sh; do
|
||||
awk -v script_name="$(basename "$script")" '
|
||||
NR==1 && /^#!/ {printf("# Begin of %s\n",script_name); next} # strip shebang in first line, print head comment
|
||||
/^\s*$/ {next} # strip any newlines or whitespace
|
||||
/^#%%MULTILINE_YAML_START$/ { print "- |"; multiline=1; next } # detect start of multiline yaml block, print "- |" into output yml
|
||||
/^#%%MULTILINE_YAML_END$/ { multiline=0; next } # detect end of multiline yaml block
|
||||
multiline==1 {printf(" %s\n",$0)} # print indented script of multiline yaml block
|
||||
multiline==0 {printf("- !!str %s\n",$0)} # not in multiline yaml, just print with "- !!str" (explicit yaml tag to avoid any quoting)
|
||||
END { printf("# End of %s\n",script_name) } # print trailing comment
|
||||
' "$script" >"$script.yml"
|
||||
done
|
||||
# start with copy and then edit in place using yq -i
|
||||
cat <<EOF >job-templates.yml
|
||||
### WARNING ###
|
||||
### THIS FILE IS RENDERED! DO NOT EDIT! ANY CHANGE WILL BE REVERTED BY RENDERING PIPELINE
|
||||
### Edit the template file job-templates.tpl.yml instead!
|
||||
|
||||
EOF
|
||||
cat job-templates.tpl.yml >> job-templates.yml
|
||||
|
||||
# shellcheck disable=SC2016 # "unquoted $ warning"
|
||||
./yq -i '(.[] | select(keys | .[] | select(tag == "!!str") | test("^(before_|after_|)script$")) | ."*script") ref $scripts
|
||||
| ($scripts | .. | select(. == "./scripts/*.sh")) |= (load(. + ".yml") | .[] style="")
|
||||
| ($scripts | .[] | select(type == "!reference")) |= ([.] | . style="flow")
|
||||
| ($scripts | select(type == "!!seq")) |= flatten(1)
|
||||
| explode .
|
||||
' job-templates.yml
|
||||
|
||||
for template in templates/*.tpl.yml
|
||||
do
|
||||
export pipeline=$(basename $template | sed "s/.tpl//")
|
||||
cat $template > pipelines/$pipeline
|
||||
./yq -i '(.[] | select(keys | .[] | select(tag == "!!str") | test("^(before_|after_|)script$")) | ."*script") ref $scripts
|
||||
| ($scripts | .. | select(. == "./scripts/*.sh")) |= (load(. + ".yml") | .[] style="")
|
||||
| ($scripts | .[] | select(type == "!reference")) |= ([.] | . style="flow")
|
||||
| ($scripts | select(type == "!!seq")) |= flatten(1)
|
||||
| explode .
|
||||
' pipelines/$pipeline
|
||||
done
|
||||
Reference in New Issue
Block a user