mirror of
				https://code.forgejo.org/actions/forgejo-release.git
				synced 2025-11-04 06:41:57 +02:00 
			
		
		
		
	feat: use tea binary from system if available (#53)
As a proposal solution to this issue: https://code.forgejo.org/actions/forgejo-release/issues/51 We use the system installed tea binary if available or download it as it was done before if not. The location of the binary is stored in a new variable `$TEA_BIN` which replaces the need for the `$ BIN_DIR` location. I tested it on Alpine and Debian. Co-authored-by: Rayan Mestiri <rayan.mestiri@gmail.com> Co-authored-by: Rayan MESTIRI <rayan.mestiri@NLGRSSL600K.ratpsmart.local> Reviewed-on: https://code.forgejo.org/actions/forgejo-release/pulls/53 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org> Co-authored-by: sheik <sheik@noreply.code.forgejo.org> Co-committed-by: sheik <sheik@noreply.code.forgejo.org>
This commit is contained in:
		
							parent
							
								
									85122bff5d
								
							
						
					
					
						commit
						7359830877
					
				
					 3 changed files with 27 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -7,4 +7,6 @@ jobs:
 | 
			
		|||
 | 
			
		||||
      - name: Unit tests of the supporting script forgejo-release.sh
 | 
			
		||||
        run: |
 | 
			
		||||
          testdata/forgejo-release-test.sh test_system_tea_bin
 | 
			
		||||
          testdata/forgejo-release-test.sh test_download_tea_bin
 | 
			
		||||
          testdata/forgejo-release-test.sh test_maybe_sign_release
 | 
			
		||||
| 
						 | 
				
			
			@ -12,7 +12,7 @@ if ${VERBOSE:-false}; then set -x; fi
 | 
			
		|||
: ${DOWNLOAD_LATEST:=false}
 | 
			
		||||
: ${TMP_DIR:=$(mktemp -d)}
 | 
			
		||||
: ${GNUPGHOME:=$TMP_DIR}
 | 
			
		||||
: ${BIN_DIR:=$TMP_DIR}
 | 
			
		||||
: ${TEA_BIN:=$TMP_DIR/tea}
 | 
			
		||||
: ${TEA_VERSION:=0.9.0}
 | 
			
		||||
: ${OVERRIDE:=false}
 | 
			
		||||
: ${HIDE_ARCHIVE_LINK:=false}
 | 
			
		||||
| 
						 | 
				
			
			@ -24,10 +24,12 @@ TAG_FILE="$TMP_DIR/tag$$.json"
 | 
			
		|||
export GNUPGHOME
 | 
			
		||||
 | 
			
		||||
setup_tea() {
 | 
			
		||||
    if ! test -f "$BIN_DIR"/tea; then
 | 
			
		||||
    if which tea 2>/dev/null; then
 | 
			
		||||
        TEA_BIN=$(which tea)
 | 
			
		||||
    else ! test -f $TEA_BIN;
 | 
			
		||||
        ARCH=$(dpkg --print-architecture)
 | 
			
		||||
        curl -sL https://dl.gitea.io/tea/$TEA_VERSION/tea-$TEA_VERSION-linux-"$ARCH" >"$BIN_DIR"/tea
 | 
			
		||||
        chmod +x "$BIN_DIR"/tea
 | 
			
		||||
        curl -sL https://dl.gitea.io/tea/$TEA_VERSION/tea-$TEA_VERSION-linux-"$ARCH" >$TEA_BIN
 | 
			
		||||
        chmod +x $TEA_BIN
 | 
			
		||||
    fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -89,11 +91,11 @@ upload_release() {
 | 
			
		|||
        echo "Uploading as Stable"
 | 
			
		||||
    fi
 | 
			
		||||
    ensure_tag
 | 
			
		||||
    if ! "$BIN_DIR"/tea release create "${assets[@]}" --repo $REPO --note "$RELEASENOTES" --tag "$TAG" --title "$TITLE" --draft ${releaseType} >&"$TMP_DIR"/tea.log; then
 | 
			
		||||
    if ! $TEA_BIN release create "${assets[@]}" --repo $REPO --note "$RELEASENOTES" --tag "$TAG" --title "$TITLE" --draft ${releaseType} >&"$TMP_DIR"/tea.log; then
 | 
			
		||||
        if grep --quiet 'Unknown API Error: 500' "$TMP_DIR"/tea.log && grep --quiet services/release/release.go:194 "$TMP_DIR"/tea.log; then
 | 
			
		||||
            echo "workaround v1.20 race condition https://codeberg.org/forgejo/forgejo/issues/1370"
 | 
			
		||||
            sleep 10
 | 
			
		||||
            "$BIN_DIR"/tea release create "${assets[@]}" --repo $REPO --note "$RELEASENOTES" --tag "$TAG" --title "$TITLE" --draft ${releaseType}
 | 
			
		||||
            $TEA_BIN release create "${assets[@]}" --repo $REPO --note "$RELEASENOTES" --tag "$TAG" --title "$TITLE" --draft ${releaseType}
 | 
			
		||||
        else
 | 
			
		||||
            cat "$TMP_DIR"/tea.log
 | 
			
		||||
            return 1
 | 
			
		||||
| 
						 | 
				
			
			@ -153,7 +155,7 @@ upload() {
 | 
			
		|||
    setup_api
 | 
			
		||||
    setup_tea
 | 
			
		||||
    rm -f ~/.config/tea/config.yml
 | 
			
		||||
    GITEA_SERVER_TOKEN=$TOKEN "$BIN_DIR"/tea login add --url $FORGEJO
 | 
			
		||||
    GITEA_SERVER_TOKEN=$TOKEN $TEA_BIN login add --url $FORGEJO
 | 
			
		||||
    maybe_sign_release
 | 
			
		||||
    maybe_override
 | 
			
		||||
    upload_release
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										16
									
								
								testdata/forgejo-release-test.sh
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								testdata/forgejo-release-test.sh
									
										
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -4,13 +4,27 @@
 | 
			
		|||
set -ex
 | 
			
		||||
PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}:  '
 | 
			
		||||
 | 
			
		||||
test_system_tea_bin() {
 | 
			
		||||
	SYSTEM_TEA_BIN=$TMP_DIR/tea
 | 
			
		||||
	touch $SYSTEM_TEA_BIN && chmod +x $SYSTEM_TEA_BIN
 | 
			
		||||
	export PATH=$TMP_DIR:$PATH
 | 
			
		||||
    setup_tea
 | 
			
		||||
	test $TEA_BIN == $SYSTEM_TEA_BIN
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
test_download_tea_bin() {
 | 
			
		||||
    # assume tea is not installed on system
 | 
			
		||||
    setup_tea
 | 
			
		||||
    test $TEA_BIN == $TMP_DIR/tea
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
test_teardown() {
 | 
			
		||||
    setup_api
 | 
			
		||||
    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 $DOER || true
 | 
			
		||||
    $TEA_BIN login delete $DOER || true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
test_reset_repo() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue