Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaning of shell scripts #5778

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/scripts/changelog/checker.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
# This script check that the current master changelog has been updated by PR,
# ignoring some internal files.
# It is used by the changelog_check github action.
Expand Down Expand Up @@ -31,11 +32,11 @@ release
changelog=master_changes.md
diffile=/tmp/diff

git fetch origin $GITHUB_BASE_REF --depth=1 --quiet
git fetch origin "$GITHUB_BASE_REF" --depth=1 --quiet
echo "> base commit"
git show origin/$GITHUB_BASE_REF --format=oneline -s
git show origin/"$GITHUB_BASE_REF" --format=oneline -s

git diff origin/$GITHUB_BASE_REF --name-only --diff-filter=AMRCX > $diffile
git diff origin/"$GITHUB_BASE_REF" --name-only --diff-filter=AMRCX > $diffile
updated=0
grep -sq $changelog $diffile || updated=1

Expand All @@ -49,9 +50,9 @@ done
echo "> kept changes"
cat $diffile

num_changes=`wc -l $diffile | cut -f 1 -d ' '`
num_changes=$(wc -l $diffile | cut -f 1 -d ' ')

if [ $num_changes -ne 0 ] ; then
if [ "$num_changes" -ne 0 ] ; then
if [ $updated -eq 0 ] ; then
echo -e "\033[32mChangelog updated\033[m"
else
Expand Down
11 changes: 6 additions & 5 deletions .github/scripts/common/hygiene-preamble.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
. .github/scripts/common/preamble.sh

if [ "$GITHUB_EVENT_NAME" = "pull_request" ] && [ "x" = "x$BASE_REF_SHA$PR_REF_SHA" ] ; then
if [ "$GITHUB_EVENT_NAME" = "pull_request" ] && [ -z "$BASE_REF_SHA$PR_REF_SHA" ] ; then
echo "Variables BASE_REF_SHA and PR_REF_SHA must be defined in a pull request job"
exit 2
fi
Expand All @@ -12,12 +13,12 @@ if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
# we need to get history from base ref to head ref for check configure
depth=10
set +e
git cat-file -e $BASE_REF_SHA
git cat-file -e "$BASE_REF_SHA"
r=$?
while [ $r -ne 0 ] ; do
git fetch origin $GITHUB_REF --depth=$depth
depth=$(( $depth + 10 ))
git cat-file -e $BASE_REF_SHA
git fetch origin "$GITHUB_REF" --depth=$depth
depth=$(( depth + 10 ))
git cat-file -e "$BASE_REF_SHA"
r=$?
done
set -e
Expand Down
1 change: 1 addition & 0 deletions .github/scripts/common/preamble.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
case $GITHUB_EVENT_NAME in
pull_request)
BRANCH=$GITHUB_HEAD_REF
Expand Down
44 changes: 22 additions & 22 deletions .github/scripts/depexts/generate-actions.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/sh
#!/bin/bash

set -eu

#for target in alpine archlinux centos debian fedora gentoo opensuse oraclelinux ubuntu; do
target=$1
dir=.github/actions/$target

mkdir -p $dir
mkdir -p "$dir"

### Generate the action
cat >$dir/action.yml << EOF
cat >"$dir"/action.yml << EOF
name: 'depexts-$target'
description: 'Test external dependencies handling for $target'
runs:
Expand All @@ -25,38 +25,38 @@ OCAML_CONSTRAINT=''

