refactor: Use environment variables for upload script authentication
Some checks are pending
Tests & Quality Checks / Test on Python 3.11 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.11-1 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12-1 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.10 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.11-2 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12-2 (push) Waiting to run
Tests & Quality Checks / Build Artifacts (push) Blocked by required conditions
Tests & Quality Checks / Build Artifacts-1 (push) Blocked by required conditions

- Add FORGEJO_TOKEN environment variable support to both upload scripts
- Windows: Add Credential Manager storage via -SaveToken flag
- macOS: Add config file storage via --save-token flag
- Scripts now check: parameter -> env var -> credential manager/config
- Update FORGEJO_PACKAGES_SETUP.md with all authentication methods
- Token is now optional - scripts find it automatically
- Matches git authentication workflow
This commit is contained in:
claudi 2026-01-28 14:29:35 +01:00
parent 7bf3a86f5c
commit 1b37335f8a
3 changed files with 220 additions and 41 deletions

View file

@ -1,6 +1,8 @@
#!/bin/bash
# Upload macOS Build to Forgejo Packages
# Usage: ./upload_to_packages.sh -v 1.0.0 -t $token
# Usage: ./upload_to_packages.sh -v 1.0.0
# Set token via: export FORGEJO_TOKEN="your_token"
# Or store in config: ./upload_to_packages.sh --save-token -t "your_token"
set -e
@ -11,19 +13,65 @@ FORGEJO_URL="https://git.him-tools.de"
REPO="HIM-public/webdrop-bridge"
DMG_PATH="build/dist/macos/WebDropBridge.dmg"
CHECKSUM_PATH="build/dist/macos/WebDropBridge.dmg.sha256"
SAVE_TOKEN=false
while [[ $# -gt 0 ]]; do
case $1 in
-v|--version) VERSION="$2"; shift 2;;
-t|--token) FORGEJO_TOKEN="$2"; shift 2;;
-u|--url) FORGEJO_URL="$2"; shift 2;;
--save-token) SAVE_TOKEN=true; shift;;
*) echo "Unknown option: $1"; exit 1;;
esac
done
if [ -z "$VERSION" ] || [ -z "$FORGEJO_TOKEN" ]; then
echo "Usage: $0 -v VERSION -t TOKEN [-u FORGEJO_URL]"
echo "Example: $0 -v 1.0.0 -t your_token_here"
# Load token from environment or .env file
if [ -z "$FORGEJO_TOKEN" ]; then
# Check if .env file exists in project root
if [ -f ".env" ]; then
export $(grep "FORGEJO_TOKEN" .env | xargs)
fi
# Check if saved in home config
if [ -z "$FORGEJO_TOKEN" ] && [ -f "$HOME/.config/webdrop-bridge/.env" ]; then
export $(grep "FORGEJO_TOKEN" "$HOME/.config/webdrop-bridge/.env" | xargs)
fi
fi
# Handle --save-token flag
if [ "$SAVE_TOKEN" = true ]; then
if [ -z "$FORGEJO_TOKEN" ]; then
read -sp "Enter Forgejo token to save: " FORGEJO_TOKEN
echo ""
fi
mkdir -p "$HOME/.config/webdrop-bridge"
echo "FORGEJO_TOKEN=$FORGEJO_TOKEN" > "$HOME/.config/webdrop-bridge/.env"
chmod 600 "$HOME/.config/webdrop-bridge/.env"
echo "✓ Token saved to $HOME/.config/webdrop-bridge/.env"
exit 0
fi
# Verify required parameters
if [ -z "$VERSION" ]; then
echo "ERROR: Version parameter required" >&2
echo "Usage: $0 -v VERSION [-t TOKEN] [-u FORGEJO_URL]" >&2
echo "Example: $0 -v 1.0.0" >&2
echo "" >&2
echo "Token can be set via:" >&2
echo " 1. Environment: export FORGEJO_TOKEN='your_token'" >&2
echo " 2. .env file: FORGEJO_TOKEN=your_token (in project root)" >&2
echo " 3. Config: $0 --save-token -t 'your_token'" >&2
echo " 4. Parameter: -t 'your_token'" >&2
exit 1
fi
if [ -z "$FORGEJO_TOKEN" ]; then
echo "ERROR: Forgejo token not found!" >&2
echo "" >&2
echo "Set token using one of these methods:" >&2
echo " 1. Environment: export FORGEJO_TOKEN='your_token'" >&2
echo " 2. .env file: FORGEJO_TOKEN=your_token (in project root)" >&2
echo " 3. Config: $0 --save-token -t 'your_token'" >&2
echo " 4. Parameter: -t 'your_token'" >&2
exit 1
fi