Skip to content

Commit eed32d4

Browse files
authored
Merge pull request #6471 from rjbou/gha-depexts
GHA depexts: some enhancements
2 parents e6c9d13 + b404830 commit eed32d4

File tree

3 files changed

+64
-33
lines changed

3 files changed

+64
-33
lines changed

.github/scripts/depexts/generate-actions.sh

+53-33
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ set -eu
66
target=$1
77
dir=.github/actions/$target
88

9-
mkdir -p $dir
9+
mkdir -p "$dir"
1010

1111
### Generate the action
12-
cat >$dir/action.yml << EOF
12+
cat > "$dir/action.yml" << EOF
1313
name: 'depexts-$target'
1414
description: 'Test external dependencies handling for $target'
1515
runs:
@@ -25,23 +25,23 @@ OCAML_CONSTRAINT=''
2525

2626
case "$target" in
2727
alpine)
28-
cat >$dir/Dockerfile << EOF
28+
cat > "$dir/Dockerfile" << EOF
2929
FROM alpine
3030
RUN apk add $mainlibs $ocaml
3131
RUN apk add g++
3232
EOF
3333
;;
3434
archlinux)
3535
# no automake
36-
cat >$dir/Dockerfile << EOF
36+
cat > "$dir/Dockerfile" << EOF
3737
FROM archlinux
3838
RUN pacman -Syu --noconfirm $mainlibs $ocaml gcc diffutils
3939
EOF
4040
;;
4141
centos)
4242
# CentOS 7 doesn't support OCaml 5 (GCC is too old)
4343
OCAML_CONSTRAINT=' & < "5.0"'
44-
cat >$dir/Dockerfile << EOF
44+
cat > "$dir/Dockerfile" << EOF
4545
FROM almalinux:9.4
4646
RUN dnf install 'dnf-command(config-manager)' -y
4747
RUN dnf config-manager --set-enabled crb
@@ -51,15 +51,15 @@ RUN sed -i 's/ID="almalinux"/ID="centos"/' /etc/os-release
5151
EOF
5252
;;
5353
debian)
54-
cat >$dir/Dockerfile << EOF
54+
cat > "$dir/Dockerfile" << EOF
5555
FROM debian
5656
RUN apt update
5757
RUN apt install -y $mainlibs $ocaml
5858
RUN apt install -y g++
5959
EOF
6060
;;
6161
fedora)
62-
cat >$dir/Dockerfile << EOF
62+
cat > "$dir/Dockerfile" << EOF
6363
FROM fedora
6464
RUN dnf install -y $mainlibs $ocaml diffutils
6565
RUN dnf install -y gcc-c++
@@ -69,7 +69,7 @@ EOF
6969
mainlibs=${mainlibs/git/dev-vcs\/git}
7070
mainlibs=${mainlibs/tar/app-arch\/tar}
7171
mainlibs=${mainlibs/bzip2/app-arch\/bzip2}
72-
cat >$dir/Dockerfile << EOF
72+
cat > "$dir/Dockerfile" << EOF
7373
# name the portage image
7474
FROM gentoo/portage as portage
7575
# image is based on stage3
@@ -83,21 +83,21 @@ EOF
8383
;;
8484
opensuse)
8585
# glpk-dev is installed manually because os-family doesn't handle tumbleweed
86-
cat >$dir/Dockerfile << EOF
86+
cat > "$dir/Dockerfile" << EOF
8787
FROM opensuse/leap:15.3
8888
RUN zypper --non-interactive install $mainlibs $ocaml diffutils gzip glpk-devel
8989
RUN zypper --non-interactive install gcc-c++
9090
EOF
9191
;;
9292
oraclelinux)
93-
cat >$dir/Dockerfile << EOF
93+
cat > "$dir/Dockerfile" << EOF
9494
FROM oraclelinux:8
9595
RUN yum install -y $mainlibs
9696
RUN yum install -y gcc-c++
9797
EOF
9898
;;
9999
ubuntu)
100-
cat >$dir/Dockerfile << EOF
100+
cat > "$dir/Dockerfile" << EOF
101101
FROM ubuntu:20.04
102102
RUN apt update
103103
RUN apt install -y $mainlibs $ocaml
@@ -108,10 +108,13 @@ esac
108108