case "$target" in
alpine)
cat >$dir/Dockerfile << EOF
cat >"$dir"/Dockerfile << EOF
FROM alpine
RUN apk add $mainlibs $ocaml
RUN apk add g++
EOF
;;
archlinux)
# no automake
cat >$dir/Dockerfile << EOF
cat >"$dir"/Dockerfile << EOF
FROM archlinux
RUN pacman -Syu --noconfirm $mainlibs $ocaml gcc diffutils
EOF
;;
centos)
# CentOS 7 doesn't support OCaml 5 (GCC is too old)
OCAML_CONSTRAINT=' & < "5.0"'
cat >$dir/Dockerfile << EOF
cat >"$dir"/Dockerfile << EOF
FROM centos:7
RUN yum install -y $mainlibs $ocaml
RUN yum install -y gcc-c++
EOF
;;
debian)
cat >$dir/Dockerfile << EOF
cat >"$dir"/Dockerfile << EOF
FROM debian
RUN apt update
RUN apt install -y $mainlibs $ocaml
RUN apt install -y g++
EOF
;;
fedora)
cat >$dir/Dockerfile << EOF
cat >"$dir"/Dockerfile << EOF
FROM fedora
RUN dnf install -y $mainlibs $ocaml diffutils
RUN dnf install -y gcc-c++
Expand All @@ -66,7 +66,7 @@ EOF
mainlibs=${mainlibs/git/dev-vcs\/git}
mainlibs=${mainlibs/tar/app-arch\/tar}
mainlibs=${mainlibs/bzip2/app-arch\/bzip2}
cat >$dir/Dockerfile << EOF
cat >"$dir"/Dockerfile << EOF
# name the portage image
FROM gentoo/portage as portage
# image is based on stage3
Expand All @@ -78,21 +78,21 @@ EOF
;;
opensuse)
# glpk-dev is installed manually because os-family doesn't handle tumbleweed
cat >$dir/Dockerfile << EOF
cat >"$dir"/Dockerfile << EOF
FROM opensuse/leap:15.3
RUN zypper --non-interactive install $mainlibs $ocaml diffutils gzip glpk-devel
RUN zypper --non-interactive install gcc-c++
EOF
;;
oraclelinux)
cat >$dir/Dockerfile << EOF
cat >"$dir"/Dockerfile << EOF
FROM oraclelinux:8
RUN yum install -y $mainlibs
RUN yum install -y gcc-c++
EOF
;;
ubuntu)
cat >$dir/Dockerfile << EOF
cat >"$dir"/Dockerfile << EOF
FROM ubuntu:20.04
RUN apt update
RUN apt install -y $mainlibs $ocaml
Expand All @@ -104,9 +104,9 @@ esac
OCAML_INVARIANT="\"ocaml\" {>= \"4.09.0\"$OCAML_CONSTRAINT}"

# Copy 2.1 opam binary from cache
cp binary/opam $dir/opam
cp binary/opam "$dir"/opam

cat >>$dir/Dockerfile << EOF
cat >>"$dir"/Dockerfile << EOF
RUN test -d /opam || mkdir /opam
ENV OPAMROOTISOK 1
ENV OPAMROOT /opam/root
Expand All @@ -120,7 +120,7 @@ EOF


### Generate the entrypoint
cat >$dir/entrypoint.sh << EOF
cat >"$dir"/entrypoint.sh << EOF
#!/bin/sh
set -eux

Expand All @@ -136,14 +136,14 @@ cd /github/workspace
EOF

# workaround for opensuse, mccs & glpk
if [ $target = "opensuse" ]; then
cat >>$dir/entrypoint.sh << EOF
if [ "$target" = "opensuse" ]; then
cat >>"$dir"/entrypoint.sh << EOF
OPAMEDITOR="sed -i 's|^build.*$|& [\\"mv\\" \\"src/glpk/dune-shared\\" \\"src/glpk/dune\\"]|'" opam pin edit mccs -yn
#opam show --raw mccs
EOF
fi

cat >>$dir/entrypoint.sh << EOF
cat >>"$dir"/entrypoint.sh << EOF
opam install . --deps
eval \$(opam env)
./configure
Expand All @@ -153,22 +153,22 @@ make
EOF

test_depext () {
for pkg in $@ ; do
echo "./opam install $pkg || true" >> $dir/entrypoint.sh
for pkg in "$@" ; do
echo "./opam install $pkg || true" >> "$dir"/entrypoint.sh
done
}

test_depext conf-gmp conf-which conf-autoconf

# disable automake for centos, as os-family returns rhel
if [ $target != "centos" ] && [ $target != "opensuse" ]; then
if [ "$target" != "centos" ] && [ "$target" != "opensuse" ]; then
test_depext conf-automake
fi

# additionnal
test_depext dpkg # gentoo
test_depext lib-sundials-dev # os version check

chmod +x $dir/entrypoint.sh
chmod +x "$dir"/entrypoint.sh

