Skip to content

Commit 98408d5

Browse files
committed
chore(release): v3.1.0 ✨
1 parent 068fed3 commit 98408d5

35 files changed

+697
-19
lines changed

.github/workflows/release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
8+
jobs:
9+
github-release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: actions/github-script@v6
16+
id: get-version
17+
with:
18+
result-encoding: string
19+
script: |
20+
const major = process.env.GITHUB_REF_NAME.substring(1, 2)
21+
const fullVersion = process.env.GITHUB_REF_NAME.substring(1)
22+
23+
core.setOutput('major', major)
24+
core.setOutput('full', fullVersion)
25+
- uses: actions/github-script@v6
26+
id: extract-changelog
27+
env:
28+
VERSION_MAJOR: '${{ steps.get-version.outputs.major }}'
29+
VERSION_FULL: '${{ steps.get-version.outputs.full }}'
30+
with:
31+
result-encoding: string
32+
script: |
33+
const file = `docs/changelog/${process.env.VERSION_MAJOR}/${process.env.VERSION_FULL}.md`
34+
35+
let output = ''
36+
const options = {
37+
listeners: {
38+
stdout: (data: Buffer) => {
39+
output += data.toString('utf8')
40+
}
41+
}
42+
}
43+
await exec.exec(`cat ${file} | tail -n +5`)
44+
45+
core.setOutput('markdown', output.trim())
46+
- name: Create Release
47+
uses: softprops/action-gh-release@v1
48+
with:
49+
body: |
50+
## Changelog
51+
${{ steps.extract-changelog.outputs.markdown }}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
sidebar_position: 4
3+
sidebar_label: 🧩 API
4+
---
5+
6+
# API
7+
8+
```js
9+
// Require the module
10+
const versionCheck = require('@version-checker/core');
11+
12+
// Or import
13+
import versionCheck from '@version-checker/core'
14+
```
15+
16+
## `function versionCheck(options, [callback])`
17+
Performs an update check with the given options. The `callback` is optional, can be omitted to return a `Promise`.
18+
19+
### The `options` object
20+
Option | Description | Default Value | Introduction
21+
--- | --- | --- | ---
22+
token | A [personal access token](https://blog.github.com/2013-05-16-personal-api-tokens/) used to access the **Github GraphQL API (v4)**. Can be omitted and instead be read from an env variable called `GITHUB_API_TOKEN`. When no token can be found, the module will fall back to the **Github Rest API (v3)**. | `undefined` | `v2.0.0`
23+
repo | The name of your Github repository.| **None. Required.** | `v1.0.0`
24+
owner | The owner of your Github repository (usually your username).| **None. Required.** | `v1.0.0`
25+
currentVersion | Your app's current version. | **None. Required.** | `v1.0.0`
26+
fetchTags | Whether to fetch the repositories' git tags instead of the GitHub releases. Useful when no releases are created, but only tags. | `false` | `v1.0.0`
27+
latestOnly | Setting this to `true` will fetch the latest release only | `false` | `v2.2.0`
28+
excludePrereleases | Excludes pre-releases from checks. Currently only works when no token is specified. | `false` | `v2.3.0`
29+
forceRest | Will use the Github REST API (v3) even with a supplied token. | `false` | `v3.0.0`
30+
31+
### The `callback` function (optional)
32+
Should be of the following form:
33+
```javascript
34+
function(error, update) {
35+
// ...your code
36+
}
37+
```
38+
* `error`:
39+
* If an error occurs, this holds the error message. `null` if no error occurs.
40+
* `update`:
41+
* An object in the format specified below. `null` if no update was found.
42+
43+
### Return type
44+
45+
The function returns a `CheckResult` which has the following structure:
46+
47+
```typescript
48+
interface CheckResult {
49+
src: string
50+
type: string
51+
update: ReleaseDescriptor | TagDescriptor | undefined
52+
}
53+
```
54+
55+
#### Properties
56+
##### `src`
57+
58+
States which API endpoint has been used.
59+
60+
Possible values:
61+
62+
- `rest`
63+
- `graphql`
64+
65+
##### `type`
66+
67+
States whether releases or tags have been fetched.
68+
69+
Possible values:
70+
71+
- `releases`
72+
- `tags`
73+
74+
##### `update`
75+
76+
Holds the actual data on a possible update. For structure details refer to [Object schemes](#object-schemes).
77+
78+
It is `undefined` in case no update could be found.
79+
80+
### Using `Promise`
81+
You can omit the `callback` function to return a `Promise`, which resolves with the `update` object.
82+
83+
## Object schemes
84+
### ReleaseDescriptor
85+
When fetching releases, an object with the following structure will be returned:
86+
```typescript
87+
interface ReleaseDescriptor {
88+
name: string
89+
tag: TagDescriptor
90+
isPrerelease: boolean
91+
isDraft: boolean
92+
publishedAt: string
93+
url: string
94+
}
95+
```
96+
97+
### TagDescriptor
98+
When fetching tags, you will receive an object with the following structure:
99+
```typescript
100+
interface TagDescriptor {
101+
name: string
102+
}
103+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
sidebar_position: 3
3+
sidebar_label: 🌐 Browser Support
4+
---
5+
6+
# Browser Support
7+
8+
To use this in the browser, install `@version-checker/browser` instead of `@version-checker/core`.
9+
10+
Subsequently, import `@version-checker/browser` instead of `@version-checker/core`.
11+
12+
**Note**: This is currently **EXPERIMENTAL**, as it depends on `@octokit/core^5.0.0-beta.4^` and the
13+
[Node.js Fetch API](https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Installation
2+
3+
## npm
4+
5+
```shell
6+
npm install -g @version-checker/cli
7+
```
8+
9+
## Binary
10+
11+
Download a binary version from the [releases page](https://github.com/axelrindle/github-version-checker/releases).
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Usage Examples
2+
3+
## Basic
4+
5+
```shell
6+
$ version-checker \
7+
--owner axelrindle \
8+
--repository version-checker \
9+
--current-version 2.2.0
10+
```
11+
12+
```
13+
An update is available! v3.0.0
14+
You are on version 2.3.0!
15+
```
16+
17+
## With json output
18+
19+
```shell
20+
$ version-checker --json \
21+
--owner axelrindle \
22+
--repository version-checker \
23+
--current-version 2.2.0
24+
```
25+
26+
```json
27+
{
28+
"type": "outdated",
29+
"data": {
30+
"name": "v2.3.0",
31+
"tag": {
32+
"name": "2.3.0"
33+
},
34+
"isPrerelease": false,
35+
"isDraft": false,
36+
"publishedAt": "2022-03-18T15:22:03Z",
37+
"url": "https://github.com/axelrindle/github-version-checker/releases/tag/2.3.0"
38+
}
39+
}
40+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "⌨️ Command Line Interface (CLI)",
3+
"position": 5,
4+
"link": {
5+
"type": "doc",
6+
"id": "cli/index"
7+
}
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Command Line Interface (CLI)
2+
3+
The CLI offers to perform a version check in non-Node.js environments.
4+
It supports plain-text and JSON-formatted output.
5+
6+
## Usage
7+
8+
```
9+
10+
$ version-checker [options]
11+
12+
Options
13+
-o, --owner The repository owner. May be a username or organization name.
14+
-r, --repository The repository name.
15+
-c, --current-version The current application version.
16+
-t, --tags Fetches tags instead of releases.
17+
--no-pre-releases Excludes pre-releases. (default false)
18+
--token A PAT to use.
19+
--json Outputs the raw result data as JSON. (default false)
20+
--verbose Enables verbose logging. (default false)
21+
-v, --version Displays current version
22+
-h, --help Displays this message
23+
24+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "🥸 Basic",
3+
"position": 1,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Basic Examples"
7+
}
8+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Async / Await
2+
3+
The future is now! Futuristic approach leveraging top-level await.
4+
5+
```js showLineNumbers title="src/util/version-check.js"
6+
const versionCheck = require('@version-checker/core')
7+
const options = {
8+
// token: '...',
9+
repo: 'version-checker',
10+
owner: 'axelrindle',
11+
currentVersion: require('../package.json').version
12+
}
13+
14+
try {
15+
// highlight-next-line
16+
const { update } = await versionCheck(options)
17+
if (update) { // update is null if there is no update available, so check here
18+
console.log('An update is available! ' + update.name)
19+
console.log('You are on version ' + options.currentVersion + '!')
20+
} else {
21+
console.log('You are up to date.')
22+
}
23+
} catch (e) {
24+
console.error(e)
25+
}
26+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Callback
2+
3+
Using a plain old callback.
4+
5+
````js showLineNumbers title="src/util/version-check.js"
6+
const versionCheck = require('@version-checker/core')
7+
const options = {
8+
// token: '...',
9+
repo: 'version-checker',
10+
owner: 'axelrindle',
11+
currentVersion: require('../package.json').version
12+
}
13+
14+
versionCheck(options, function (error, result) {
15+
if (error) {
16+
console.error(error)
17+
process.exit(-1)
18+
}
19+
20+
const { update } = result
21+
if (update) {
22+
console.log('An update is available! ' + update.name)
23+
console.log('You are on version ' + options.currentVersion + '!')
24+
} else {
25+
console.log('You are up to date.')
26+
}
27+
})
28+
```

0 commit comments

Comments
 (0)