This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
shell script changes for POSIX compliance and portability #217
Open
dcantrell
wants to merge
4
commits into
CentOS-PaaS-SIG:master
Choose a base branch
from
dcantrell:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
256b3d1
Shell syntax and portability fixes for create-containers.sh
dcantrell 4e9941b
Shell syntax and portability fixes for koji_build_pr.sh
dcantrell 1f37a63
Shell syntax and portability fixes for pull_old_task.sh
dcantrell 026a19d
Shell syntax and portability fixes for repoquery.sh
dcantrell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,96 @@ | ||
#!/bin/bash | ||
#!/bin/sh | ||
|
||
# This container builds with koji into $RPMDIR starting from a pagure PR | ||
|
||
set -xeo pipefail | ||
# avoid using head -n 1 as with pipefail it might cause the command to exit with error 141 due to broken pipe | ||
|
||
PATH=/bin:/usr/bin | ||
|
||
# Check to make sure we have all required vars | ||
if [ -z "${fed_repo}" ]; then echo "No fed_repo env var" ; exit 1 ; fi | ||
if [ -z "${fed_id}" ]; then echo "No fed_id env var" ; exit 1 ; fi | ||
if [ -z "${fed_uid}" ]; then echo "No fed_uid env var" ; exit 1 ; fi | ||
if [ -z "${FEDORA_PRINCIPAL}" ]; then echo "No FEDORA_PRINCIPAL env var"; exit 1; fi | ||
if [ -z "${PAGURE_URL}" ]; then echo "No PAGURE_URL env var"; exit 1; fi | ||
|
||
CURRENTDIR=$(pwd) | ||
if [ ${CURRENTDIR} == "/" ] ; then | ||
cd /home | ||
if [ -z "${fed_repo:=}" ]; then | ||
echo "No fed_repo env var" >&2 | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${fed_id:=}" ]; then | ||
echo "No fed_id env var" >&2 | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${fed_uid:=}" ]; then | ||
echo "No fed_uid env var" >&2 | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${FEDORA_PRINCIPAL:=}" ]; then | ||
echo "No FEDORA_PRINCIPAL env var" >&2 | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${PAGURE_URL:=}" ]; then | ||
echo "No PAGURE_URL env var" >&2 | ||
exit 1 | ||
fi | ||
|
||
CURRENTDIR="$(realpath "$(pwd)")" | ||
|
||
if [ "${CURRENTDIR}" = "/" ] ; then | ||
if [ ! -d /home ]; then | ||
echo "Missing /home" >&2 | ||
exit 1 | ||
fi | ||
|
||
cd /home || exit 1 | ||
CURRENTDIR=/home | ||
fi | ||
|
||
# Allow change koji server to be used | ||
KOJI_PARAMS=${KOJI_PARAMS:-} | ||
KOJI_PARAMS="${KOJI_PARAMS:-}" | ||
|
||
RPMDIR=${CURRENTDIR}/${fed_repo}_repo | ||
RPMDIR="${CURRENTDIR}/${fed_repo}_repo" | ||
|
||
# Create one dir to store logs in that will be mounted | ||
LOGDIR=${CURRENTDIR}/logs | ||
rm -rf ${LOGDIR}/* | ||
mkdir -p ${LOGDIR} | ||
LOGDIR="${CURRENTDIR}/logs" | ||
[ -d "${LOGDIR}" ] && rm -rf "${LOGDIR:?}"/* | ||
mkdir -p "${LOGDIR}" | ||
|
||
# Clone the fedoraproject git repo | ||
rm -rf ${fed_repo} | ||
git clone ${PAGURE_URL}/${fed_namespace}/${fed_repo}.git | ||
if [ "$?" != 0 ]; then echo -e "ERROR: GIT CLONE\nSTATUS: $?"; exit 1; fi | ||
pushd ${fed_repo} | ||
rm -rf "${fed_repo}" | ||
|
||
if ! git clone "${PAGURE_URL}"/"${fed_namespace:?}"/"${fed_repo}".git ; then | ||
retcode=$? | ||
echo "ERROR: GIT CLONE" | ||
echo "STATUS: ${retcode}" | ||
exit 1 | ||
fi | ||
|
||
cd "${fed_repo}" || exit 1 | ||
# Checkout the branch and apply the patch to HEAD of branch | ||
git checkout ${fed_branch} | ||
git fetch -fu origin refs/pull/${fed_id}/head:pr | ||
git checkout "${fed_branch:?}" | ||
git fetch -fu origin refs/pull/"${fed_id}"/head:pr | ||
# Setting git config and merge message in case we try to merge a closed PR, like it is done on stage instance | ||
git -c "user.name=Fedora CI" -c "[email protected]" merge pr -m "Fedora CI pipeline" | ||
# Get current NVR | ||
truenvr=$(rpm -q --define "dist .$DIST_BRANCH" --queryformat '%{name}-%{version}-%{release}\n' --specfile ${fed_repo}.spec | awk 'NR==1') | ||
truenvr=$(rpm -q --define "dist .$DIST_BRANCH" --queryformat '%{name}-%{version}-%{release}\n' --specfile "${fed_repo}".spec | awk 'NR==1') | ||
echo "original_spec_nvr=${truenvr}" >> ${LOGDIR}/job.props | ||
# Find number of git commits in log to append to RELEASE before %{?dist} | ||
commits=$(git log --pretty=format:'' | wc -l) | ||
|
||
# Build srpm to send to koji | ||
fedpkg --release ${fed_branch} srpm | ||
VERSION=$(rpmspec --queryformat "%{VERSION}\n" -q ${fed_repo}.spec | awk 'NR==1') | ||
fedpkg --release "${fed_branch}" srpm | ||
VERSION=$(rpmspec --queryformat "%{VERSION}\n" -q "${fed_repo}".spec | awk 'NR==1') | ||
# Set up koji creds | ||
kinit -k -t "${CURRENTDIR}/fedora.keytab" $FEDORA_PRINCIPAL | ||
kinit -k -t "${CURRENTDIR}/fedora.keytab" "${FEDORA_PRINCIPAL}" | ||
|
||
# Some packages are requiring configure not be run as root, so set this to bypass the error | ||
export FORCE_UNSAFE_CONFIGURE=1 | ||
|
||
# Build the package with koji | ||
# ignore koij exit status. If build fails it will be detected later, https://pagure.io/fedora-ci/general/issue/76 | ||
koji ${KOJI_PARAMS} build --wait --arch-override=x86_64 --scratch ${branch} ${fed_repo}*.src.rpm | tee ${LOGDIR}/kojioutput.txt || true | ||
koji "${KOJI_PARAMS}" build --wait --arch-override=x86_64 --scratch "${fed_branch}" "${fed_repo}"*.src.rpm | tee ${LOGDIR}/kojioutput.txt || true | ||
|
||
popd | ||
cd "${CURRENTDIR}" || exit 1 | ||
|
||
SCRATCHID=$(cat ${LOGDIR}/kojioutput.txt | awk '/Created task:/ { print $3 }') | ||
if ! [[ $SCRATCHID =~ ^[0-9]+$ ]]; then | ||
SCRATCHID=$(awk '/Created task:/ { print $3 }' < ${LOGDIR}/kojioutput.txt) | ||
if ! echo "${SCRATCHID}" | grep -q -E '^[0-9]+$' >/dev/null 2>&1 ; then | ||
echo "status=FAIL" >> ${LOGDIR}/job.props | ||
echo -e "ERROR: KOJI BUILD" | ||
echo "ERROR: KOJI BUILD" | ||
exit 1 | ||
fi | ||
|
||
|
@@ -73,50 +100,50 @@ echo "koji_task_id=${SCRATCHID}" >> ${LOGDIR}/job.props | |
TASK_STATE="unknown" | ||
while echo ${TASK_STATE} | grep -Ev "closed|failed|cancelled"; do | ||
# Wait for build to finish as the command can exit before build finishes, ignore exit code | ||
koji watch-task ${SCRATCHID} || true | ||
for i in {1..5}; do | ||
if koji taskinfo ${SCRATCHID} | tee ${LOGDIR}/taskinfo.txt; then | ||
koji watch-task "${SCRATCHID}" || true | ||
for i in $(seq 1 5); do | ||
if koji taskinfo "${SCRATCHID}" | tee ${LOGDIR}/taskinfo.txt; then | ||
break | ||
fi | ||
if [[ $i -eq 5 ]]; then | ||
if [ "${i}" -eq 5 ]; then | ||
echo "status=FAIL" >> ${LOGDIR}/job.props | ||
echo -e "ERROR: KOJI TASK_INFO" | ||
echo "ERROR: KOJI TASK_INFO" | ||
exit 1 | ||
fi | ||
sleep 60 | ||
done | ||
TASK_STATE=$(cat ${LOGDIR}/taskinfo.txt | grep "State:" | awk '{print$2}') | ||
TASK_STATE=$(grep "State:" ${LOGDIR}/taskinfo.txt | awk '{print$2}') | ||
done | ||
|
||
if [ ${TASK_STATE} != "closed" ]; then | ||
if [ ! "${TASK_STATE}" = "closed" ]; then | ||
echo "status=FAIL" >> ${LOGDIR}/job.props | ||
echo -e "ERROR: KOJI BUILD\nSTATUS: $TASK_STATE" | ||
echo "ERROR: KOJI BUILD" | ||
echo "STATUS: ${TASK_STATE}" | ||
exit 1 | ||
fi | ||
|
||
echo "status=SUCCESS" >> ${LOGDIR}/job.props | ||
|
||
# Make repo to download rpms to | ||
rm -rf ${RPMDIR} | ||
mkdir -p ${RPMDIR} | ||
rm -rf "${RPMDIR}" | ||
mkdir -p "${RPMDIR}" | ||
# Create repo | ||
pushd ${RPMDIR} | ||
for i in {1..5}; do | ||
koji ${KOJI_PARAMS} download-build --arch=x86_64 --arch=src --arch=noarch --debuginfo --task-id ${SCRATCHID} || koji ${KOJI_PARAMS} download-task --arch=x86_64 --arch=src --arch=noarch --logs ${SCRATCHID} && break | ||
echo "koji build download failed, attempt: $i/5" | ||
if [[ $i -lt 5 ]]; then | ||
cd "${RPMDIR}" || exit 1 | ||
for i in $(seq 1 5); do | ||
koji "${KOJI_PARAMS}" download-build --arch=x86_64 --arch=src --arch=noarch --debuginfo --task-id "${SCRATCHID}" || koji "${KOJI_PARAMS}" download-task --arch=x86_64 --arch=src --arch=noarch --logs "${SCRATCHID}" && break | ||
echo "koji build download failed, attempt: ${i}/5" | ||
if [ "${i}" -lt 5 ]; then | ||
sleep 10 | ||
else | ||
exit 1 | ||
fi | ||
done | ||
createrepo . | ||
popd | ||
cd "${CURRENTDIR}" || exit 1 | ||
|
||
# Store modified nvr as well | ||
set +e | ||
RPM_TO_CHECK=$(find ${RPMDIR}/ -name "${fed_repo}-${VERSION}*" | awk 'NR==1') | ||
RPM_NAME=$(basename $RPM_TO_CHECK) | ||
NVR=$(rpm --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n" -qp $RPM_TO_CHECK) | ||
RPM_TO_CHECK=$(find "${RPMDIR}"/ -name "${fed_repo}-${VERSION}*" | awk 'NR==1') | ||
NVR=$(rpm --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n" -qp "${RPM_TO_CHECK}") | ||
echo "nvr=${NVR}" >> ${LOGDIR}/job.props | ||
exit 0 |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this removal intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that line is not portable shell.