Skip to content

Commit a2750b8

Browse files
stertooylimakzi
andauthored
Cleanup, more CI testing for scripts, validate inputs (#49)
* Cleanup, more CI testing for scripts, validate inputs * Add missing quotes in pkginfo_to_json.g * Add linebreak Co-authored-by: Kamil Zabielski <50334623+limakzi@users.noreply.github.com> --------- Co-authored-by: Kamil Zabielski <50334623+limakzi@users.noreply.github.com>
1 parent fc7ca56 commit a2750b8

File tree

7 files changed

+115
-50
lines changed

7 files changed

+115
-50
lines changed

.github/workflows/CI.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@ jobs:
6565

6666
- name: "Shellcheck"
6767
shell: bash
68+
working-directory: scripts
6869
run: shellcheck -o all *.sh
6970

7071
- name: "Test check_filenames.sh"
7172
shell: bash
73+
working-directory: scripts
7274
run: |
73-
mkdir -p filename-dir
75+
mkdir -p filename-dir/doc
7476
cd filename-dir
75-
mkdir -p doc
7677
touch :q \\Users\\GillBates AUX COM².tar.gz period. space\ DOC \
7778
PackageInfo.g doc/manual.pdf manual.pdf README readme.txt auxiliary .gaplint.yml
7879
../check_filenames.sh > $RUNNER_TEMP/filenames_run.txt || true # suppress expected error here
@@ -89,6 +90,7 @@ jobs:
8990
9091
- name: "Test check_absolute_paths.sh"
9192
shell: bash
93+
working-directory: scripts
9294
run: |
9395
mkdir -p paths-dir/doc
9496
cd paths-dir
@@ -101,3 +103,30 @@ jobs:
101103
./doc/chap1_mj.html
102104
./doc/chap2_mj.html
103105
EOF
106+
107+
- name: "Test check_symlinks.sh"
108+
shell: bash
109+
working-directory: scripts
110+
run: |
111+
mkdir -p symlinks-dir
112+
cd symlinks-dir
113+
echo "THIS FILE IS NOT A SYMLINK" > actual.file
114+
../check_symlinks.sh > $RUNNER_TEMP/symlinks_run.txt # should not give error
115+
ln -s actual.file sym.link
116+
../check_symlinks.sh > $RUNNER_TEMP/symlinks_run.txt || true # suppress expected error here
117+
diff <(sort $RUNNER_TEMP/symlinks_run.txt) - <<EOF
118+
./sym.link
119+
EOF
120+
121+
- name: "Test check_date.sh"
122+
shell: bash
123+
working-directory: scripts
124+
run: |
125+
if ! ./check_date.sh "$(date +%Y-%m-%d)" \
126+
|| ! ./check_date.sh "$(date -d "1 day ago" +%Y-%m-%d)" \
127+
|| ! ./check_date.sh "$(date -d "1 day" +%Y-%m-%d)" \
128+
|| ./check_date.sh "$(date -d "2 days ago" +%Y-%m-%d)" \
129+
|| ./check_date.sh "$(date -d "2 days" +%Y-%m-%d)"
130+
then
131+
exit 1
132+
fi

action.yml

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ inputs:
1818
runs:
1919
using: "composite"
2020
steps:
21+
- name: "Validate input"
22+
shell: bash
23+
run: |
24+
validate_boolean() {
25+
local input=$1
26+
local option_name=$2
27+
if ! [[ "$input" =~ ^(true|false)$ ]]; then
28+
echo "::error::Invalid value for option $option_name. Expected 'true' or 'false', but found '$input'"
29+
exit 1;
30+
fi
31+
}
32+
33+
validate_boolean "${{ inputs.dry-run }}" dry-run
34+
validate_boolean "${{ inputs.force }}" force
2135
2236
- name: "Validate PackageInfo.g"
2337
shell: bash
@@ -27,7 +41,7 @@ runs:
2741
- name: "Check documentation for absolute paths"
2842
shell: bash
2943
run: |
30-
$GITHUB_ACTION_PATH/check_absolute_paths.sh || {
44+
$GITHUB_ACTION_PATH/scripts/check_absolute_paths.sh || {
3145
echo "::error::Found absolute paths in HTML file(s)"
3246
exit 1
3347
}
@@ -58,10 +72,10 @@ runs:
5872
- name: "Generate package-info.json"
5973
shell: bash
6074
run: |
61-
gap -A -q $GITHUB_ACTION_PATH/pkginfo_to_json.g
75+
gap -A -q $GITHUB_ACTION_PATH/scripts/pkginfo_to_json.g
6276
if [ ! -f "package-info.json" ] ; then
63-
echo "::error::Could not create package-info.json"
64-
exit 1
77+
echo "::error::Could not create package-info.json"
78+
exit 1
6579
fi
6680
mv package-info.json $ASSETS
6781
@@ -75,11 +89,11 @@ runs:
7589
[ "${TMP[1]}" = "github.com" ] &&
7690
[ "${TMP[4]}" = "releases" ] &&
7791
[ "${TMP[5]}" = "download" ]; then
78-
echo "TAG=${TMP[6]}" | tee -a "$GITHUB_ENV"
79-
echo "BASENAME=${TMP[7]}" | tee -a "$GITHUB_ENV"
92+
echo "TAG=${TMP[6]}" | tee -a "$GITHUB_ENV"
93+
echo "BASENAME=${TMP[7]}" | tee -a "$GITHUB_ENV"
8094
else
81-
echo "::error::ArchiveURL in PackageInfo.g does not point to a GitHub release"
82-
exit 1
95+
echo "::error::ArchiveURL in PackageInfo.g does not point to a GitHub release"
96+
exit 1
8397
fi
8498
echo "PKGNAME=$(cat package-info.json | jq -r '.PackageName')" | tee -a "$GITHUB_ENV"
8599
echo "VERSION=$(cat package-info.json | jq -r '.Version')" | tee -a "$GITHUB_ENV"
@@ -113,19 +127,10 @@ runs:
113127
shell: bash
114128
if: ${{ inputs.force != 'true' }}
115129
run: |
116-
# Convert DD/MM/YYYY to YYYY-MM-DD
117-
if [[ "$DATE" =~ ^[0-9]{2}/[0-9]{2}/[0-9]{4}$ ]]; then
118-
DATE=$(echo "$DATE" | awk -F/ '{print $3"-"$2"-"$1}')
119-
fi
120-
121-
TODAY=$(date +%Y-%m-%d)
122-
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
123-
TOMORROW=$(date -d "tomorrow" +%Y-%m-%d)
124-
125-
if [[ "$DATE" != "$TODAY" && "$DATE" != "$YESTERDAY" && "$DATE" != "$TOMORROW" ]]; then
126-
echo "::error::Date found in PackageInfo.g ($DATE) does not match current date ($TODAY) up to ±1 day."
130+
$GITHUB_ACTION_PATH/scripts/check_date.sh $DATE || {
131+
echo "::error::Date found in PackageInfo.g ($DATE) does not match current date ($(date +%Y-%m-%d)) up to ±1 day."
127132
exit 1
128-
fi
133+
}
129134
130135
# We make a copy of the current directory to build the release from, because
131136
# the next step will remove files/folders that may be necessary for subsequent
@@ -140,15 +145,16 @@ runs:
140145
shell: bash
141146
working-directory: ${{ runner.temp }}/${{ env.BASENAME }}
142147
run: |
143-
echo "::group::Cleanup git and github related files"
144-
rm -rvf .git* .hg* .cvs* .circleci
145-
echo "::group::Cleanup codecov, travis, azure-pipelines"
146-
rm -fv .codecov.* .travis.* .appveyor.* azure-pipelines.*
147-
rm -fv .gaplint.*
148-
rm -fv requirements.txt
148+
echo "::group::Cleanup git and github related files"
149+
rm -rvf .git* .hg* .cvs* .circleci
150+
151+
echo "::group::Cleanup codecov, travis, azure-pipelines"
152+
rm -fv .codecov.* .travis.* .appveyor.* azure-pipelines.*
153+
rm -fv .gaplint.*
154+
rm -fv requirements.txt
149155
150-
echo "::group::Cleanup macOS metadata"
151-
find . -name .DS_Store -exec rm -f {} +
156+
echo "::group::Cleanup macOS metadata"
157+
find . -name .DS_Store -exec rm -f {} +
152158
153159
- name: "Run autogen.sh"
154160
shell: bash
@@ -165,37 +171,41 @@ runs:
165171
shell: bash
166172
working-directory: ${{ runner.temp }}/${{ env.BASENAME }}
167173
run : |
168-
if find . -type l | grep -q .; then
174+
$GITHUB_ACTION_PATH/scripts/check_symlinks.sh || {
169175
echo "::error::Symlinks detected"
170176
exit 1
171-
fi
177+
}
172178
173179
- name: "Reject bad filenames"
174180
shell: bash
175181
working-directory: ${{ runner.temp }}/${{ env.BASENAME }}
176-
run: $GITHUB_ACTION_PATH/check_filenames.sh
182+
run: |
183+
$GITHUB_ACTION_PATH/scripts/check_filenames.sh || {
184+
echo "::error::Found problematic filenames"
185+
exit 1
186+
}
177187
178188
- name: "Create archives"
179189
shell: bash
180190
working-directory: ${{ runner.temp }}
181191
run: |
182192
for EXT in $ARCHIVE_FORMATS ; do
183-
ARCHIVENAME=$BASENAME$EXT
184-
echo "Creating $ARCHIVENAME ..."
185-
case $EXT in
193+
ARCHIVENAME=$BASENAME$EXT
194+
echo "Creating $ARCHIVENAME ..."
195+
case $EXT in
186196
.tar.gz) tar cf - "$BASENAME" | gzip -9c > "$ASSETS/$ARCHIVENAME" ;;
187197
.tar.bz2) tar cf - "$BASENAME" | bzip2 -9c > "$ASSETS/$ARCHIVENAME" ;;
188198
.zip) zip -r9 --quiet "$ASSETS/$ARCHIVENAME" "$BASENAME" ;;
189199
*)
190-
echo "::error::Unsupported archive format $EXT"
191-
exit 1
192-
;;
193-
esac
194-
if [ ! -f "$ASSETS/$ARCHIVENAME" ] ; then
195-
echo "::error::Failed at creating "$ARCHIVENAME""
196-
exit 1
197-
fi
198-
echo "Created $ARCHIVENAME"
200+
echo "::error::Unsupported archive format $EXT"
201+
exit 1
202+
;;
203+
esac
204+
if [ ! -f "$ASSETS/$ARCHIVENAME" ] ; then
205+
echo "::error::Failed at creating '$ARCHIVENAME'"
206+
exit 1
207+
fi
208+
echo "Created $ARCHIVENAME"
199209
done
200210
201211
- name: "Copy manual(s)"

