Skip to content

Commit 6a815da

Browse files
authored
Add release workflow (#58)
* Add release workflow * Update readme * Add node version * Validate before creating version
1 parent 9e8adb4 commit 6a815da

File tree

4 files changed

+168
-11
lines changed

4 files changed

+168
-11
lines changed

.github/actions/setup/action.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Based on https://github.com/directus/eslint-config/blob/main/.github/actions/setup/action.yml
2+
3+
name: Setup
4+
description: Configure Node.js + pnpm and install dependencies
5+
6+
inputs:
7+
registry:
8+
description: NPM registry to set up for auth
9+
required: false
10+
11+
runs:
12+
using: composite
13+
steps:
14+
- name: Setup Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version-file: package.json
18+
registry-url: ${{ inputs.registry }}
19+
20+
- name: Setup pnpm
21+
uses: pnpm/action-setup@v4
22+
23+
- name: Get pnpm cache dir
24+
id: pnpm-cache-dir
25+
shell: bash
26+
run: echo "pnpm-cache-dir=$(pnpm store path)" >> $GITHUB_OUTPUT
27+
28+
- name: Setup pnpm cache
29+
uses: actions/cache@v4
30+
with:
31+
path: ${{ steps.pnpm-cache-dir.outputs.pnpm-cache-dir }}
32+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
33+
restore-keys: |
34+
${{ runner.os }}-pnpm-store-
35+
36+
- name: Install dependencies
37+
shell: bash
38+
run: pnpm install

.github/workflows/release.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Based on https://github.com/directus/eslint-config/blob/main/.github/workflows/release.yml
2+
3+
name: Release
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: SemVer for the release, for example "1.0.0"
10+
required: true
11+
type: string
12+
13+
jobs:
14+
check-version:
15+
name: Check Version
16+
runs-on: ubuntu-latest
17+
outputs:
18+
version: ${{ steps.version.outputs.release }}
19+
is-prerelease: ${{ steps.version.outputs.prerelease && true || false }}
20+
steps:
21+
- name: Check version
22+
uses: madhead/semver-utils@v4
23+
id: version
24+
with:
25+
version: ${{ inputs.version }}
26+
lenient: false
27+
28+
validate:
29+
name: Validate
30+
needs: check-version
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v4
35+
36+
- name: Setup env
37+
uses: ./.github/actions/setup
38+
39+
- name: Build
40+
run: pnpm run build
41+
42+
create-version:
43+
name: Create Version
44+
needs:
45+
- check-version
46+
- validate
47+
runs-on: ubuntu-latest
48+
permissions:
49+
contents: write
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v4
53+
54+
- name: Setup env
55+
uses: ./.github/actions/setup
56+
57+
- name: Bump version
58+
run: pnpm version --no-git-tag-version '${{ needs.check-version.outputs.version }}'
59+
60+
- name: Create version commit & tag
61+
run: |
62+
author='${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>'
63+
version='v${{ needs.check-version.outputs.version }}'
64+
branch='${{ github.ref }}'
65+
66+
git config user.name 'github-actions[bot]'
67+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
68+
69+
git commit --all --author "$author" --message "$version"
70+
71+
git tag --annotate "$version" --message "$version"
72+
73+
git push --atomic origin "$branch" "refs/tags/${version}"
74+
75+
create-release:
76+
name: Create Release
77+
needs:
78+
- check-version
79+
- create-version
80+
runs-on: ubuntu-latest
81+
permissions:
82+
contents: write
83+
steps:
84+
- name: Checkout repository
85+
uses: actions/checkout@v4
86+
87+
- name: Create release
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
run: |
91+
gh release create \
92+
'v${{ needs.check-version.outputs.version }}' \
93+
--verify-tag \
94+
--generate-notes \
95+
${{ needs.check-version.outputs.is-prerelease == 'true' && '--prerelease' || '' }}
96+
97+
publish-npm:
98+
name: Publish to NPM
99+
needs:
100+
- check-version
101+
- create-version
102+
runs-on: ubuntu-latest
103+
permissions:
104+
id-token: write
105+
steps:
106+
- name: Checkout repository
107+
uses: actions/checkout@v4
108+
with:
109+
ref: refs/tags/v${{ needs.check-version.outputs.version }}
110+
111+
- name: Setup env
112+
uses: ./.github/actions/setup
113+
with:
114+
registry: https://registry.npmjs.org
115+
116+
- name: Build
117+
run: pnpm run build
118+
119+
- name: Publish
120+
env:
121+
NPM_CONFIG_PROVENANCE: true
122+
run: |
123+
pnpm publish \
124+
--access=public \
125+
--no-git-checks \
126+
--tag ${{ needs.check-version.outputs.is-prerelease == 'true' && 'canary' || 'latest' }}

README.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ Examples of how to use the equivalent of the documented REST endpoint in the JS
2626

2727
## Deploying Releases
2828

29-
> [!NOTE]
30-
> This requires write access to the `@directus` organization on npm
31-
3229
To deploy a new release to npm:
3330

34-
- `rm -rf dist` if it exists
35-
- `pnpm build` to build a new `dist` folder
36-
- `pnpm lint` to ensure the built spec is valid
37-
- `pnpm version <patch | minor>`
38-
- `git push && git push --tags`
39-
- `pnpm publish`
40-
41-
This manual process will be replaced with a CD action, but until we set that up, follow the above :)
31+
- Run the [release workflow](https://github.com/directus/openapi/actions/workflows/release.yml)

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@
3535
"jiti": "2.4.2",
3636
"nodemon": "3.1.9",
3737
"openapi3-ts": "4.4.0"
38+
},
39+
"engines": {
40+
"node": ">=22"
3841
}
3942
}

0 commit comments

Comments
 (0)