mirror of
https://code.forgejo.org/actions/forgejo-release.git
synced 2024-11-25 03:24:45 +01: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
|
- id: forgejo
|
||||||
uses: https://code.forgejo.org/actions/setup-forgejo@v1
|
uses: https://code.forgejo.org/actions/setup-forgejo@v1
|
||||||
with:
|
with:
|
||||||
|
user: testuser
|
||||||
image-version: 1.19
|
image-version: 1.19
|
||||||
- run: |
|
- run: |
|
||||||
set -ex
|
set -ex
|
||||||
curl ${{ steps.forgejo.outputs.url }}/api/forgejo/v1/version | grep 1.19
|
curl -sS ${{ steps.forgejo.outputs.url }}/api/forgejo/v1/version | grep 1.19
|
||||||
ls -l forgejo-release.sh
|
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
|
set -ex
|
||||||
|
|
||||||
: ${PULL_USER:=forgejo-integration}
|
: ${PULL_USER:=forgejo-integration}
|
||||||
if test "$CI_REPO" = "forgejo/release" ; then
|
: ${PUSH_USER:=forgejo}
|
||||||
: ${PUSH_USER:=forgejo}
|
|
||||||
else
|
|
||||||
: ${PUSH_USER:=forgejo-experimental}
|
|
||||||
fi
|
|
||||||
: ${TAG:=${CI_COMMIT_TAG}}
|
: ${TAG:=${CI_COMMIT_TAG}}
|
||||||
: ${DOMAIN:=codeberg.org}
|
: ${FORGEJO:=https://codeberg.org}
|
||||||
|
: ${REPO:=forgejo}
|
||||||
: ${RELEASE_DIR:=dist/release}
|
: ${RELEASE_DIR:=dist/release}
|
||||||
: ${BIN_DIR:=/tmp}
|
: ${BIN_DIR:=/tmp}
|
||||||
: ${TEA_VERSION:=0.9.0}
|
: ${TEA_VERSION:=0.9.0}
|
||||||
|
@ -23,7 +20,7 @@ setup_tea() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure_tag() {
|
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)
|
local sha=$(jq --raw-output .commit.sha < /tmp/tag.json)
|
||||||
if test "$sha" != "$CI_COMMIT_SHA" ; then
|
if test "$sha" != "$CI_COMMIT_SHA" ; then
|
||||||
cat /tmp/tag.json
|
cat /tmp/tag.json
|
||||||
|
@ -31,7 +28,7 @@ ensure_tag() {
|
||||||
false
|
false
|
||||||
fi
|
fi
|
||||||
else
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,19 +39,19 @@ upload() {
|
||||||
test ${RELEASETYPE+false} || echo "Uploading as Stable"
|
test ${RELEASETYPE+false} || echo "Uploading as Stable"
|
||||||
ensure_tag
|
ensure_tag
|
||||||
anchor=$(echo $CI_COMMIT_TAG | sed -e 's/^v//' -e 's/[^a-zA-Z0-9]/-/g')
|
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() {
|
push() {
|
||||||
setup_api
|
setup_api
|
||||||
setup_tea
|
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
|
upload
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_api() {
|
setup_api() {
|
||||||
if ! which jq || ! which curl ; then
|
if ! which jq curl ; then
|
||||||
apk --update --no-cache add jq curl
|
apt-get install -y -qq jq curl
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +61,7 @@ api() {
|
||||||
path=$1
|
path=$1
|
||||||
shift
|
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() {
|
pull() {
|
||||||
|
@ -72,7 +69,7 @@ pull() {
|
||||||
(
|
(
|
||||||
mkdir -p $RELEASE_DIR
|
mkdir -p $RELEASE_DIR
|
||||||
cd $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
|
jq --raw-output '.assets[] | "\(.name) \(.browser_download_url)"' < /tmp/assets.json | while read name url ; do
|
||||||
wget --quiet -O $name $url
|
wget --quiet -O $name $url
|
||||||
done
|
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
|
set -ex
|
||||||
|
|
||||||
|
DIR=$(mktemp -d)
|
||||||
|
|
||||||
|
#trap "rm -fr $DIR" EXIT
|
||||||
|
|
||||||
test_teardown() {
|
test_teardown() {
|
||||||
setup_api
|
setup_api
|
||||||
api DELETE repos/$PUSH_USER/forgejo/releases/tags/$TAG || true
|
api DELETE repos/$PUSH_USER/$REPO/releases/tags/$TAG || true
|
||||||
api DELETE repos/$PUSH_USER/forgejo/tags/$TAG || true
|
api DELETE repos/$PUSH_USER/$REPO/tags/$TAG || true
|
||||||
rm -fr dist/release
|
rm -fr dist/release
|
||||||
setup_tea
|
setup_tea
|
||||||
$BIN_DIR/tea login delete $RELEASETEAMUSER || true
|
$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_setup() {
|
||||||
|
test_reset_repo
|
||||||
mkdir -p $RELEASE_DIR
|
mkdir -p $RELEASE_DIR
|
||||||
touch $RELEASE_DIR/file-one.txt
|
touch $RELEASE_DIR/file-one.txt
|
||||||
touch $RELEASE_DIR/file-two.txt
|
touch $RELEASE_DIR/file-two.txt
|
||||||
}
|
}
|
||||||
|
|
||||||
test_ensure_tag() {
|
test_ensure_tag() {
|
||||||
api DELETE repos/$PUSH_USER/forgejo/tags/$TAG || true
|
api DELETE repos/$PUSH_USER/$REPO/tags/$TAG || true
|
||||||
#
|
#
|
||||||
# idempotent
|
# idempotent
|
||||||
#
|
#
|
||||||
ensure_tag
|
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
|
ensure_tag
|
||||||
api GET repos/$PUSH_USER/forgejo/tags/$TAG > /tmp/tag2.json
|
api GET repos/$PUSH_USER/$REPO/tags/$TAG > $DIR/tag2.json
|
||||||
diff -u /tmp/tag[12].json
|
diff -u $DIR/tag[12].json
|
||||||
#
|
#
|
||||||
# sanity check on the SHA of an existing tag
|
# sanity check on the SHA of an existing tag
|
||||||
#
|
#
|
||||||
|
@ -34,21 +46,13 @@ test_ensure_tag() {
|
||||||
CI_COMMIT_SHA=12345
|
CI_COMMIT_SHA=12345
|
||||||
! ensure_tag
|
! 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_run() {
|
||||||
test_teardown
|
test_teardown
|
||||||
to_push=/tmp/binaries-releases-to-push
|
to_push=$DIR/binaries-releases-to-push
|
||||||
pulled=/tmp/binaries-releases-pulled
|
pulled=$DIR/binaries-releases-pulled
|
||||||
RELEASE_DIR=$to_push
|
RELEASE_DIR=$to_push
|
||||||
test_setup
|
test_setup
|
||||||
test_ensure_tag
|
test_ensure_tag
|
||||||
|
@ -60,10 +64,11 @@ test_run() {
|
||||||
echo "================================ TEST END"
|
echo "================================ TEST END"
|
||||||
}
|
}
|
||||||
|
|
||||||
: ${CI_REPO_OWNER:=dachary}
|
: ${RELEASETEAMUSER:=root}
|
||||||
|
: ${REPO:=testrepo}
|
||||||
|
: ${CI_REPO_OWNER:=root}
|
||||||
: ${PULL_USER=$CI_REPO_OWNER}
|
: ${PULL_USER=$CI_REPO_OWNER}
|
||||||
: ${PUSH_USER=$CI_REPO_OWNER}
|
: ${PUSH_USER=$CI_REPO_OWNER}
|
||||||
: ${CI_COMMIT_TAG:=W17.8.20-1}
|
: ${CI_COMMIT_TAG:=v17.8.20-1}
|
||||||
: ${CI_COMMIT_SHA:=$(git rev-parse HEAD)}
|
|
||||||
|
|
||||||
. $(dirname $0)/../forgejo-release.sh
|
. $(dirname $0)/../forgejo-release.sh
|
||||||
|
|
Loading…
Reference in a new issue