Skip to content

Commit 0e1da85

Browse files
committed
streamline CI
1 parent 0c76b29 commit 0e1da85

5 files changed

Lines changed: 115 additions & 38 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build & Publish Package
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
increment:
7+
required: true
8+
type: string
9+
preid:
10+
required: false
11+
type: string
12+
13+
env:
14+
NODE_VERSION: 22
15+
16+
jobs:
17+
build-and-publish:
18+
runs-on: ubuntu-24.04
19+
timeout-minutes: 5
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
24+
- run: |
25+
git config --global user.name 'AboutBits Tech'
26+
git config --global user.email 'tech@aboutbits.it'
27+
- uses: aboutbits/github-actions-node/setup-and-install@v2
28+
with:
29+
node-version: ${{ env.NODE_VERSION }}
30+
registry-url: 'https://registry.npmjs.org'
31+
- name: Get current package version
32+
id: currentVersion
33+
run: echo "currentVersion=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
34+
- name: Validate prerelease increment
35+
if: github.event.inputs.increment == 'prerelease' && !contains(steps.currentVersion.outputs.currentVersion, '-')
36+
run: exit 1
37+
- name: npm version
38+
run: |
39+
if [ -n "${{ github.event.inputs.preid }}" ]; then
40+
npm version ${{ github.event.inputs.increment }} --preid ${{ github.event.inputs.preid }}
41+
else
42+
npm version ${{ github.event.inputs.increment }}
43+
fi
44+
- name: Get next package version
45+
id: nextVersion
46+
run: echo "nextVersion=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
47+
- run: npm publish
48+
env:
49+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
50+
- name: Create GitHub release
51+
uses: actions/github-script@v7
52+
with:
53+
script: |
54+
github.rest.repos.createRelease({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
tag_name: 'v${{ steps.nextVersion.outputs.nextVersion }}',
58+
name: 'v${{ steps.nextVersion.outputs.nextVersion }}',
59+
prerelease: '${{ steps.nextVersion.outputs.nextVersion }}'.includes('-')
60+
})

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test Package
1+
name: Main
22

33
on: push
44

@@ -12,7 +12,7 @@ jobs:
1212
timeout-minutes: 10
1313
strategy:
1414
matrix:
15-
node_version: [ 18, 20, 22 ]
15+
node_version: [18, 20, 22]
1616
steps:
1717
- uses: actions/checkout@v4
1818
- uses: aboutbits/github-actions-node/setup-and-install@v2
@@ -30,7 +30,7 @@ jobs:
3030
timeout-minutes: 10
3131
strategy:
3232
matrix:
33-
node_version: [ 18, 20, 22 ]
33+
node_version: [18, 20, 22]
3434
steps:
3535
- uses: actions/checkout@v4
3636
- uses: aboutbits/github-actions-node/setup-and-install@v2

.github/workflows/pre-release.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Pre-Release Package
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
increment:
7+
description: "Version increment type"
8+
type: choice
9+
required: true
10+
default: "prepatch"
11+
options:
12+
- "premajor"
13+
- "preminor"
14+
- "prepatch"
15+
preid:
16+
description: "--preid"
17+
type: string
18+
required: true
19+
20+
jobs:
21+
build-and-publish:
22+
uses: ./.github/workflows/build-and-publish.yml
23+
with:
24+
increment: ${{ github.event.inputs.increment }}
25+
preid: ${{ github.event.inputs.preid }}
26+
secrets: inherit

.github/workflows/release.yml

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
1-
name: Create Relase & Publish Package
1+
name: Release Package
22

33
on:
4-
push:
5-
tags:
6-
- 'v*'
7-
8-
env:
9-
NODE_VERSION: 22
4+
workflow_dispatch:
5+
inputs:
6+
increment:
7+
description: "Version increment type"
8+
type: choice
9+
required: true
10+
default: "patch"
11+
options:
12+
- "major"
13+
- "minor"
14+
- "patch"
15+
- "prerelease"
1016

1117
jobs:
12-
build:
13-
runs-on: ubuntu-24.04
14-
timeout-minutes: 5
15-
steps:
16-
- uses: actions/checkout@v4
17-
- uses: actions/github-script@v7
18-
with:
19-
script: |
20-
github.rest.repos.createRelease({
21-
owner: context.repo.owner,
22-
repo: context.repo.repo,
23-
tag_name: '${{ github.ref }}',
24-
name: 'Release ${{ github.ref_name }}',
25-
prerelease: '${{ github.ref_name }}'.includes('-')
26-
})
27-
- uses: aboutbits/github-actions-node/setup-and-install@v2
28-
with:
29-
node-version: ${{ env.NODE_VERSION }}
30-
registry-url: 'https://registry.npmjs.org'
31-
- run: npm publish
32-
env:
33-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
18+
build-and-publish:
19+
uses: ./.github/workflows/build-and-publish.yml
20+
with:
21+
increment: ${{ github.event.inputs.increment }}
22+
secrets: inherit

readme.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,15 @@ export default function TestComponent() {
246246

247247
## Build & Publish
248248

249-
To publish the package commit all changes and push them to main. Then run one of the following commands locally:
249+
To build and publish the package, visit the GitHub Actions page of the repository.
250250

251-
```bash
252-
npm version patch
253-
npm version minor
254-
npm version major
255-
```
251+
You can choose between two workflows:
252+
- `Release Package` to publish a new version of the package.
253+
- `Pre-Release Package` to publish a new pre-release version of the package.
254+
255+
**Note:** Pre-releases need to be supplied with a pre-id.
256+
257+
**Note:** To increment a pre-release, you have to run the normal release workflow and select "prerelease". For this action you need to already be on a pre-release version.
256258

257259
## Information
258260

0 commit comments

Comments
 (0)