2023-05-26 11:03:49 +00:00
|
|
|
#!/bin/bash
|
2023-04-01 09:12:56 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
2023-03-26 15:41:37 +00:00
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
test_teardown() {
|
|
|
|
setup_api
|
2023-03-29 23:08:18 +00:00
|
|
|
api DELETE repos/$REPO/releases/tags/$TAG || true
|
|
|
|
api DELETE repos/$REPO/tags/$TAG || true
|
2023-03-26 15:41:37 +00:00
|
|
|
rm -fr dist/release
|
|
|
|
setup_tea
|
2023-03-29 23:08:18 +00:00
|
|
|
$BIN_DIR/tea login delete $DOER || true
|
2023-03-26 15:41:37 +00:00
|
|
|
}
|
|
|
|
|
2023-03-26 21:03:56 +00:00
|
|
|
test_reset_repo() {
|
2023-03-29 23:08:18 +00:00
|
|
|
local project="$1"
|
|
|
|
api DELETE repos/$REPO || true
|
|
|
|
api POST user/repos --data-raw '{"name":"'$project'", "auto_init":true}'
|
2023-05-26 11:03:49 +00:00
|
|
|
git clone $FORGEJO/$REPO $TMP_DIR/repo
|
|
|
|
SHA=$(git -C $TMP_DIR/repo rev-parse HEAD)
|
2023-03-26 21:03:56 +00:00
|
|
|
}
|
|
|
|
|
2023-03-26 15:41:37 +00:00
|
|
|
test_setup() {
|
2023-03-29 23:08:18 +00:00
|
|
|
local project="$1"
|
|
|
|
test_reset_repo $project
|
2023-03-26 15:41:37 +00:00
|
|
|
mkdir -p $RELEASE_DIR
|
|
|
|
touch $RELEASE_DIR/file-one.txt
|
|
|
|
touch $RELEASE_DIR/file-two.txt
|
|
|
|
}
|
|
|
|
|
2023-05-23 23:01:51 +00:00
|
|
|
test_wait_release_fail() {
|
|
|
|
! wait_release
|
|
|
|
}
|
|
|
|
|
|
|
|
test_wait_release() {
|
|
|
|
wait_release
|
|
|
|
release_draft true
|
|
|
|
! wait_release
|
|
|
|
}
|
|
|
|
|
2023-03-26 15:41:37 +00:00
|
|
|
test_ensure_tag() {
|
2023-03-29 23:08:18 +00:00
|
|
|
api DELETE repos/$REPO/tags/$TAG || true
|
2023-03-26 15:41:37 +00:00
|
|
|
#
|
|
|
|
# idempotent
|
|
|
|
#
|
|
|
|
ensure_tag
|
2023-05-26 11:03:49 +00:00
|
|
|
api GET repos/$REPO/tags/$TAG > $TMP_DIR/tag1.json
|
2023-03-26 15:41:37 +00:00
|
|
|
ensure_tag
|
2023-05-26 11:03:49 +00:00
|
|
|
api GET repos/$REPO/tags/$TAG > $TMP_DIR/tag2.json
|
|
|
|
diff -u $TMP_DIR/tag[12].json
|
2023-03-26 15:41:37 +00:00
|
|
|
#
|
|
|
|
# sanity check on the SHA of an existing tag
|
|
|
|
#
|
|
|
|
(
|
2023-03-29 23:08:18 +00:00
|
|
|
SHA=12345
|
2023-03-26 15:41:37 +00:00
|
|
|
! ensure_tag
|
|
|
|
)
|
2023-03-29 23:08:18 +00:00
|
|
|
api DELETE repos/$REPO/tags/$TAG
|
2023-03-26 15:41:37 +00:00
|
|
|
}
|
|
|
|
|
2023-05-26 11:03:49 +00:00
|
|
|
test_maybe_sign_release_no_gpg() {
|
|
|
|
test_maybe_sign_release_setup no_gpg
|
|
|
|
|
|
|
|
GPG_PRIVATE_KEY=
|
|
|
|
maybe_sign_release
|
|
|
|
|
|
|
|
! test -f $RELEASE_DIR/file-one.txt.asc
|
|
|
|
}
|
|
|
|
|
|
|
|
test_maybe_sign_release_gpg_no_passphrase() {
|
|
|
|
test_maybe_sign_release_setup gpg_no_passphrase
|
|
|
|
|
|
|
|
GPG_PRIVATE_KEY=testdata/gpg-private-no-passphrase.asc
|
|
|
|
maybe_sign_release
|
|
|
|
|
|
|
|
test_maybe_sign_release_skipped
|
|
|
|
test_maybe_sign_release_verify
|
|
|
|
}
|
|
|
|
|
|
|
|
test_maybe_sign_release_gpg() {
|
|
|
|
test_maybe_sign_release_setup gpg
|
|
|
|
|
|
|
|
GPG_PRIVATE_KEY=testdata/gpg-private.asc
|
|
|
|
GPG_PASSPHRASE=testdata/gpg-private.passphrase
|
|
|
|
maybe_sign_release
|
|
|
|
|
|
|
|
test_maybe_sign_release_skipped
|
|
|
|
test_maybe_sign_release_verify
|
|
|
|
}
|
|
|
|
|
|
|
|
test_maybe_sign_release_skipped() {
|
|
|
|
! test -f $RELEASE_DIR/file-one.txt.sha256.asc
|
|
|
|
! test -f $RELEASE_DIR/file-two.txt.sha256.asc
|
|
|
|
}
|
|
|
|
|
|
|
|
test_maybe_sign_release_verify() {
|
|
|
|
for file in $RELEASE_DIR/file-one.txt $RELEASE_DIR/file-two.txt; do
|
|
|
|
gpg --verify $file.asc $file
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
test_maybe_sign_release_setup() {
|
|
|
|
local name="$1"
|
|
|
|
|
|
|
|
echo "========= maybe_sign_release $name ========="
|
|
|
|
RELEASE_DIR=$TMP_DIR/$name
|
|
|
|
mkdir -p $RELEASE_DIR
|
|
|
|
GNUPGHOME=$TMP_DIR/$name/.gnupg
|
|
|
|
mkdir -p $GNUPGHOME
|
|
|
|
touch $RELEASE_DIR/file-one.txt
|
|
|
|
touch $RELEASE_DIR/file-one.txt.sha256
|
|
|
|
touch $RELEASE_DIR/file-two.txt
|
|
|
|
touch $RELEASE_DIR/file-two.txt.sha256
|
|
|
|
}
|
|
|
|
|
|
|
|
test_maybe_sign_release() {
|
|
|
|
test_maybe_sign_release_no_gpg
|
|
|
|
test_maybe_sign_release_gpg_no_passphrase
|
|
|
|
test_maybe_sign_release_gpg
|
|
|
|
}
|
|
|
|
|
2023-03-26 15:41:37 +00:00
|
|
|
test_run() {
|
2023-03-29 23:08:18 +00:00
|
|
|
local user="$1"
|
|
|
|
local project="$2"
|
2023-03-26 15:41:37 +00:00
|
|
|
test_teardown
|
2023-05-26 11:03:49 +00:00
|
|
|
to_push=$TMP_DIR/binaries-releases-to-push
|
|
|
|
pulled=$TMP_DIR/binaries-releases-pulled
|
2023-03-26 15:41:37 +00:00
|
|
|
RELEASE_DIR=$to_push
|
2023-03-29 23:08:18 +00:00
|
|
|
REPO=$user/$project
|
|
|
|
test_setup $project
|
2023-03-26 15:41:37 +00:00
|
|
|
test_ensure_tag
|
2023-05-23 23:01:51 +00:00
|
|
|
DELAY=0
|
|
|
|
test_wait_release_fail
|
2023-03-26 15:41:37 +00:00
|
|
|
echo "================================ TEST BEGIN"
|
2023-03-29 23:08:18 +00:00
|
|
|
upload
|
2023-03-26 15:41:37 +00:00
|
|
|
RELEASE_DIR=$pulled
|
2023-03-29 23:08:18 +00:00
|
|
|
download
|
2023-03-26 15:41:37 +00:00
|
|
|
diff -r $to_push $pulled
|
|
|
|
echo "================================ TEST END"
|
2023-05-23 23:01:51 +00:00
|
|
|
test_wait_release
|
2023-03-26 15:41:37 +00:00
|
|
|
}
|
|
|
|
|
2023-05-26 11:03:49 +00:00
|
|
|
TMP_DIR=$(mktemp -d)
|
|
|
|
|
|
|
|
trap "rm -fr $TMP_DIR" EXIT
|
|
|
|
|
2023-03-29 23:08:18 +00:00
|
|
|
: ${TAG:=v17.8.20-1}
|
2023-03-26 15:41:37 +00:00
|
|
|
|
|
|
|
. $(dirname $0)/../forgejo-release.sh
|