84 lines
2.4 KiB
YAML
84 lines
2.4 KiB
YAML
name: release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: "Tag to release (e.g. v0.2.0)"
|
|
required: true
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: https://gitea.com/actions/checkout@v4
|
|
|
|
- name: Setup Node
|
|
uses: https://gitea.com/actions/setup-node@v4
|
|
with:
|
|
node-version: "20"
|
|
|
|
- name: Install dependencies
|
|
run: npm ci || npm install
|
|
|
|
- name: Test
|
|
run: npm test
|
|
|
|
- name: Build bundle
|
|
run: npm run build
|
|
|
|
- name: Stage release artifacts
|
|
run: |
|
|
mkdir -p release
|
|
cp dist/app.mjs release/app.mjs
|
|
cp scripts/install.sh release/install.sh
|
|
ls -lh release/
|
|
|
|
- name: Resolve tag
|
|
id: tag
|
|
run: |
|
|
if [ -n "${{ inputs.tag }}" ]; then
|
|
echo "name=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "name=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Publish Gitea Release
|
|
env:
|
|
TOKEN: ${{ secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN }}
|
|
TAG: ${{ steps.tag.outputs.name }}
|
|
run: |
|
|
set -eu
|
|
API="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases"
|
|
parse_id='let d="";process.stdin.on("data",c=>d+=c).on("end",()=>{try{process.stdout.write(String(JSON.parse(d).id||""))}catch(e){}})'
|
|
|
|
rid=$(curl -sS -X POST "$API" \
|
|
-H "Authorization: token $TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"draft\":false,\"prerelease\":false}" \
|
|
| node -e "$parse_id")
|
|
|
|
if [ -z "$rid" ]; then
|
|
echo "release may already exist, fetching by tag $TAG"
|
|
rid=$(curl -sS "$API/tags/$TAG" -H "Authorization: token $TOKEN" | node -e "$parse_id")
|
|
fi
|
|
|
|
if [ -z "$rid" ]; then
|
|
echo "failed to create or find release for $TAG" >&2
|
|
exit 1
|
|
fi
|
|
echo "release id=$rid"
|
|
|
|
for f in release/app.mjs release/install.sh; do
|
|
name=$(basename "$f")
|
|
echo "uploading $name"
|
|
curl -sS -X POST "$API/$rid/assets?name=$name" \
|
|
-H "Authorization: token $TOKEN" \
|
|
-F "attachment=@$f" \
|
|
-o /dev/null -w " -> HTTP %{http_code}\n"
|
|
done
|