ci(gitea): релиз по тегу v* с main.js, manifest.json, styles.css
CI / Lint, Typecheck & Test (push) Successful in 2m46s
CI / Lint, Typecheck & Test (push) Successful in 2m46s
- workflows перенесены в .gitea/workflows (GitHub Actions на Gitea не исполнялись) - runs-on: native — host-mode раннер ci-sapphira; без setup-node/cache: npm, так как на хосте нет tar/zstd, node 24/npm 11 берутся из PATH раннера - ci.yml: push/PR в master/dev -> npm ci, lint, typecheck, test - release.yml: тег v* -> сборка, сверка тега с manifest.json/package.json, публикация релиза через Gitea API - scripts/publish-release.mjs: идемпотентная публикация трёх ассетов - добавлен npm run typecheck
This commit is contained in:
1 parent
7cc89afbf7
commit
b5618addb9
5 files changed
+213
-89
No files matched your search
@@ -0,0 +1,40 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- dev
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- dev
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
name: Lint, Typecheck & Test
|
||||
# Host-mode Gitea runner is registered with the single label "native".
|
||||
# It runs directly on the host: no Docker, no tar/zstd, no preinstalled
|
||||
# tool-cache. Use the host toolchain (node + npm) instead of setup-node.
|
||||
runs-on: native
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Toolchain
|
||||
run: node -v && npm -v
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci --no-audit --no-fund
|
||||
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
|
||||
- name: Typecheck
|
||||
run: npm run typecheck
|
||||
|
||||
- name: Test
|
||||
run: npm test
|
||||
@@ -0,0 +1,52 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Build & Publish
|
||||
# Host-mode runner: label "native", host toolchain only (see ci.yml).
|
||||
runs-on: native
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Toolchain
|
||||
run: node -v && npm -v
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci --no-audit --no-fund
|
||||
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
|
||||
- name: Typecheck
|
||||
run: npm run typecheck
|
||||
|
||||
- name: Test
|
||||
run: npm test
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Verify tag matches manifest.json and package.json
|
||||
run: |
|
||||
tag="${GITHUB_REF_NAME#v}"
|
||||
manifest="$(node -p "require('./manifest.json').version")"
|
||||
pkg="$(node -p "require('./package.json').version")"
|
||||
if [ "$tag" != "$manifest" ] || [ "$tag" != "$pkg" ]; then
|
||||
echo "::error::Tag $tag does not match manifest.json ($manifest) / package.json ($pkg)"
|
||||
exit 1
|
||||
fi
|
||||
echo "Version match: $tag"
|
||||
|
||||
- name: Publish release (main.js, manifest.json, styles.css)
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: node scripts/publish-release.mjs
|
||||
@@ -1,34 +0,0 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- dev
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- dev
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
name: Lint & Test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
|
||||
- name: Test
|
||||
run: npm test
|
||||
@@ -1,55 +0,0 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Lint, Test, Build & Release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
|
||||
- name: Test
|
||||
run: npm test
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Verify tag version matches manifest
|
||||
run: |
|
||||
TAG_VERSION="${GITHUB_REF_NAME#v}"
|
||||
MANIFEST_VERSION=$(node -p "require('./manifest.json').version")
|
||||
if [ "$TAG_VERSION" != "$MANIFEST_VERSION" ]; then
|
||||
echo "::error::Tag version ($TAG_VERSION) does not match manifest.json version ($MANIFEST_VERSION)"
|
||||
exit 1
|
||||
fi
|
||||
echo "✅ Version match: $TAG_VERSION"
|
||||
|
||||
- name: Create GitHub Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
name: ${{ github.ref_name }}
|
||||
generate_release_notes: true
|
||||
files: |
|
||||
main.js
|
||||
manifest.json
|
||||
styles.css
|
||||
Executable
+121
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env node
|
||||
// Publish a Gitea release for the current tag and attach the plugin bundle.
|
||||
//
|
||||
// Required environment (set by Gitea Actions):
|
||||
// GITHUB_SERVER_URL e.g. https://git.example.com
|
||||
// GITHUB_REPOSITORY e.g. owner/repo
|
||||
// GITHUB_REF_NAME tag name, e.g. v1.1.6
|
||||
// GITEA_TOKEN job token (${{ secrets.GITEA_TOKEN }}), needs contents: write
|
||||
//
|
||||
// The run is idempotent: an existing release for the tag is reused and assets
|
||||
// with the same names are replaced instead of duplicated.
|
||||
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
const ASSETS = ['main.js', 'manifest.json', 'styles.css'];
|
||||
|
||||
const server = required('GITHUB_SERVER_URL').replace(/\/+$/, '');
|
||||
const repository = required('GITHUB_REPOSITORY');
|
||||
const tag = required('GITHUB_REF_NAME');
|
||||
const token = required('GITEA_TOKEN');
|
||||
const api = `${server}/api/v1/repos/${repository}`;
|
||||
|
||||
async function request(method, path, body, headers = {}) {
|
||||
const response = await fetch(`${api}${path}`, {
|
||||
method,
|
||||
headers: { Authorization: `token ${token}`, ...headers },
|
||||
body,
|
||||
});
|
||||
const text = await response.text();
|
||||
return { status: response.status, text };
|
||||
}
|
||||
|
||||
function parse(text) {
|
||||
return text ? JSON.parse(text) : {};
|
||||
}
|
||||
|
||||
function fail(message) {
|
||||
console.error(`::error::${message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function required(name) {
|
||||
const value = process.env[name];
|
||||
if (!value) fail(`missing environment variable ${name}`);
|
||||
return value;
|
||||
}
|
||||
|
||||
// Gitea expects the file as multipart form-data (`attachment`); `name` in the
|
||||
// query string sets the asset name explicitly.
|
||||
function toFormData(name, data) {
|
||||
const form = new FormData();
|
||||
form.append('attachment', new Blob([data], { type: 'application/octet-stream' }), name);
|
||||
return form;
|
||||
}
|
||||
|
||||
async function ensureRelease() {
|
||||
const found = await request('GET', `/releases/tags/${encodeURIComponent(tag)}`);
|
||||
if (found.status === 200) {
|
||||
const release = parse(found.text);
|
||||
console.log(`release ${tag} already exists (id ${release.id})`);
|
||||
return release;
|
||||
}
|
||||
|
||||
const payload = JSON.stringify({
|
||||
tag_name: tag,
|
||||
name: tag,
|
||||
body: `Release ${tag}`,
|
||||
});
|
||||
const created = await request('POST', '/releases', payload, {
|
||||
'Content-Type': 'application/json',
|
||||
});
|
||||
if (created.status !== 201) {
|
||||
fail(`creating release ${tag} failed: HTTP ${created.status} ${created.text}`);
|
||||
}
|
||||
const release = parse(created.text);
|
||||
console.log(`release ${tag} created (id ${release.id})`);
|
||||
return release;
|
||||
}
|
||||
|
||||
async function existingAssets(releaseId) {
|
||||
const response = await request('GET', `/releases/${releaseId}/assets`);
|
||||
if (response.status !== 200) {
|
||||
fail(`listing assets failed: HTTP ${response.status} ${response.text}`);
|
||||
}
|
||||
return new Map(parse(response.text).map((asset) => [asset.name, asset.id]));
|
||||
}
|
||||
|
||||
async function replaceAsset(releaseId, name, assets) {
|
||||
let data;
|
||||
try {
|
||||
data = await readFile(name);
|
||||
} catch {
|
||||
fail(`asset ${name} is missing — did the build run?`);
|
||||
}
|
||||
if (data.length === 0) fail(`asset ${name} is empty`);
|
||||
|
||||
const previous = assets.get(name);
|
||||
if (previous !== undefined) {
|
||||
const removed = await request('DELETE', `/releases/${releaseId}/assets/${previous}`);
|
||||
if (removed.status !== 204 && removed.status !== 200) {
|
||||
fail(`removing old ${name} failed: HTTP ${removed.status} ${removed.text}`);
|
||||
}
|
||||
}
|
||||
|
||||
const uploaded = await request(
|
||||
'POST',
|
||||
`/releases/${releaseId}/assets?name=${encodeURIComponent(name)}`,
|
||||
toFormData(name, data),
|
||||
);
|
||||
if (uploaded.status !== 201) {
|
||||
fail(`uploading ${name} failed: HTTP ${uploaded.status} ${uploaded.text}`);
|
||||
}
|
||||
console.log(`uploaded ${name} (${data.length} bytes)`);
|
||||
}
|
||||
|
||||
const release = await ensureRelease();
|
||||
const assets = await existingAssets(release.id);
|
||||
for (const name of ASSETS) {
|
||||
await replaceAsset(release.id, name, assets);
|
||||
}
|
||||
console.log(`release ${tag} published with ${ASSETS.join(', ')}`);
|
||||
Reference in new issue
Block a user