From ca02749d652d08e57f9d7c930b5c6db7df04b5ce Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Thu, 30 Mar 2023 01:08:18 +0200 Subject: [PATCH] adapt shell tests --- .forgejo/workflows/integration.yml | 7 +++-- forgejo-release.sh | 2 +- testdata/forgejo-release-test.sh | 47 +++++++++++++++--------------- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index c8da8e2..f0ec5fe 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -20,6 +20,7 @@ jobs: run: | set -ex export FORGEJO="${{ steps.forgejo.outputs.url }}" - export RELEASETEAMTOKEN="${{ steps.forgejo.outputs.token }}" - export CI_REPO_OWNER=testuser - testdata/forgejo-release-test.sh test_run + export TOKEN="${{ steps.forgejo.outputs.token }}" + export DOER=testuser + export VERBOSE=true + testdata/forgejo-release-test.sh test_run testuser otherrepo diff --git a/forgejo-release.sh b/forgejo-release.sh index a6cd273..ea4a3ee 100755 --- a/forgejo-release.sh +++ b/forgejo-release.sh @@ -54,7 +54,7 @@ upload() { setup_api() { if ! which jq curl ; then - apt-get install -y -qq jq curl + apt-get install -y -qq jq curl wget fi } diff --git a/testdata/forgejo-release-test.sh b/testdata/forgejo-release-test.sh index 210c317..0131212 100755 --- a/testdata/forgejo-release-test.sh +++ b/testdata/forgejo-release-test.sh @@ -4,71 +4,72 @@ set -ex DIR=$(mktemp -d) -#trap "rm -fr $DIR" EXIT +trap "rm -fr $DIR" EXIT test_teardown() { setup_api - api DELETE repos/$PUSH_USER/$REPO/releases/tags/$TAG || true - api DELETE repos/$PUSH_USER/$REPO/tags/$TAG || true + api DELETE repos/$REPO/releases/tags/$TAG || true + api DELETE repos/$REPO/tags/$TAG || true rm -fr dist/release setup_tea - $BIN_DIR/tea login delete $RELEASETEAMUSER || true + $BIN_DIR/tea login delete $DOER || 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) + 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) } test_setup() { - test_reset_repo + 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() { - api DELETE repos/$PUSH_USER/$REPO/tags/$TAG || true + api DELETE repos/$REPO/tags/$TAG || true # # idempotent # ensure_tag - api GET repos/$PUSH_USER/$REPO/tags/$TAG > $DIR/tag1.json + api GET repos/$REPO/tags/$TAG > $DIR/tag1.json ensure_tag - api GET repos/$PUSH_USER/$REPO/tags/$TAG > $DIR/tag2.json + api GET repos/$REPO/tags/$TAG > $DIR/tag2.json diff -u $DIR/tag[12].json # # sanity check on the SHA of an existing tag # ( - CI_COMMIT_SHA=12345 + SHA=12345 ! ensure_tag ) - api DELETE repos/$PUSH_USER/$REPO/tags/$TAG + api DELETE repos/$REPO/tags/$TAG } test_run() { + local user="$1" + local project="$2" test_teardown to_push=$DIR/binaries-releases-to-push pulled=$DIR/binaries-releases-pulled RELEASE_DIR=$to_push - test_setup + REPO=$user/$project + test_setup $project test_ensure_tag echo "================================ TEST BEGIN" - push + upload RELEASE_DIR=$pulled - pull + download diff -r $to_push $pulled echo "================================ TEST END" } -: ${RELEASETEAMUSER:=root} -: ${REPO:=testrepo} -: ${CI_REPO_OWNER:=root} -: ${PULL_USER=$CI_REPO_OWNER} -: ${PUSH_USER=$CI_REPO_OWNER} -: ${CI_COMMIT_TAG:=v17.8.20-1} +: ${DOER:=root} +: ${TAG:=v17.8.20-1} . $(dirname $0)/../forgejo-release.sh