#done
2 changes: 1 addition & 1 deletion .github/scripts/main/archives-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ rm -rf src_ext/archives
make -C src_ext cache-archives
ls -al src_ext/archives
rm -rf ~/opam-repository
git clone $OPAM_REPO_MAIN ~/opam-repository --bare
git clone "$OPAM_REPO_MAIN" ~/opam-repository --bare
4 changes: 2 additions & 2 deletions .github/scripts/main/create-ocaml-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ PLATFORM="$5"
if [[ $OCAML_BRANCH -gt 407 ]]; then
if [[ -n $GITHUB_BASE_REF ]]; then
git tag combak
git fetch origin $GITHUB_BASE_REF
git checkout origin/$GITHUB_BASE_REF
git fetch origin "$GITHUB_BASE_REF"
git checkout origin/"$GITHUB_BASE_REF"
fi
make -C src_ext dune-local.stamp
cd src_ext/dune-local
Expand Down
10 changes: 5 additions & 5 deletions .github/scripts/main/hygiene.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ case $GITHUB_EVENT_NAME in
CheckConfigure "$GITHUB_SHA"
;;
pull_request)
for commit in $(git rev-list $BASE_REF_SHA...$PR_REF_SHA --reverse)
for commit in $(git rev-list "$BASE_REF_SHA...$PR_REF_SHA" --reverse)
do
echo "check configure for $commit"
CheckConfigure "$commit"
Expand Down Expand Up @@ -97,9 +97,9 @@ cd ..

