Compare commits
6
Commits
72fd363600
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
570ed2183b | ||
|
|
d7a74a6971 | ||
|
|
18963ae03b | ||
|
|
f8c186fe2c | ||
|
|
d40d19ae96 | ||
|
|
ac17a954b0 |
Executable
+52
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# create-release.sh — create a Gitea release and attach dist/ assets.
|
||||||
|
#
|
||||||
|
# Required env vars (set by the workflow):
|
||||||
|
# GITEA_TOKEN Gitea API token with release write scope
|
||||||
|
# TAG_NAME tag name (e.g. v0.0.1-beta)
|
||||||
|
# API_URL Gitea API base URL (e.g. http://gitea.local/api/v1)
|
||||||
|
# REPOSITORY owner/repo
|
||||||
|
# SHA commit SHA the tag points at
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
PAYLOAD=$(cat <<EOF
|
||||||
|
{
|
||||||
|
"tag_name": "${TAG_NAME}",
|
||||||
|
"target_commitish": "${SHA}",
|
||||||
|
"name": "Release ${TAG_NAME}",
|
||||||
|
"body": "Auto-generated release assets.",
|
||||||
|
"draft": false,
|
||||||
|
"prerelease": false
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
echo "Creating Gitea release for tag ${TAG_NAME}..."
|
||||||
|
|
||||||
|
RELEASE_RESPONSE=$(curl -fsS -X POST "${API_URL}/repos/${REPOSITORY}/releases" \
|
||||||
|
-H "accept: application/json" \
|
||||||
|
-H "authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "${PAYLOAD}")
|
||||||
|
|
||||||
|
RELEASE_ID=$(printf '%s' "${RELEASE_RESPONSE}" | grep -oP '"id":\s*\K[0-9]+' | head -n 1)
|
||||||
|
if [ -z "${RELEASE_ID}" ]; then
|
||||||
|
echo "ERROR: failed to create release. Response:"
|
||||||
|
echo "${RELEASE_RESPONSE}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Release created with ID ${RELEASE_ID}"
|
||||||
|
|
||||||
|
for asset in dist/snapshot-*.whl dist/snapshot-*.tar.gz; do
|
||||||
|
if [ -f "${asset}" ]; then
|
||||||
|
echo "Uploading ${asset}..."
|
||||||
|
curl -fsS -X POST "${API_URL}/repos/${REPOSITORY}/releases/${RELEASE_ID}/assets" \
|
||||||
|
-H "accept: application/json" \
|
||||||
|
-H "authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-F "attachment=@${asset}"
|
||||||
|
echo
|
||||||
|
else
|
||||||
|
echo "Skipping ${asset} (not found)"
|
||||||
|
fi
|
||||||
|
done
|
||||||
+27
-59
@@ -2,83 +2,51 @@ name: CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
# branches:
|
||||||
- main
|
# - main
|
||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- 'v*'
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
ci:
|
ci:
|
||||||
name: CI
|
name: CI
|
||||||
# `astral-uv` is a self-hosted runner with uv pre-installed, so we can
|
# Standard GitHub-hosted ubuntu runner. uv is installed via the
|
||||||
# skip the setup-uv step entirely. pyproject.toml's
|
# astral-sh/setup-uv action (one extra step vs. using a self-hosted
|
||||||
# [tool.hatch.build.hooks.jupyter-builder] handles jlpm install +
|
# runner with uv pre-installed, but matches what GitHub-hosted CI
|
||||||
# jlpm build:prod before wheel assembly.
|
# provides out of the box).
|
||||||
runs-on: astral-uv
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Build package
|
- name: Set up uv
|
||||||
run: uv build
|
uses: https://github.com/astral-sh/setup-uv@v6
|
||||||
|
|
||||||
- name: Upload wheel artifacts
|
|
||||||
if: success()
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
with:
|
||||||
name: snapshot-dist
|
enable-cache: true
|
||||||
path: dist/snapshot-*
|
|
||||||
if-no-files-found: error
|
- name: Build package
|
||||||
|
env:
|
||||||
|
# Use the Tsinghua PyPI mirror for build-environment resolution;
|
||||||
|
# the runner is in China and the default pypi.org is too slow
|
||||||
|
# / unreliable for build dependency install.
|
||||||
|
UV_DEFAULT_INDEX: "https://pypi.tuna.tsinghua.edu.cn/simple/"
|
||||||
|
run: uv build
|
||||||
|
|
||||||
# Only create a release + attach dist/ assets when pushing a v* tag.
|
# Only create a release + attach dist/ assets when pushing a v* tag.
|
||||||
# On branch pushes / pull requests this step is skipped entirely.
|
# On branch pushes / pull requests this step is skipped entirely.
|
||||||
|
# The release logic is in a separate script to avoid embedding a JSON
|
||||||
|
# heredoc inside a YAML block scalar (the previous version of this
|
||||||
|
# step was rejected by Gitea's YAML parser at line 51).
|
||||||
- name: Upload release assets via Gitea API
|
- name: Upload release assets via Gitea API
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
TAG_NAME: ${{ github.ref_name }}
|
||||||
set -euo pipefail
|
API_URL: ${{ github.api_url }}
|
||||||
TAG_NAME="${{ github.ref_name }}"
|
REPOSITORY: ${{ github.repository }}
|
||||||
|
SHA: ${{ github.sha }}
|
||||||
echo "Creating Gitea release for tag ${TAG_NAME}..."
|
run: ./.github/scripts/create-release.sh
|
||||||
|
|
||||||
RELEASE_RESPONSE=$(curl -fsS -X POST "${{ github.api_url }}/repos/${{ github.repository }}/releases" \
|
|
||||||
-H "accept: application/json" \
|
|
||||||
-H "authorization: token ${GITEA_TOKEN}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "$(cat <<EOF
|
|
||||||
{
|
|
||||||
"tag_name": "${TAG_NAME}",
|
|
||||||
"target_commitish": "${{ github.sha }}",
|
|
||||||
"name": "Release ${TAG_NAME}",
|
|
||||||
"body": "Auto-generated release assets.",
|
|
||||||
"draft": false,
|
|
||||||
"prerelease": false
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
)")
|
|
||||||
|
|
||||||
RELEASE_ID=$(printf '%s' "${RELEASE_RESPONSE}" | grep -oP '"id":\s*\K[0-9]+' | head -n 1)
|
|
||||||
if [ -z "${RELEASE_ID}" ]; then
|
|
||||||
echo "ERROR: failed to create release. Response:"
|
|
||||||
echo "${RELEASE_RESPONSE}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "Release created with ID ${RELEASE_ID}"
|
|
||||||
|
|
||||||
for asset in dist/snapshot-*.whl dist/snapshot-*.tar.gz; do
|
|
||||||
if [ -f "${asset}" ]; then
|
|
||||||
echo "Uploading ${asset}..."
|
|
||||||
curl -fsS -X POST "${{ github.api_url }}/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
|
|
||||||
-H "accept: application/json" \
|
|
||||||
-H "authorization: token ${GITEA_TOKEN}" \
|
|
||||||
-F "attachment=@${asset}"
|
|
||||||
echo
|
|
||||||
else
|
|
||||||
echo "Skipping ${asset} (not found)"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Always run, regardless of job status. The script is a side-effect;
|
# Always run, regardless of job status. The script is a side-effect;
|
||||||
# if the notification itself fails we swallow the error so CI does
|
# if the notification itself fails we swallow the error so CI does
|
||||||
|
|||||||
Reference in New Issue
Block a user