diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml index b775bcd..de240dd 100644 --- a/.forgejo/workflows/release.yml +++ b/.forgejo/workflows/release.yml @@ -1,23 +1,79 @@ -name: Build Test 2 +name: Build and Release Ody Agent on: + push: + tags: + - 'v*' workflow_dispatch: + inputs: + version: + description: 'Version tag (e.g. v1.0.1)' + required: false + default: 'v1.0.1' jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-host steps: - - name: Checkout - run: git clone --depth=1 https://git.wellspr.ing/wellspring/ody-agent.git /build && ls /build - - - name: Install Go + - name: Prepare workspace run: | - curl -fsSL https://go.dev/dl/go1.22.3.linux-amd64.tar.gz -o /tmp/go.tar.gz - tar -C /usr/local -xzf /tmp/go.tar.gz - /usr/local/go/bin/go version + export PATH="/usr/local/go/bin:$PATH" + go version + rm -rf /tmp/ody-build && mkdir -p /tmp/ody-build/dist + git clone --depth=1 https://git.wellspr.ing/wellspring/ody-agent.git /tmp/ody-build/src + ls /tmp/ody-build/src - - name: Build Linux + - name: Build all platforms run: | - cd /build - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 /usr/local/go/bin/go build -o /tmp/ody-agent-linux . - ls -lh /tmp/ody-agent-linux + export PATH="/usr/local/go/bin:$PATH" + cd /tmp/ody-build/src + GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build \ + -ldflags "-s -w -H=windowsgui -X main.defaultServer=https://425.today" \ + -o /tmp/ody-build/dist/ody-agent-win.exe . + GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build \ + -ldflags "-s -w -X main.defaultServer=https://425.today" \ + -o /tmp/ody-build/dist/ody-agent-mac-arm64 . + GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build \ + -ldflags "-s -w -X main.defaultServer=https://425.today" \ + -o /tmp/ody-build/dist/ody-agent-mac-amd64 . + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build \ + -ldflags "-s -w -X main.defaultServer=https://425.today" \ + -o /tmp/ody-build/dist/ody-agent-linux . + echo "--- Built artifacts ---" + ls -lh /tmp/ody-build/dist/ + + - name: Publish Forgejo release + run: | + FORGEJO_URL="https://git.wellspr.ing" + REPO="wellspring/ody-agent" + if [ "$GITHUB_EVENT_NAME" = "push" ]; then + VERSION="${GITHUB_REF#refs/tags/}" + else + VERSION="v1.0.1" + fi + echo "Publishing release: $VERSION" + EXISTING_ID=$(curl -sf "$FORGEJO_URL/api/v1/repos/$REPO/releases/tags/$VERSION" \ + -H "Authorization: token $FORGEJO_RELEASE_TOKEN" 2>/dev/null \ + | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || echo "") + if [ -n "$EXISTING_ID" ]; then + curl -sf -X DELETE "$FORGEJO_URL/api/v1/repos/$REPO/releases/$EXISTING_ID" \ + -H "Authorization: token $FORGEJO_RELEASE_TOKEN" + echo "Deleted old release $EXISTING_ID" + fi + RELEASE=$(curl -sf -X POST "$FORGEJO_URL/api/v1/repos/$REPO/releases" \ + -H "Authorization: token $FORGEJO_RELEASE_TOKEN" \ + -H "Content-Type: application/json" \ + -d "{\"tag_name\":\"$VERSION\",\"name\":\"Ody Agent $VERSION\",\"body\":\"Desktop agent for WellSpr.ing merchants. Connects your local machine to your 425.today merchant inbox.\",\"draft\":false}") + RELEASE_ID=$(echo "$RELEASE" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])") + echo "Created release ID: $RELEASE_ID" + for f in /tmp/ody-build/dist/*; do + FNAME=$(basename "$f") + echo "Uploading $FNAME..." + curl -sf -X POST \ + "$FORGEJO_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets?name=$FNAME" \ + -H "Authorization: token $FORGEJO_RELEASE_TOKEN" \ + -H "Content-Type: application/octet-stream" \ + --data-binary "@$f" + echo "$FNAME done." + done + echo "Release live: $FORGEJO_URL/$REPO/releases/tag/$VERSION"