forgejo-release/testdata/forgejo-release-test.sh

75 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/sh
set -ex
2023-03-27 00:03:56 +03:00
DIR=$(mktemp -d)
2023-03-30 02:08:18 +03:00
trap "rm -fr $DIR" EXIT
2023-03-27 00:03:56 +03:00
test_teardown() {
setup_api
2023-03-30 02:08:18 +03:00
api DELETE repos/$REPO/releases/tags/$TAG || true
api DELETE repos/$REPO/tags/$TAG || true
rm -fr dist/release
setup_tea
2023-03-30 02:08:18 +03:00
$BIN_DIR/tea login delete $DOER || true
}
2023-03-27 00:03:56 +03:00
test_reset_repo() {
2023-03-30 02:08:18 +03:00
local project="$1"
api DELETE repos/$REPO || true
api POST user/repos --data-raw '{"name":"'$project'", "auto_init":true}'
git clone $FORGEJO/$REPO $DIR/repo
SHA=$(git -C $DIR/repo rev-parse HEAD)
2023-03-27 00:03:56 +03:00
}
test_setup() {
2023-03-30 02:08:18 +03:00
local project="$1"
test_reset_repo $project
mkdir -p $RELEASE_DIR
touch $RELEASE_DIR/file-one.txt
touch $RELEASE_DIR/file-two.txt
}
test_ensure_tag() {
2023-03-30 02:08:18 +03:00
api DELETE repos/$REPO/tags/$TAG || true
#
# idempotent
#
ensure_tag
2023-03-30 02:08:18 +03:00
api GET repos/$REPO/tags/$TAG > $DIR/tag1.json
ensure_tag
2023-03-30 02:08:18 +03:00
api GET repos/$REPO/tags/$TAG > $DIR/tag2.json
2023-03-27 00:03:56 +03:00
diff -u $DIR/tag[12].json
#
# sanity check on the SHA of an existing tag
#
(
2023-03-30 02:08:18 +03:00
SHA=12345
! ensure_tag
)
2023-03-30 02:08:18 +03:00
api DELETE repos/$REPO/tags/$TAG
}
test_run() {
2023-03-30 02:08:18 +03:00
local user="$1"
local project="$2"
test_teardown
2023-03-27 00:03:56 +03:00
to_push=$DIR/binaries-releases-to-push
pulled=$DIR/binaries-releases-pulled
RELEASE_DIR=$to_push
2023-03-30 02:08:18 +03:00
REPO=$user/$project
test_setup $project
test_ensure_tag
echo "================================ TEST BEGIN"
2023-03-30 02:08:18 +03:00
upload
RELEASE_DIR=$pulled
2023-03-30 02:08:18 +03:00
download
diff -r $to_push $pulled
echo "================================ TEST END"
}
2023-03-30 02:08:18 +03:00
: ${TAG:=v17.8.20-1}
. $(dirname $0)/../forgejo-release.sh