98 lines
3.1 KiB
YAML
98 lines
3.1 KiB
YAML
name: Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
|
|
env:
|
|
BINARY_NAME: email-mcp
|
|
BUILD_PATH: build/email-mcp-linux-amd64
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go.mod
|
|
|
|
- name: Build linux amd64 binary
|
|
run: make build GOOS=linux GOARCH=amd64
|
|
|
|
- name: Create or fetch release
|
|
id: release
|
|
env:
|
|
TAG_NAME: ${{ github.ref_name }}
|
|
REPOSITORY: ${{ github.repository }}
|
|
API_URL: ${{ github.api_url }}
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
if [ -z "${TAG_NAME}" ]; then
|
|
echo "missing tag name" >&2
|
|
exit 1
|
|
fi
|
|
|
|
owner="${REPOSITORY%%/*}"
|
|
repo="${REPOSITORY#*/}"
|
|
release_url="${API_URL}/repos/${owner}/${repo}/releases/tags/${TAG_NAME}"
|
|
create_url="${API_URL}/repos/${owner}/${repo}/releases"
|
|
|
|
http_code="$(curl -sS -o release.json -w '%{http_code}' \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
"${release_url}")"
|
|
|
|
if [ "${http_code}" = "404" ]; then
|
|
payload="$(printf '{"tag_name":"%s","name":"%s","prerelease":false,"draft":false}' "${TAG_NAME}" "${TAG_NAME}")"
|
|
http_code="$(curl -sS -o release.json -w '%{http_code}' \
|
|
-X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "${payload}" \
|
|
"${create_url}")"
|
|
fi
|
|
|
|
if [ "${http_code}" -lt 200 ] || [ "${http_code}" -ge 300 ]; then
|
|
echo "release API call failed with status ${http_code}" >&2
|
|
cat release.json >&2
|
|
exit 1
|
|
fi
|
|
|
|
release_id="$(python3 -c 'import json; print(json.load(open("release.json", "r", encoding="utf-8"))["id"])')"
|
|
|
|
echo "release_id=${release_id}" >> "${GITHUB_OUTPUT}"
|
|
|
|
- name: Upload release asset
|
|
env:
|
|
REPOSITORY: ${{ github.repository }}
|
|
API_URL: ${{ github.api_url }}
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
RELEASE_ID: ${{ steps.release.outputs.release_id }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
owner="${REPOSITORY%%/*}"
|
|
repo="${REPOSITORY#*/}"
|
|
asset_name="$(basename "${BUILD_PATH}")"
|
|
upload_url="${API_URL}/repos/${owner}/${repo}/releases/${RELEASE_ID}/assets?name=${asset_name}"
|
|
|
|
http_code="$(curl -sS -o asset.json -w '%{http_code}' \
|
|
-X POST \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary @"${BUILD_PATH}" \
|
|
"${upload_url}")"
|
|
|
|
if [ "${http_code}" -lt 200 ] || [ "${http_code}" -ge 300 ]; then
|
|
echo "asset upload failed with status ${http_code}" >&2
|
|
cat asset.json >&2
|
|
exit 1
|
|
fi
|