diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index bfc45f8..b4e6918 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -78,7 +78,26 @@ jobs: REPOSITORY: ${{ gitea.repository }} run: | set -eu - upload_url="${SERVER_URL%/}/api/v1/repos/$REPOSITORY/releases/$RELEASE_ID/assets" + release_url="${SERVER_URL%/}/api/v1/repos/$REPOSITORY/releases/$RELEASE_ID" + upload_url="$release_url/assets" + release_json="$(curl -fsS -H "Authorization: token $GITEA_TOKEN" "$release_url")" + + delete_asset_if_exists() { + asset_name="$1" + asset_id="$(printf '%s' "$release_json" \ + | tr '{' '\n' \ + | grep "\"name\":\"$asset_name\"" \ + | sed -n 's/.*"id":[[:space:]]*\([0-9][0-9]*\).*/\1/p' \ + | head -n 1)" + if [ -n "$asset_id" ]; then + curl -fsS -X DELETE "$upload_url/$asset_id" \ + -H "Authorization: token $GITEA_TOKEN" + fi + } + + delete_asset_if_exists "$RELEASE_ARCHIVE" + delete_asset_if_exists "$RELEASE_SHA256" + curl -fsS -X POST "$upload_url?name=$RELEASE_ARCHIVE" \ -H "Authorization: token $GITEA_TOKEN" \ -F "attachment=@$RELEASE_ARCHIVE" diff --git a/src/commands/update.rs b/src/commands/update.rs index 169c4b1..a6a988d 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -116,17 +116,16 @@ fn update(force: bool) -> Result { curl -fsSL {} -o \"$tmp/openstock.tar.gz\"\n\ tar -xzf \"$tmp/openstock.tar.gz\" -C \"$tmp\"\n\ test -x \"$tmp/openstock\"\n\ - mkdir -p {}\n\ - target={}\n\ - tmp_target=\"{}/.openstock.tmp.$$\"\n\ + install_dir={}\n\ + mkdir -p \"$install_dir\"\n\ + target=\"$install_dir/openstock\"\n\ + tmp_target=\"$install_dir/.openstock.tmp.$$\"\n\ cp \"$tmp/openstock\" \"$tmp_target\"\n\ chmod 755 \"$tmp_target\"\n\ mv -f \"$tmp_target\" \"$target\"\n\ printf 'installed: %s\\n' \"$target\"\n", shell_quote(&asset.browser_download_url), shell_quote(&install_dir.display().to_string()), - shell_quote(&install_dir.join("openstock").display().to_string()), - shell_quote(&install_dir.display().to_string()), ); let output = Command::new("sh") .arg("-c")