109109
OCAML_INVARIANT="\"ocaml\" {>= \"4.09.0\"$OCAML_CONSTRAINT}"
110110

111-
# Copy 2.1 opam binary from cache
112-
cp binary/opam $dir/opam
111+
# Copy released opam binary from cache
112+
cp binary/opam "$dir/opam"
113113

114-
cat >>$dir/Dockerfile << EOF
114+
LOCAL_REPO=/opam/repo
115+
CONF_BRANCH=confs
116+
117+
cat >> "$dir/Dockerfile" << EOF
115118
RUN test -d /opam || mkdir /opam
116119
ENV OPAMROOTISOK=1
117120
ENV OPAMROOT=/opam/root
@@ -120,7 +123,19 @@ ENV OPAMCONFIRMLEVEL=unsafe-yes
120123
ENV OPAMPRECISETRACKING=1
121124
COPY opam /usr/bin/opam
122125
RUN echo 'default-invariant: [ $OCAML_INVARIANT ]' > /opam/opamrc
123-
RUN /usr/bin/opam init --no-setup --disable-sandboxing --bare --config /opam/opamrc git+$OPAM_REPO#$OPAM_REPO_SHA
126+
# Retrieve opam repo
127+
RUN git clone $OPAM_REPO --single-branch --branch master $LOCAL_REPO
128+
RUN git config --global user.email "[email protected]"
129+
RUN git config --global user.name "OPAM GHA"
130+
RUN git -C $LOCAL_REPO reset --hard $OPAM_REPO_SHA
131+
RUN git -C $LOCAL_REPO reset --soft \$(git -C $LOCAL_REPO rev-list --all | tail -1)
132+
RUN git -C $LOCAL_REPO commit -qm "all packages"
133+
# Build a branch that contains only confs packages
134+
RUN git -C $LOCAL_REPO checkout -b $CONF_BRANCH
135+
RUN git -C $LOCAL_REPO rm -q \$(git -C $LOCAL_REPO ls-files packages | grep -v "^packages/conf-")
136+
RUN git -C $LOCAL_REPO commit -qm "keep only confs"
137+
# Setup opam
138+
RUN /usr/bin/opam init --no-setup --disable-sandboxing --bare --config /opam/opamrc git+file://$LOCAL_REPO#master
124139
RUN echo 'archive-mirrors: "https://opam.ocaml.org/cache"' >> \$OPAMROOT/config
125140
RUN /usr/bin/opam switch create this-opam --formula='$OCAML_INVARIANT'
126141
RUN /usr/bin/opam install opam-core opam-state opam-solver opam-repository opam-format opam-client --deps
@@ -131,67 +146,72 @@ EOF
131146

132147

133148
### Generate the entrypoint
134-
cat >$dir/entrypoint.sh << EOF
149+
cat > "$dir/entrypoint.sh" << EOF
135150
#!/bin/sh
136151
set -eux
137152
138153
git config --global --add safe.directory /github/workspace
139154
155+
## CI WORKING DIR
140156
# Workdir is /github/workpaces
141157
cd /github/workspace
142158
143-
### LOCAL TESTING
144-
#git clone https://github.com/ocaml/opam --single-branch --branch 2.2 --depth 1 local-opam
159+
## LOCAL TESTING WORKING DIR
160+
# with docker run -v local/path/opam:/opam/local-git:ro
161+
#git clone /opam/local-git --single-branch --branch branch-name --depth 1 local-opam
162+
# with a distant branch
163+
#git clone https://github.com/ocaml/opam --single-branch --branch branch-name --depth 1 local-opam
145164
#cd local-opam
146165
147-
opam install . --deps
148-
eval \$(opam env)
166+
/usr/bin/opam install . --deps
167+
eval \$(/usr/bin/opam env)
149168
./configure
150169
make
170+
151171
./opam config report
152-
./opam switch create confs --empty
172+
./opam switch create confs --empty --repo rconf=git+file://$LOCAL_REPO#$CONF_BRANCH
153173
EOF
154174

155175
# Test depexts
156176

157177
DEPEXTS2TEST=""
158178
test_depext () {
159-
DEPEXTS2TEST="$DEPEXTS2TEST $@"
179+
DEPEXTS2TEST="$DEPEXTS2TEST $*"
160180
}
161181

162182
test_depext conf-gmp.4 conf-which.1
163183