if [ "$GITHUB_EVENT_NAME" = "push" ] && [ "$BRANCH" = "master" ]; then
(set +x ; echo -en "::group::check default cli\r") 2>/dev/null
CURRENT_MAJOR="`sed -n "s/^AC_INIT(\[opam],\[\([0-9]\+\)[^0-9]*.*])$/\1/p" configure.ac`"
DEFAULT_CLI_MAJOR="`sed -n "/let *default *=/s/.*(\([0-9]*\)[^0-9]*.*/\1/p" src/client/opamCLIVersion.ml`"
if [ $CURRENT_MAJOR -eq $DEFAULT_CLI_MAJOR ]; then
CURRENT_MAJOR="$(sed -n "s/^AC_INIT(\[opam],\[\([0-9]\+\)[^0-9]*.*])$/\1/p" configure.ac)"
DEFAULT_CLI_MAJOR="$(sed -n "/let *default *=/s/.*(\([0-9]*\)[^0-9]*.*/\1/p" src/client/opamCLIVersion.ml)"
if [ "$CURRENT_MAJOR" -eq "$DEFAULT_CLI_MAJOR" ]; then
echo "Major viersion is default cli one: $CURRENT_MAJOR"
else
echo -e "[\e[31mERROR\e[0m] Major version $CURRENT_MAJOR and default cli version $DEFAULT_CLI_MAJOR mismatches"
Expand All @@ -125,4 +125,4 @@ please run dune exec --root=. -- ./ci.exe from .github/workflows and fixup the c
fi
(set +x ; echo -en "::endgroup::check workflow generation\r") 2>/dev/null

exit $ERROR
exit "$ERROR"
2 changes: 1 addition & 1 deletion .github/scripts/main/legacy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -xue
. .github/scripts/main/preamble.sh

eval $(opam env)
OPAMCONFIRMLEVEL= OPAMCLI=2.0 opam upgrade --unlock-base --yes
OPAMCONFIRMLEVEL='' OPAMCLI=2.0 opam upgrade --unlock-base --yes

for package in core format installer ; do
opam pin add --yes --no-action opam-$package .
Expand Down
22 changes: 11 additions & 11 deletions .github/scripts/main/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export OCAMLRUNPARAM=b
if [[ $OPAM_TEST -eq 1 ]] ; then
export OPAMROOT=$OPAMBSROOT
# If the cached root is newer, regenerate a binary compatible root
opam env || { rm -rf $OPAMBSROOT; init-bootstrap; }
opam env || { rm -rf "$OPAMBSROOT"; init-bootstrap; }
eval $(opam env)
fi

Expand All @@ -37,7 +37,7 @@ if [ "$OPAM_TEST" != "1" ]; then
echo 'DUNE_PROFILE=dev' >> Makefile.config
fi

if [ $OPAM_UPGRADE -eq 1 ]; then
if [ "$OPAM_UPGRADE" -eq 1 ]; then
unset-dev-version
fi
# Disable implicit transitive deps
Expand Down Expand Up @@ -83,17 +83,17 @@ if [ "$OPAM_TEST" = "1" ]; then
# Compile and run opam-rt
(set +x ; echo -en "::group::opam-rt\r") 2>/dev/null
opamrt_url="https://github.com/ocaml-opam/opam-rt"
if [ ! -d $CACHE/opam-rt ]; then
git clone $opamrt_url $CACHE/opam-rt
if [ ! -d "$CACHE"/opam-rt ]; then
git clone $opamrt_url "$CACHE"/opam-rt
fi
cd $CACHE/opam-rt
cd "$CACHE"/opam-rt
git fetch origin
if git ls-remote --exit-code origin $BRANCH ; then
if git branch | grep -q $BRANCH; then
git checkout $BRANCH
git reset --hard origin/$BRANCH
if git ls-remote --exit-code origin "$BRANCH" ; then
if git branch | grep -q "$BRANCH"; then
git checkout "$BRANCH"
git reset --hard origin/"$BRANCH"
else
git checkout -b $BRANCH origin/$BRANCH
git checkout -b "$BRANCH" origin/"$BRANCH"
fi
else
git checkout master
Expand All @@ -102,7 +102,7 @@ if [ "$OPAM_TEST" = "1" ]; then

test -d _opam || opam switch create . --no-install --formula '"ocaml-system"'
eval $(opam env)
opam pin $GITHUB_WORKSPACE -yn --with-version to-test
opam pin "$GITHUB_WORKSPACE" -yn --with-version to-test
# opam lib pins defined in opam-rt are ignored as there is a local pin
opam pin . -yn --ignore-pin-depends
opam install opam-rt --deps-only opam-devel.to-test
Expand Down
6 changes: 3 additions & 3 deletions .github/scripts/main/ocaml-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ HOST="${3:-}"

if [ "$PLATFORM" = Windows ]; then
EXE='.exe'
if [ -e $OCAML_LOCAL.tar ]; then
if [ -e "$OCAML_LOCAL".tar ]; then
mkdir -p "$OCAML_LOCAL"
tar -C "$OCAML_LOCAL" -pxf "$OCAML_LOCAL.tar"
exit 0
Expand Down Expand Up @@ -115,7 +115,7 @@ if [[ $OPAM_TEST -ne 1 ]] ; then
fi
fi

if ! ./configure --prefix "$PREFIX"$HOST --with-vendored-deps ${CONFIGURE_SWITCHES:-} ; then
if ! ./configure --prefix "$PREFIX$HOST" --with-vendored-deps "${CONFIGURE_SWITCHES:-}" ; then
echo
echo -e "[\e[31mERROR\e[0m] OCaml's configure script failed"
(set +x ; echo -en "::group::config.log contents\r") 2>/dev/null
Expand All @@ -137,7 +137,7 @@ cd ..
rm -rf "ocaml-$OCAML_VERSION"

if [[ $PLATFORM != 'Windows' ]]; then
echo > "$OCAML_LOCAL/bin/ocamldoc" <<"EOF"
cat > "$OCAML_LOCAL/bin/ocamldoc" <<"EOF"
#!/bin/sh

echo 'ocamldoc is not supposed to be called'>&2
Expand Down
12 changes: 6 additions & 6 deletions .github/scripts/main/opam-bs-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ set -xue

. .github/scripts/main/preamble.sh

rm -f $OPAM_LOCAL/bin/opam-bootstrap
mkdir -p $OPAM_LOCAL/bin/
rm -f "$OPAM_LOCAL"/bin/opam-bootstrap
mkdir -p "$OPAM_LOCAL"/bin/

os=$( (uname -s || echo unknown) | awk '{print tolower($0)}')
if [ "$os" = "darwin" ] ; then
os=macos
fi

curl -sL -o $OPAM_LOCAL/bin/opam-bootstrap \
curl -sL -o "$OPAM_LOCAL"/bin/opam-bootstrap \
"https://github.com/ocaml/opam/releases/download/$OPAMBSVERSION/opam-$OPAMBSVERSION-$(uname -m)-$os"
cp -f $OPAM_LOCAL/bin/opam-bootstrap $OPAM_LOCAL/bin/opam
chmod a+x $OPAM_LOCAL/bin/opam
cp -f "$OPAM_LOCAL"/bin/opam-bootstrap "$OPAM_LOCAL"/bin/opam
chmod a+x "$OPAM_LOCAL"/bin/opam

opam --version

if [[ -d $OPAMBSROOT ]] ; then
init-bootstrap || { rm -rf $OPAMBSROOT; init-bootstrap; }
init-bootstrap || { rm -rf "$OPAMBSROOT"; init-bootstrap; }
else
init-bootstrap
fi
2 changes: 1 addition & 1 deletion .github/scripts/main/opam-rt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export OPAMKEEPLOGS=1
# TODO: Make opam-rt compatible with non-master initial branches
git config --global init.defaultBranch master

cd $CACHE/opam-rt
cd "$CACHE"/opam-rt
make KINDS="local git" run
Loading
Loading