1
0
Fork 0
mirror of https://code.forgejo.org/actions/forgejo-release synced 2025-06-08 03:58:19 +02:00

adapt and test

This commit is contained in:
Earl Warren 2023-03-26 23:03:56 +02:00
parent fc5cdffbe4
commit 245db64a1e
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 42 additions and 36 deletions

45
testdata/forgejo-release-test.sh vendored Normal file → Executable file
View file

@ -2,31 +2,43 @@
set -ex
DIR=$(mktemp -d)
#trap "rm -fr $DIR" EXIT
test_teardown() {
setup_api
api DELETE repos/$PUSH_USER/forgejo/releases/tags/$TAG || true
api DELETE repos/$PUSH_USER/forgejo/tags/$TAG || true
api DELETE repos/$PUSH_USER/$REPO/releases/tags/$TAG || true
api DELETE repos/$PUSH_USER/$REPO/tags/$TAG || true
rm -fr dist/release
setup_tea
$BIN_DIR/tea login delete $RELEASETEAMUSER || true
}
test_reset_repo() {
api DELETE repos/$PUSH_USER/$REPO || true
api POST user/repos --data-raw '{"name":"'$REPO'", "auto_init":true}'
git clone $FORGEJO/$PUSH_USER/$REPO $DIR/repo
CI_COMMIT_SHA=$(git -C $DIR/repo rev-parse HEAD)
}
test_setup() {
test_reset_repo
mkdir -p $RELEASE_DIR
touch $RELEASE_DIR/file-one.txt
touch $RELEASE_DIR/file-two.txt
}
test_ensure_tag() {
api DELETE repos/$PUSH_USER/forgejo/tags/$TAG || true
api DELETE repos/$PUSH_USER/$REPO/tags/$TAG || true
#
# idempotent
#
ensure_tag
api GET repos/$PUSH_USER/forgejo/tags/$TAG > /tmp/tag1.json
api GET repos/$PUSH_USER/$REPO/tags/$TAG > $DIR/tag1.json
ensure_tag
api GET repos/$PUSH_USER/forgejo/tags/$TAG > /tmp/tag2.json
diff -u /tmp/tag[12].json
api GET repos/$PUSH_USER/$REPO/tags/$TAG > $DIR/tag2.json
diff -u $DIR/tag[12].json
#
# sanity check on the SHA of an existing tag
#
@ -34,21 +46,13 @@ test_ensure_tag() {
CI_COMMIT_SHA=12345
! ensure_tag
)
api DELETE repos/$PUSH_USER/forgejo/tags/$TAG
api DELETE repos/$PUSH_USER/$REPO/tags/$TAG
}
#
# Running the test locally instead of within Woodpecker
#
# 1. Setup: obtain a token at https://codeberg.org/user/settings/applications
# 2. Run: RELEASETEAMUSER=<username> RELEASETEAMTOKEn=<apptoken> binaries-pull-push-test.sh test_run
# 3. Verify: (optional) manual verification at https://codeberg.org/<username>/forgejo/releases
# 4. Cleanup: RELEASETEAMUSER=<username> RELEASETEAMTOKEn=<apptoken> binaries-pull-push-test.sh test_teardown
#
test_run() {
test_teardown
to_push=/tmp/binaries-releases-to-push
pulled=/tmp/binaries-releases-pulled
to_push=$DIR/binaries-releases-to-push
pulled=$DIR/binaries-releases-pulled
RELEASE_DIR=$to_push
test_setup
test_ensure_tag
@ -60,10 +64,11 @@ test_run() {
echo "================================ TEST END"
}
: ${CI_REPO_OWNER:=dachary}
: ${RELEASETEAMUSER:=root}
: ${REPO:=testrepo}
: ${CI_REPO_OWNER:=root}
: ${PULL_USER=$CI_REPO_OWNER}
: ${PUSH_USER=$CI_REPO_OWNER}
: ${CI_COMMIT_TAG:=W17.8.20-1}
: ${CI_COMMIT_SHA:=$(git rev-parse HEAD)}
: ${CI_COMMIT_TAG:=v17.8.20-1}
. $(dirname $0)/../forgejo-release.sh