Compare commits
7 Commits
d319087c44
...
release
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2768eb39de | ||
|
|
30f2b4f810 | ||
|
|
f47a203a80 | ||
|
|
1ed9829f58 | ||
|
|
e836809fc0 | ||
|
|
3b24386dd0 | ||
|
|
e356f50927 |
26
.gitea/workflows/ci.yml
Normal file
26
.gitea/workflows/ci.yml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "22"
|
||||||
|
cache: "npm"
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: npm run build
|
||||||
@@ -8,6 +8,10 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
if: startsWith(gitea.ref, 'refs/tags/v')
|
||||||
|
outputs:
|
||||||
|
version: ${{ steps.version.outputs.version }}
|
||||||
|
tag: ${{ steps.version.outputs.tag }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
@@ -16,7 +20,7 @@ jobs:
|
|||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: "20"
|
node-version: "22"
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
@@ -27,19 +31,147 @@ jobs:
|
|||||||
|
|
||||||
- name: Get version
|
- name: Get version
|
||||||
id: version
|
id: version
|
||||||
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Create release and upload assets
|
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
GITEA_REF: ${{ gitea.ref }}
|
||||||
run: |
|
run: |
|
||||||
VERSION="${{ steps.version.outputs.version }}"
|
echo "version=${GITEA_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
||||||
TAG="${GITHUB_REF#refs/tags/}"
|
echo "tag=${GITEA_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||||
REPO="${GITHUB_REPOSITORY}"
|
|
||||||
SERVER_URL="${GITHUB_SERVER_URL}"
|
|
||||||
API_URL="${SERVER_URL}/api/v1"
|
|
||||||
|
|
||||||
# Create the release
|
- name: Upload build artifacts
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: build-output
|
||||||
|
path: .scaffold/build/
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
|
update-rolling-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download build artifacts
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: build-output
|
||||||
|
path: .scaffold/build/
|
||||||
|
|
||||||
|
- name: Upsert rolling 'release' tag with latest update.json
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ gitea.token }}
|
||||||
|
API_URL: ${{ gitea.server_url }}/api/v1
|
||||||
|
REPO: ${{ gitea.repository }}
|
||||||
|
VERSION: ${{ needs.build.outputs.version }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
TAG="release"
|
||||||
|
|
||||||
|
echo "=== Configuration ==="
|
||||||
|
echo "API_URL: ${API_URL}"
|
||||||
|
echo "REPO: ${REPO}"
|
||||||
|
echo "VERSION: ${VERSION}"
|
||||||
|
|
||||||
|
# Check if the rolling release already exists
|
||||||
|
EXISTING=$(curl -s -o /dev/null -w "%{http_code}" \
|
||||||
|
"${API_URL}/repos/${REPO}/releases/tags/${TAG}" \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}")
|
||||||
|
|
||||||
|
echo "Existing release check: HTTP ${EXISTING}"
|
||||||
|
|
||||||
|
if [ "${EXISTING}" = "200" ]; then
|
||||||
|
# Fetch the release ID
|
||||||
|
RELEASE_ID=$(curl -s "${API_URL}/repos/${REPO}/releases/tags/${TAG}" \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
| jq -r '.id')
|
||||||
|
|
||||||
|
echo "Found existing 'release' release (ID: ${RELEASE_ID}). Replacing assets..."
|
||||||
|
|
||||||
|
# Delete all existing assets so we can upload fresh ones
|
||||||
|
ASSETS=$(curl -s "${API_URL}/repos/${REPO}/releases/${RELEASE_ID}/assets" \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}")
|
||||||
|
echo "${ASSETS}" | jq -r '.[].id' | while read -r ASSET_ID; do
|
||||||
|
echo "Deleting asset ${ASSET_ID}..."
|
||||||
|
curl -s -X DELETE "${API_URL}/repos/${REPO}/releases/${RELEASE_ID}/assets/${ASSET_ID}" \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Update the release body to reflect the current version
|
||||||
|
curl -s -X PATCH "${API_URL}/repos/${REPO}/releases/${RELEASE_ID}" \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"body\": \"Rolling release — always points to the latest update manifest (currently v${VERSION}). Do not delete.\"}"
|
||||||
|
|
||||||
|
else
|
||||||
|
# Create the rolling release for the first time
|
||||||
|
echo "Creating new 'release' release..."
|
||||||
|
|
||||||
|
# Ensure the tag exists (Gitea requires the tag to exist before creating a release for it)
|
||||||
|
curl -s -X POST "${API_URL}/repos/${REPO}/tags" \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"tag_name\": \"${TAG}\", \"target\": \"main\"}" || true
|
||||||
|
|
||||||
|
RELEASE=$(curl -s -X POST "${API_URL}/repos/${REPO}/releases" \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{
|
||||||
|
\"tag_name\": \"${TAG}\",
|
||||||
|
\"name\": \"Update Manifest (rolling)\",
|
||||||
|
\"body\": \"Rolling release — always points to the latest update manifest (currently v${VERSION}). Do not delete.\",
|
||||||
|
\"draft\": false,
|
||||||
|
\"prerelease\": false
|
||||||
|
}")
|
||||||
|
|
||||||
|
RELEASE_ID=$(echo "${RELEASE}" | jq -r '.id')
|
||||||
|
|
||||||
|
if [ -z "${RELEASE_ID}" ] || [ "${RELEASE_ID}" = "null" ]; then
|
||||||
|
echo "Failed to create rolling release. Response: ${RELEASE}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Created rolling release ID: ${RELEASE_ID}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Upload update.json and update-beta.json to the rolling release
|
||||||
|
for JSON in .scaffold/build/update.json .scaffold/build/update-beta.json; do
|
||||||
|
[ -f "${JSON}" ] || continue
|
||||||
|
FILENAME=$(basename "${JSON}")
|
||||||
|
echo "Uploading ${FILENAME} to rolling release..."
|
||||||
|
curl -s -X POST "${API_URL}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}" \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
--data-binary "@${JSON}"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Rolling 'release' release updated to v${VERSION}."
|
||||||
|
|
||||||
|
publish-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [build, update-rolling-release]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download build artifacts
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: build-output
|
||||||
|
path: .scaffold/build/
|
||||||
|
|
||||||
|
- name: Create versioned release and upload assets
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ gitea.token }}
|
||||||
|
API_URL: ${{ gitea.server_url }}/api/v1
|
||||||
|
REPO: ${{ gitea.repository }}
|
||||||
|
VERSION: ${{ needs.build.outputs.version }}
|
||||||
|
TAG: ${{ needs.build.outputs.tag }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
echo "=== Configuration ==="
|
||||||
|
echo "API_URL: ${API_URL}"
|
||||||
|
echo "REPO: ${REPO}"
|
||||||
|
echo "VERSION: ${VERSION}"
|
||||||
|
echo "TAG: ${TAG}"
|
||||||
|
|
||||||
|
# Create the versioned release
|
||||||
RELEASE=$(curl -s -X POST "${API_URL}/repos/${REPO}/releases" \
|
RELEASE=$(curl -s -X POST "${API_URL}/repos/${REPO}/releases" \
|
||||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
@@ -51,16 +183,16 @@ jobs:
|
|||||||
\"prerelease\": false
|
\"prerelease\": false
|
||||||
}")
|
}")
|
||||||
|
|
||||||
RELEASE_ID=$(echo "${RELEASE}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
RELEASE_ID=$(echo "${RELEASE}" | jq -r '.id')
|
||||||
|
|
||||||
if [ -z "${RELEASE_ID}" ]; then
|
if [ -z "${RELEASE_ID}" ] || [ "${RELEASE_ID}" = "null" ]; then
|
||||||
echo "Failed to create release. Response: ${RELEASE}"
|
echo "Failed to create release. Response: ${RELEASE}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Created release ID: ${RELEASE_ID}"
|
echo "Created release ID: ${RELEASE_ID}"
|
||||||
|
|
||||||
# Upload all XPI files
|
# Upload XPI
|
||||||
for XPI in .scaffold/build/*.xpi; do
|
for XPI in .scaffold/build/*.xpi; do
|
||||||
[ -f "${XPI}" ] || continue
|
[ -f "${XPI}" ] || continue
|
||||||
FILENAME=$(basename "${XPI}")
|
FILENAME=$(basename "${XPI}")
|
||||||
@@ -71,7 +203,7 @@ jobs:
|
|||||||
--data-binary "@${XPI}"
|
--data-binary "@${XPI}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Upload update manifests if present
|
# Upload update manifests
|
||||||
for JSON in .scaffold/build/update.json .scaffold/build/update-beta.json; do
|
for JSON in .scaffold/build/update.json .scaffold/build/update-beta.json; do
|
||||||
[ -f "${JSON}" ] || continue
|
[ -f "${JSON}" ] || continue
|
||||||
FILENAME=$(basename "${JSON}")
|
FILENAME=$(basename "${JSON}")
|
||||||
@@ -82,4 +214,4 @@ jobs:
|
|||||||
--data-binary "@${JSON}"
|
--data-binary "@${JSON}"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Release ${TAG} published successfully."
|
echo "Versioned release ${TAG} published."
|
||||||
|
|||||||
@@ -17,7 +17,8 @@
|
|||||||
"lint": "eslint src",
|
"lint": "eslint src",
|
||||||
"lint:fix": "eslint src --fix",
|
"lint:fix": "eslint src --fix",
|
||||||
"format": "prettier --write \"src/**/*.ts\" \"addon/**/*.js\"",
|
"format": "prettier --write \"src/**/*.ts\" \"addon/**/*.js\"",
|
||||||
"format:check": "prettier --check \"src/**/*.ts\" \"addon/**/*.js\""
|
"format:check": "prettier --check \"src/**/*.ts\" \"addon/**/*.js\"",
|
||||||
|
"postinstall": "node scripts/patch-scaffold.mjs"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
45
scripts/patch-scaffold.mjs
Normal file
45
scripts/patch-scaffold.mjs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/**
|
||||||
|
* Patches zotero-plugin-scaffold's parseRepoUrl to accept non-.com domains.
|
||||||
|
*
|
||||||
|
* The upstream regex hardcodes `.com` in the URL pattern, which breaks builds
|
||||||
|
* when the repository is hosted on a self-hosted Gitea instance (any other TLD).
|
||||||
|
* This script runs automatically via the `postinstall` npm hook after every
|
||||||
|
* `npm install` / `npm ci`.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { readFileSync, writeFileSync } from "fs";
|
||||||
|
import { resolve, dirname } from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const target = resolve(
|
||||||
|
__dirname,
|
||||||
|
"../node_modules/zotero-plugin-scaffold/dist/shared/zotero-plugin-scaffold.Lk5EW_9z.mjs"
|
||||||
|
);
|
||||||
|
|
||||||
|
let content;
|
||||||
|
try {
|
||||||
|
content = readFileSync(target, "utf8");
|
||||||
|
} catch {
|
||||||
|
console.warn("[patch-scaffold] Target file not found, skipping patch.");
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Original: matches only .com hosts
|
||||||
|
// /:\/\/.+com\/([^/]+)\/([^.]+)\.git$/
|
||||||
|
// Replacement: matches any host and makes .git suffix optional
|
||||||
|
// /:\/\/.+?\/([^/]+)\/([^/.]+)(?:\.git)?$/
|
||||||
|
const SEARCH = String.raw`url.match(/:\/\/.+com\/([^/]+)\/([^.]+)\.git$/)`;
|
||||||
|
const REPLACE = String.raw`url.match(/:\/\/.+?\/([^/]+)\/([^/.]+)(?:\.git)?$/)`;
|
||||||
|
|
||||||
|
if (content.includes(SEARCH)) {
|
||||||
|
writeFileSync(target, content.replace(SEARCH, REPLACE), "utf8");
|
||||||
|
console.log("[patch-scaffold] Applied: parseRepoUrl now accepts any TLD.");
|
||||||
|
} else if (content.includes(REPLACE)) {
|
||||||
|
console.log("[patch-scaffold] Already patched, nothing to do.");
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
"[patch-scaffold] Could not find target string — scaffold may have been updated. " +
|
||||||
|
"Check scripts/patch-scaffold.mjs and update SEARCH/REPLACE strings."
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
import { defineConfig } from "zotero-plugin-scaffold";
|
import { defineConfig } from "zotero-plugin-scaffold";
|
||||||
import pkg from "./package.json";
|
import pkg from "./package.json";
|
||||||
|
|
||||||
|
const GITEA_BASE = "https://gitea.bueso.eu/ignacio.ballesteros/zotero-notes-export-org";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
source: ["src", "addon"],
|
source: ["src", "addon"],
|
||||||
dist: ".scaffold/build",
|
dist: ".scaffold/build",
|
||||||
name: pkg.config.addonName,
|
name: pkg.config.addonName,
|
||||||
id: pkg.config.addonID,
|
id: pkg.config.addonID,
|
||||||
namespace: pkg.config.addonRef,
|
namespace: pkg.config.addonRef,
|
||||||
|
// Explicit URLs are required because zotero-plugin-scaffold's URL parser
|
||||||
|
// only handles .com domains and cannot parse our self-hosted Gitea instance.
|
||||||
|
xpiDownloadLink: `${GITEA_BASE}/releases/download/v{{version}}/{{xpiName}}.xpi`,
|
||||||
|
updateURL: `${GITEA_BASE}/releases/download/release/{{updateJson}}`,
|
||||||
build: {
|
build: {
|
||||||
esbuildOptions: [
|
esbuildOptions: [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user