164-
if [ $target != "gentoo" ]; then
184+
if [ "$target" != gentoo ]; then
165185
test_depext conf-autoconf.0.1
166186
fi
167187

168188
# disable automake for centos, as os-family returns rhel
169-
if [ $target != "centos" ] && [ $target != "gentoo" ] && [ $target != "opensuse" ]; then
189+
if [ "$target" != centos ] && [ "$target" != gentoo ] && [ "$target" != opensuse ]; then
170190
test_depext conf-automake.1
171191
fi
172192

173-
# additionna
174-
if [ $target != "oraclelinux" ] && [ $target != "xxx" ]; then
193+
# additional
194+
if [ "$target" != oraclelinux ]; then
175195
test_depext conf-dpkg.1 # gentoo
176196
fi
177197

178198
# package with os-version check
179199

180-
if [ $target = "debian" ] || [ $target = "ubuntu" ]; then
200+
if [ "$target" = debian ] || [ "$target" = ubuntu ]; then
181201
test_depext conf-sundials.2
182202
# conf-libgccjit.1 conf-rdkit.1
183203
fi
184204

185-
if [ $target = "alpine" ]; then
205+
if [ "$target" = alpine ]; then
186206
test_depext conf-clang-format.1
187207
# conf-pandoc.0.1
188208
fi
189209

190-
if [ $target = "fedora" ]; then
210+
if [ "$target" = fedora ]; then
191211
test_depext conf-emacs.1
192212
fi
193213

194-
if [ $target = "oraclelinux" ] || [ $target = "centos" ]; then
214+
if [ "$target" = oraclelinux ] || [ "$target" = centos ]; then
195215
test_depext conf-pkg-config.3
196216
fi
197217

@@ -203,7 +223,7 @@ if [ -z "$DEPEXTS2TEST" ]; then
203223
exit 3
204224
fi
205225

206-
cat >>$dir/entrypoint.sh << EOF
226+
cat >> "$dir/entrypoint.sh" << EOF
207227
ERRORS=""
208228
test_depexts () {
209229
for pkg in \$@ ; do
@@ -222,10 +242,10 @@ fi
222242
EOF
223243

224244
# Test depexts update
225-
cat >>$dir/entrypoint.sh << EOF
245+
cat >> "$dir/entrypoint.sh" << EOF
226246
./opam update --depexts || ERRORS="\$ERRORS opam-update-depexts"
227247
EOF
228248

229-
chmod +x $dir/entrypoint.sh
249+
chmod +x "$dir/entrypoint.sh"
230250

231251
#done

.github/scripts/main/hygiene.sh

+6
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ else
135135
(set +x; echo -e "shell/install.sh: \e[31mERROR\e[0m") 2>/dev/null
136136
ERROR=1
137137
fi
138+
if shellcheck .github/scripts/depexts/generate-actions.sh ; then
139+
(set +x; echo ".github/scripts/depexts/generate-actions.sh: OK") 2>/dev/null
140+
else
141+
(set +x; echo -e ".github/scripts/depexts/generate-actions.sh: \e[31mERROR\e[0m") 2>/dev/null
142+
ERROR=1
143+
fi
138144
(set +x ; echo -en "::endgroup::check shell scripts using shellcheck\r") 2>/dev/null
139145

140146
exit $ERROR

master_changes.md

+5
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ users)
231231
* Show Cygwin version info after loading it from the cache [#6383 @kit-ty-kate]
232232
* Upgrade the opam version used to setup the depexts workflows to 2.3.0 [#6444 @kit-ty-kate]
233233
* Enable the depexts workflow on master and when the opam description change [#6447 @kit-ty-kate]
234+
* Make depext generate action script pass spellcheck [#6471 @kit-ty-kate]
235+
* Add depext generate action script to spellcheck check action [#6471 @kit-ty-kate]
236+
* Some cleaning in depext generate action and instruction for local testing [#6471 @rjbou]
237+
* Cache the repository and a minimal one in docker image for depext jobs [#6471 @rjbou]
238+
* Use the good opam binary in depext jobs [#6471 @RyanGibb]
234239

235240
## Doc
236241
* Update the command to install opam to point to the new simplified url on opam.ocaml.org [#6226 @kit-ty-kate]

0 commit comments

Comments
 (0)