scripts/check_date.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
set -o pipefail
4+
5+
DATE="$1"
6+
7+
# Convert DD/MM/YYYY to YYYY-MM-DD
8+
if [[ "${DATE}" =~ ^[0-9]{2}/[0-9]{2}/[0-9]{4}$ ]]; then
9+
DATE=$(echo "${DATE}" | awk -F/ '{print $3"-"$2"-"$1}')
10+
fi
11+
12+
TODAY=$(date +%Y-%m-%d)
13+
YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
14+
TOMORROW=$(date -d "tomorrow" +%Y-%m-%d)
15+
16+
if [[ "${DATE}" != "${TODAY}" && "${DATE}" != "${YESTERDAY}" && "${DATE}" != "${TOMORROW}" ]]; then
17+
exit 1
18+
fi

scripts/check_symlinks.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
set -o pipefail
4+
5+
if find . -type l | grep .; then
6+
exit 1
7+
fi
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ LoadPackage("json");
33
InstallMethod(RecNames, [IsRecord and IsInternalRep], x -> AsSSortedList(REC_NAMES(x)));
44

55
InstallMethod(_GapToJsonStreamInternal, [IsOutputStream, IsObject],
6-
function(o, x)
6+
function(o, x)
77
PrintTo(o, "null");
8-
end);
8+
end
9+
);
910

1011
Read("PackageInfo.g");
1112
if not IsBound(GAPInfo.PackageInfoCurrent) then
12-
Print("Reading PackageInfo.g failed\n");
13-
FORCE_QUIT_GAP(2);
13+
Exec("echo \"::error::Reading PackageInfo.g failed\"");
14+
ForceQuitGap(2);
1415
fi;
1516
pkginfo := GAPInfo.PackageInfoCurrent;
1617

@@ -19,7 +20,7 @@ if IsBound(pkginfo.PackageDoc) and not IsList(pkginfo.PackageDoc) then
1920
pkginfo.PackageDoc := [pkginfo.PackageDoc];
2021
fi;
2122

22-
output := OutputTextFile("package-info.json", false );
23+
output := OutputTextFile("package-info.json", false);
2324
GapToJsonStream(output, pkginfo);
2425
CloseStream(output);
2526

0 commit comments

Comments
 (0)