Skip to content

Commit

Permalink
feat: release for different gitea versions (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
anbraten authored Nov 19, 2022
1 parent e2d7551 commit e625139
Show file tree
Hide file tree
Showing 10 changed files with 73,702 additions and 1,874 deletions.
26 changes: 12 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@ name: Release

on:
push:
branches:
- main
tags:
- '*'

jobs:
release:
name: Release
runs-on: ubuntu-latest
env:
GITEA_VERSION: ${{ github.ref_name }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- run: echo "Releasing version '${{github.ref_name}}' ..."

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
node-version: '18'

- name: Cache pnpm modules
uses: actions/cache@v2
Expand All @@ -30,26 +34,20 @@ jobs:
- uses: pnpm/[email protected]
with:
version: 6
version: 7
run_install: true

- name: Download Swagger Spec
run: pnpm run download

- name: Generate api
run: pnpm run generate:api

- name: Generate api docs
run: pnpm run generate:docs
- name: Generate api client & docs
run: pnpm generate

- name: Build
run: pnpm run build
run: pnpm build

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm run release
run: pnpm publish --no-git-checks

- name: Deploy 🚀
uses: JamesIves/[email protected]
Expand Down
64 changes: 18 additions & 46 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
env:
VERSION: latest
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -20,7 +22,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
node-version: '18'

- name: Cache pnpm modules
uses: actions/cache@v2
Expand All @@ -32,24 +34,22 @@ jobs:
- uses: pnpm/[email protected]
with:
version: 6
version: 7
run_install: true

- name: Generate api
run: pnpm generate:api
- name: Generate client
run: pnpm generate

- name: Unit test
env:
TEST_GITEA_TOKEN: ${{ secrets.TEST_GITEA_TOKEN }}
run: pnpm coverage

# - uses: artiomtr/[email protected]
# if: "github.event_name == 'pull_request'"
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# skip-step: all

typecheck:
name: Typecheck
runs-on: ubuntu-latest
env:
VERSION: latest
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -59,7 +59,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
node-version: '18'

- name: Cache pnpm modules
uses: actions/cache@v2
Expand All @@ -71,48 +71,20 @@ jobs:
- uses: pnpm/[email protected]
with:
version: 6
version: 7
run_install: true

- name: Generate api
run: pnpm generate:api
- name: Generate client
run: pnpm generate

- name: Typecheck
run: pnpm typecheck

# lint:
# name: Lint
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v2
# with:
# fetch-depth: 0

# - name: Setup Node.js
# uses: actions/setup-node@v2
# with:
# node-version: '14'

# - name: Cache pnpm modules
# uses: actions/cache@v2
# with:
# path: ~/.pnpm-store
# key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
# restore-keys: |
# ${{ runner.os }}-

# - uses: pnpm/[email protected]
# with:
# version: 6
# run_install: true

# - name: Lint
# run: pnpm run lint

check-format:
name: Check format
runs-on: ubuntu-latest
env:
VERSION: latest
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -122,7 +94,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
node-version: '18'

- name: Cache pnpm modules
uses: actions/cache@v2
Expand All @@ -134,7 +106,7 @@ jobs:
- uses: pnpm/[email protected]
with:
version: 6
version: 7
run_install: true

- name: Check format
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/anbraten/gitea-js/Release)](https://github.com/anbraten/gitea-js/actions)
[![Docs](https://img.shields.io/badge/Docs-up_to_date-brightgreen)](https://anbraten.github.io/gitea-js/)

Gitea-js is an api client created based on the official [swagger definition](https://gitea.com/swagger.v1.json) from Gitea. Generated client uses [Fetch Api](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) (native browser support) to make requests.
Gitea-js is an api client automatically created from the official [Open api definition](https://gitea.com/swagger.v1.json) of Gitea. The client uses the [Fetch Api](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) (native browser support) to make requests. For node you can use [cross-fetch](https://www.npmjs.com/package/cross-fetch) to polyfill the Fetch Api.

## Version mapping

The major and minor version of this library is mapped to the version of the Gitea api. The patch version of this library is incremented for every release and uses the latest patch version of Gitea.

| Gitea-js | Gitea |
| -------- | ---------- |
| 1.19.x | 1.19 (dev) |
| 1.18.x | 1.18 |
| 1.16.x | 1.17 |
| < 1.2.0 | 1.17 |

## Examples

Expand Down
63 changes: 63 additions & 0 deletions contrib/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { generateApi } from 'swagger-typescript-api';
import path from 'path';
import { exec as _exec } from 'child_process';
import fs from 'fs';

async function exec(cmd: string) {
return await new Promise<string>((resolve) => {
_exec(cmd, (err: any, stdout: any, stderr: any) => {
if (err) {
console.error(err);
return;
}
console.log(stdout);
resolve(stdout);
});
});
}

function getVersions(_version: string) {
if (!_version) {
throw new Error('version must be set');
}

if (_version === 'latest') {
const newestFile = fs.readdirSync(path.resolve(__dirname, '..', 'src', 'schemas')).sort().pop();
const giteaVersion = newestFile?.replace('v', '').replace('.json', '');

return {
version: `${giteaVersion}.0`,
giteaVersion,
};
}

const version = _version.replace(/^v/, '');
const [major, minor] = version.split('.');
const giteaVersion = `${major}.${minor}`;

return { version, giteaVersion };
}

async function run(_version: string) {
const { version, giteaVersion } = getVersions(_version);

console.log(`Generating gitea-js version "${version}" for Gitea "${giteaVersion}" ...`);

await generateApi({
name: 'api.ts',
output: path.resolve(__dirname, '..', 'src'),
input: path.resolve(__dirname, '..', 'src', 'schemas', `v${giteaVersion}.json`),
});

console.log(`Generating docs for ...`);

await exec(`typedoc src/index.ts`);

console.log(`Setting package.json version to "${version}" ...`);

await exec(`sed -i 's/0.0.0/${version}/g' package.json`);

console.log(`Done.`);
}

run(process.env.VERSION);
39 changes: 16 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gitea-js",
"version": "0.0.0-semantic-release",
"version": "0.0.0",
"homepage": "https://anbraten.github.io/gitea-js/",
"repository": "github:anbraten/gitea-js",
"author": "Anbraten",
Expand All @@ -18,34 +18,27 @@
"/dist"
],
"scripts": {
"download": "wget https://gitea.com/swagger.v1.json -O ./src/swagger.json",
"generate:api": "swagger-typescript-api -p https://gitea.com/swagger.v1.json -o ./src -n api.ts",
"generate:docs": "typedoc ./src/index.ts",
"generate": "pnpm generate:api && pnpm generate:docs",
"generate": "tsx contrib/generate.ts",
"build": "tsup src/index.ts --dts --format cjs,esm",
"all": "pnpm download && pnpm generate && pnpm build",
"clean": "rm -rf dist/ node_modules/",
"test": "dotenv vitest",
"test:ui": "pnpm test -- --ui",
"coverage": "pnpm test run -- --coverage",
"lint:format": "prettier --check .",
"typecheck": "tsc --noEmit",
"release": "semantic-release"
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@geprog/semantic-release-config": "1.0.0",
"@types/node": "17.0.13",
"@vitest/ui": "0.5.9",
"c8": "7.11.0",
"cross-fetch": "3.1.5",
"dotenv-cli": "5.0.0",
"prettier": "2.5.1",
"semantic-release": "19.0.2",
"swagger-typescript-api": "9.3.1",
"tsup": "5.11.13",
"typedoc": "0.22.11",
"typescript": "4.5.5",
"vite": "2.8.6",
"vitest": "0.5.9"
"@types/node": "^17.0.3",
"@vitest/ui": "^0.25.2",
"c8": "^7.12.0",
"cross-fetch": "^3.1.5",
"dotenv-cli": "^6.0.0",
"prettier": "^2.7.1",
"swagger-typescript-api": "^12.0.2",
"tsup": "^6.5.0",
"tsx": "^3.12.1",
"typedoc": "^0.23.21",
"typescript": "^4.9.3",
"vite": "^3.2.4",
"vitest": "^0.25.2"
}
}
Loading

0 comments on commit e625139

Please sign in to comment.