Skip to content

Commit e625139

Browse files
authored
feat: release for different gitea versions (#3)
1 parent e2d7551 commit e625139

File tree

10 files changed

+73702
-1874
lines changed

10 files changed

+73702
-1874
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@ name: Release
22

33
on:
44
push:
5-
branches:
6-
- main
5+
tags:
6+
- '*'
77

88
jobs:
99
release:
1010
name: Release
1111
runs-on: ubuntu-latest
12+
env:
13+
GITEA_VERSION: ${{ github.ref_name }}
1214
steps:
1315
- name: Checkout
1416
uses: actions/checkout@v2
1517
with:
1618
fetch-depth: 0
1719

20+
- run: echo "Releasing version '${{github.ref_name}}' ..."
21+
1822
- name: Setup Node.js
1923
uses: actions/setup-node@v2
2024
with:
21-
node-version: '14'
25+
node-version: '18'
2226

2327
- name: Cache pnpm modules
2428
uses: actions/cache@v2
@@ -30,26 +34,20 @@ jobs:
3034
3135
- uses: pnpm/action-setup@v2.0.1
3236
with:
33-
version: 6
37+
version: 7
3438
run_install: true
3539

36-
- name: Download Swagger Spec
37-
run: pnpm run download
38-
39-
- name: Generate api
40-
run: pnpm run generate:api
41-
42-
- name: Generate api docs
43-
run: pnpm run generate:docs
40+
- name: Generate api client & docs
41+
run: pnpm generate
4442

4543
- name: Build
46-
run: pnpm run build
44+
run: pnpm build
4745

4846
- name: Release
4947
env:
5048
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5149
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
52-
run: pnpm run release
50+
run: pnpm publish --no-git-checks
5351

5452
- name: Deploy 🚀
5553
uses: JamesIves/github-pages-deploy-action@v4.2.3

.github/workflows/tests.yml

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
unit-tests:
1212
name: Unit tests
1313
runs-on: ubuntu-latest
14+
env:
15+
VERSION: latest
1416
steps:
1517
- name: Checkout
1618
uses: actions/checkout@v2
@@ -20,7 +22,7 @@ jobs:
2022
- name: Setup Node.js
2123
uses: actions/setup-node@v2
2224
with:
23-
node-version: '14'
25+
node-version: '18'
2426

2527
- name: Cache pnpm modules
2628
uses: actions/cache@v2
@@ -32,24 +34,22 @@ jobs:
3234
3335
- uses: pnpm/action-setup@v2.0.1
3436
with:
35-
version: 6
37+
version: 7
3638
run_install: true
3739

38-
- name: Generate api
39-
run: pnpm generate:api
40+
- name: Generate client
41+
run: pnpm generate
4042

4143
- name: Unit test
44+
env:
45+
TEST_GITEA_TOKEN: ${{ secrets.TEST_GITEA_TOKEN }}
4246
run: pnpm coverage
4347

44-
# - uses: artiomtr/jest-coverage-report-action@v2.0-rc.1
45-
# if: "github.event_name == 'pull_request'"
46-
# with:
47-
# github-token: ${{ secrets.GITHUB_TOKEN }}
48-
# skip-step: all
49-
5048
typecheck:
5149
name: Typecheck
5250
runs-on: ubuntu-latest
51+
env:
52+
VERSION: latest
5353
steps:
5454
- name: Checkout
5555
uses: actions/checkout@v2
@@ -59,7 +59,7 @@ jobs:
5959
- name: Setup Node.js
6060
uses: actions/setup-node@v2
6161
with:
62-
node-version: '14'
62+
node-version: '18'
6363

6464
- name: Cache pnpm modules
6565
uses: actions/cache@v2
@@ -71,48 +71,20 @@ jobs:
7171
7272
- uses: pnpm/action-setup@v2.0.1
7373
with:
74-
version: 6
74+
version: 7
7575
run_install: true
7676

77-
- name: Generate api
78-
run: pnpm generate:api
77+
- name: Generate client
78+
run: pnpm generate
7979

8080
- name: Typecheck
8181
run: pnpm typecheck
8282

83-
# lint:
84-
# name: Lint
85-
# runs-on: ubuntu-latest
86-
# steps:
87-
# - name: Checkout
88-
# uses: actions/checkout@v2
89-
# with:
90-
# fetch-depth: 0
91-
92-
# - name: Setup Node.js
93-
# uses: actions/setup-node@v2
94-
# with:
95-
# node-version: '14'
96-
97-
# - name: Cache pnpm modules
98-
# uses: actions/cache@v2
99-
# with:
100-
# path: ~/.pnpm-store
101-
# key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
102-
# restore-keys: |
103-
# ${{ runner.os }}-
104-
105-
# - uses: pnpm/action-setup@v2.0.1
106-
# with:
107-
# version: 6
108-
# run_install: true
109-
110-
# - name: Lint
111-
# run: pnpm run lint
112-
11383
check-format:
11484
name: Check format
11585
runs-on: ubuntu-latest
86+
env:
87+
VERSION: latest
11688
steps:
11789
- name: Checkout
11890
uses: actions/checkout@v2
@@ -122,7 +94,7 @@ jobs:
12294
- name: Setup Node.js
12395
uses: actions/setup-node@v2
12496
with:
125-
node-version: '14'
97+
node-version: '18'
12698

12799
- name: Cache pnpm modules
128100
uses: actions/cache@v2
@@ -134,7 +106,7 @@ jobs:
134106
135107
- uses: pnpm/action-setup@v2.0.1
136108
with:
137-
version: 6
109+
version: 7
138110
run_install: true
139111

140112
- name: Check format

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@
66
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/anbraten/gitea-js/Release)](https://github.com/anbraten/gitea-js/actions)
77
[![Docs](https://img.shields.io/badge/Docs-up_to_date-brightgreen)](https://anbraten.github.io/gitea-js/)
88

9-
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.
9+
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.
10+
11+
## Version mapping
12+
13+
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.
14+
15+
| Gitea-js | Gitea |
16+
| -------- | ---------- |
17+
| 1.19.x | 1.19 (dev) |
18+
| 1.18.x | 1.18 |
19+
| 1.16.x | 1.17 |
20+
| < 1.2.0 | 1.17 |
1021

1122
## Examples
1223

contrib/generate.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { generateApi } from 'swagger-typescript-api';
2+
import path from 'path';
3+
import { exec as _exec } from 'child_process';
4+
import fs from 'fs';
5+
6+
async function exec(cmd: string) {
7+
return await new Promise<string>((resolve) => {
8+
_exec(cmd, (err: any, stdout: any, stderr: any) => {
9+
if (err) {
10+
console.error(err);
11+
return;
12+
}
13+
console.log(stdout);
14+
resolve(stdout);
15+
});
16+
});
17+
}
18+
19+
function getVersions(_version: string) {
20+
if (!_version) {
21+
throw new Error('version must be set');
22+
}
23+
24+
if (_version === 'latest') {
25+
const newestFile = fs.readdirSync(path.resolve(__dirname, '..', 'src', 'schemas')).sort().pop();
26+
const giteaVersion = newestFile?.replace('v', '').replace('.json', '');
27+
28+
return {
29+
version: `${giteaVersion}.0`,
30+
giteaVersion,
31+
};
32+
}
33+
34+
const version = _version.replace(/^v/, '');
35+
const [major, minor] = version.split('.');
36+
const giteaVersion = `${major}.${minor}`;
37+
38+
return { version, giteaVersion };
39+
}
40+
41+
async function run(_version: string) {
42+
const { version, giteaVersion } = getVersions(_version);
43+
44+
console.log(`Generating gitea-js version "${version}" for Gitea "${giteaVersion}" ...`);
45+
46+
await generateApi({
47+
name: 'api.ts',
48+
output: path.resolve(__dirname, '..', 'src'),
49+
input: path.resolve(__dirname, '..', 'src', 'schemas', `v${giteaVersion}.json`),
50+
});
51+
52+
console.log(`Generating docs for ...`);
53+
54+
await exec(`typedoc src/index.ts`);
55+
56+
console.log(`Setting package.json version to "${version}" ...`);
57+
58+
await exec(`sed -i 's/0.0.0/${version}/g' package.json`);
59+
60+
console.log(`Done.`);
61+
}
62+
63+
run(process.env.VERSION);

package.json

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitea-js",
3-
"version": "0.0.0-semantic-release",
3+
"version": "0.0.0",
44
"homepage": "https://anbraten.github.io/gitea-js/",
55
"repository": "github:anbraten/gitea-js",
66
"author": "Anbraten",
@@ -18,34 +18,27 @@
1818
"/dist"
1919
],
2020
"scripts": {
21-
"download": "wget https://gitea.com/swagger.v1.json -O ./src/swagger.json",
22-
"generate:api": "swagger-typescript-api -p https://gitea.com/swagger.v1.json -o ./src -n api.ts",
23-
"generate:docs": "typedoc ./src/index.ts",
24-
"generate": "pnpm generate:api && pnpm generate:docs",
21+
"generate": "tsx contrib/generate.ts",
2522
"build": "tsup src/index.ts --dts --format cjs,esm",
26-
"all": "pnpm download && pnpm generate && pnpm build",
27-
"clean": "rm -rf dist/ node_modules/",
2823
"test": "dotenv vitest",
2924
"test:ui": "pnpm test -- --ui",
3025
"coverage": "pnpm test run -- --coverage",
3126
"lint:format": "prettier --check .",
32-
"typecheck": "tsc --noEmit",
33-
"release": "semantic-release"
27+
"typecheck": "tsc --noEmit"
3428
},
3529
"devDependencies": {
36-
"@geprog/semantic-release-config": "1.0.0",
37-
"@types/node": "17.0.13",
38-
"@vitest/ui": "0.5.9",
39-
"c8": "7.11.0",
40-
"cross-fetch": "3.1.5",
41-
"dotenv-cli": "5.0.0",
42-
"prettier": "2.5.1",
43-
"semantic-release": "19.0.2",
44-
"swagger-typescript-api": "9.3.1",
45-
"tsup": "5.11.13",
46-
"typedoc": "0.22.11",
47-
"typescript": "4.5.5",
48-
"vite": "2.8.6",
49-
"vitest": "0.5.9"
30+
"@types/node": "^17.0.3",
31+
"@vitest/ui": "^0.25.2",
32+
"c8": "^7.12.0",
33+
"cross-fetch": "^3.1.5",
34+
"dotenv-cli": "^6.0.0",
35+
"prettier": "^2.7.1",
36+
"swagger-typescript-api": "^12.0.2",
37+
"tsup": "^6.5.0",
38+
"tsx": "^3.12.1",
39+
"typedoc": "^0.23.21",
40+
"typescript": "^4.9.3",
41+
"vite": "^3.2.4",
42+
"vitest": "^0.25.2"
5043
}
5144
}

0 commit comments

Comments
 (0)