86e73d87d3
CI Feature / Load example-gitea-env.conf to pipeline env (push) Successful in 24s
acc-tests Cucumber test report
CI Feature / Cucumber tests (push) Failing after 1m10s
unit-tests Bats test report
CI Feature / Bats tests (push) Successful in 1m35s
CI Feature / Report Summary (push) Successful in 6s
47 lines
1.4 KiB
Bash
Executable File
47 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
INPUT_FILE="${INPUT_FILE:?}"
|
|
YQ_TPL="${YQ_TPL:?}"
|
|
VERSION="${VERSION:?}"
|
|
SOURCE_REPO="${SOURCE_REPO:?}"
|
|
SOURCE_COMMIT="${SOURCE_COMMIT:?}"
|
|
GITOPS_REPO="${GITOPS_REPO:?}"
|
|
GITEA_TOKEN="${GITEA_TOKEN:?}"
|
|
GITEA_API_URL="${GITEA_API_URL:?}"
|
|
GITOPS_BRANCH="${GITOPS_BRANCH:-main}"
|
|
|
|
_gitops_substitute() {
|
|
echo "$1" | sed "s/{{VERSION}}/$2/g"
|
|
}
|
|
|
|
YQ_EXPR=$(_gitops_substitute "${YQ_TPL}" "${VERSION}")
|
|
|
|
GITEA_HOST=$(echo "${GITEA_API_URL}" | sed 's|https://||' | sed 's|http://||')
|
|
CLONE_URL="https://${GITEA_TOKEN}@${GITEA_HOST}/${GITOPS_REPO}.git"
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
_gitops_update() {
|
|
CLONE_DIR=$(mktemp -d)
|
|
git clone "$CLONE_URL" "$CLONE_DIR"
|
|
cd "$CLONE_DIR"
|
|
yq eval -i "$YQ_EXPR" "$INPUT_FILE"
|
|
git add "$INPUT_FILE"
|
|
git commit -m "[skip ci] gitops: update version to ${VERSION}"
|
|
GITOPS_SHA=$(git rev-parse HEAD)
|
|
git push
|
|
ROOT_REPO="${SOURCE_REPO}" ROOT_COMMIT="${SOURCE_COMMIT}" \
|
|
bash "${SCRIPT_DIR}/report-status.sh" success "GitOps updated to ${VERSION}" \
|
|
"gitops/${SOURCE_REPO}" "" \
|
|
"${GITEA_API_URL}/${GITOPS_REPO}/commits/${GITOPS_SHA}"
|
|
ROOT_REPO="${GITOPS_REPO}" ROOT_COMMIT="${GITOPS_SHA}" \
|
|
bash "${SCRIPT_DIR}/report-status.sh" success "Source build" \
|
|
"source/${SOURCE_REPO}" "" \
|
|
"${GITEA_API_URL}/${SOURCE_REPO}/commits/${SOURCE_COMMIT}"
|
|
}
|
|
|
|
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
|
|
_gitops_update
|
|
fi
|