mirror of
https://code.forgejo.org/actions/forgejo-release.git
synced 2024-12-22 07:35:48 +02:00
adapt and test
This commit is contained in:
parent
fc5cdffbe4
commit
245db64a1e
3 changed files with 42 additions and 36 deletions
|
@ -7,8 +7,12 @@ jobs:
|
|||
- id: forgejo
|
||||
uses: https://code.forgejo.org/actions/setup-forgejo@v1
|
||||
with:
|
||||
user: testuser
|
||||
image-version: 1.19
|
||||
- run: |
|
||||
set -ex
|
||||
curl ${{ steps.forgejo.outputs.url }}/api/forgejo/v1/version | grep 1.19
|
||||
ls -l forgejo-release.sh
|
||||
curl -sS ${{ steps.forgejo.outputs.url }}/api/forgejo/v1/version | grep 1.19
|
||||
export FORGEJO="${{ steps.forgejo.outputs.url }}"
|
||||
export RELEASETEAMTOKEN="${{ steps.forgejo.outputs.token }}"
|
||||
export CI_REPO_OWNER=testuser
|
||||
testdata/forgejo-release-test.sh test_run
|
||||
|
|
|
@ -3,13 +3,10 @@
|
|||
set -ex
|
||||
|
||||
: ${PULL_USER:=forgejo-integration}
|
||||
if test "$CI_REPO" = "forgejo/release" ; then
|
||||
: ${PUSH_USER:=forgejo}
|
||||
else
|
||||
: ${PUSH_USER:=forgejo-experimental}
|
||||
fi
|
||||
: ${PUSH_USER:=forgejo}
|
||||
: ${TAG:=${CI_COMMIT_TAG}}
|
||||
: ${DOMAIN:=codeberg.org}
|
||||
: ${FORGEJO:=https://codeberg.org}
|
||||
: ${REPO:=forgejo}
|
||||
: ${RELEASE_DIR:=dist/release}
|
||||
: ${BIN_DIR:=/tmp}
|
||||
: ${TEA_VERSION:=0.9.0}
|
||||
|
@ -23,7 +20,7 @@ setup_tea() {
|
|||
}
|
||||
|
||||
ensure_tag() {
|
||||
if api GET repos/$PUSH_USER/forgejo/tags/$TAG > /tmp/tag.json ; then
|
||||
if api GET repos/$PUSH_USER/$REPO/tags/$TAG > /tmp/tag.json ; then
|
||||
local sha=$(jq --raw-output .commit.sha < /tmp/tag.json)
|
||||
if test "$sha" != "$CI_COMMIT_SHA" ; then
|
||||
cat /tmp/tag.json
|
||||
|
@ -31,7 +28,7 @@ ensure_tag() {
|
|||
false
|
||||
fi
|
||||
else
|
||||
api POST repos/$PUSH_USER/forgejo/tags --data-raw '{"tag_name": "'$CI_COMMIT_TAG'", "target": "'$CI_COMMIT_SHA'"}'
|
||||
api POST repos/$PUSH_USER/$REPO/tags --data-raw '{"tag_name": "'$CI_COMMIT_TAG'", "target": "'$CI_COMMIT_SHA'"}'
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -42,19 +39,19 @@ upload() {
|
|||
test ${RELEASETYPE+false} || echo "Uploading as Stable"
|
||||
ensure_tag
|
||||
anchor=$(echo $CI_COMMIT_TAG | sed -e 's/^v//' -e 's/[^a-zA-Z0-9]/-/g')
|
||||
$BIN_DIR/tea release create $ASSETS --repo $PUSH_USER/forgejo --note "See https://codeberg.org/forgejo/forgejo/src/branch/forgejo/RELEASE-NOTES.md#${anchor}" --tag $CI_COMMIT_TAG --title $CI_COMMIT_TAG ${RELEASETYPE}
|
||||
$BIN_DIR/tea release create $ASSETS --repo $PUSH_USER/$REPO --note "$RELEASENOTES" --tag $CI_COMMIT_TAG --title $CI_COMMIT_TAG ${RELEASETYPE}
|
||||
}
|
||||
|
||||
push() {
|
||||
setup_api
|
||||
setup_tea
|
||||
GITEA_SERVER_TOKEN=$RELEASETEAMTOKEN $BIN_DIR/tea login add --name $RELEASETEAMUSER --url $DOMAIN
|
||||
GITEA_SERVER_TOKEN=$RELEASETEAMTOKEN $BIN_DIR/tea login add --name $RELEASETEAMUSER --url $FORGEJO
|
||||
upload
|
||||
}
|
||||
|
||||
setup_api() {
|
||||
if ! which jq || ! which curl ; then
|
||||
apk --update --no-cache add jq curl
|
||||
if ! which jq curl ; then
|
||||
apt-get install -y -qq jq curl
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -64,7 +61,7 @@ api() {
|
|||
path=$1
|
||||
shift
|
||||
|
||||
curl --fail -X $method -sS -H "Content-Type: application/json" -H "Authorization: token $RELEASETEAMTOKEN" "$@" https://$DOMAIN/api/v1/$path
|
||||
curl --fail -X $method -sS -H "Content-Type: application/json" -H "Authorization: token $RELEASETEAMTOKEN" "$@" $FORGEJO/api/v1/$path
|
||||
}
|
||||
|
||||
pull() {
|
||||
|
@ -72,7 +69,7 @@ pull() {
|
|||
(
|
||||
mkdir -p $RELEASE_DIR
|
||||
cd $RELEASE_DIR
|
||||
api GET repos/$PULL_USER/forgejo/releases/tags/$TAG > /tmp/assets.json
|
||||
api GET repos/$PULL_USER/$REPO/releases/tags/$TAG > /tmp/assets.json
|
||||
jq --raw-output '.assets[] | "\(.name) \(.browser_download_url)"' < /tmp/assets.json | while read name url ; do
|
||||
wget --quiet -O $name $url
|
||||
done
|
||||
|
|
45
testdata/forgejo-release-test.sh
vendored
Normal file → Executable file
45
testdata/forgejo-release-test.sh
vendored
Normal file → Executable 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
|
||||
|
|
Loading…
Reference in a new issue