Skip to content

Commit c4cc0bf

Browse files
committed
Added workflow to publish via CI
1 parent 34155da commit c4cc0bf

File tree

5 files changed

+104
-4
lines changed

5 files changed

+104
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- main
77
- 'renovate/*'
8+
workflow_call:
89
jobs:
910
test:
1011
name: Test (Node ${{ matrix.node-version }})

.github/workflows/publish.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
workflow_dispatch:
8+
inputs:
9+
dry-run:
10+
description: 'Preview what would be published without actually publishing'
11+
required: false
12+
type: boolean
13+
default: true
14+
15+
jobs:
16+
test:
17+
uses: ./.github/workflows/ci.yml
18+
19+
publish:
20+
name: Publish to npm
21+
needs: test
22+
runs-on: ubuntu-latest
23+
if: github.repository == 'TryGhost/gscan'
24+
concurrency:
25+
group: publish-npm-${{ github.ref }}
26+
cancel-in-progress: false
27+
28+
permissions:
29+
id-token: write
30+
contents: read
31+
32+
env:
33+
FORCE_COLOR: 1
34+
CI: true
35+
NPM_CONFIG_PROVENANCE: true
36+
37+
steps:
38+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
39+
40+
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6
41+
with:
42+
node-version: 24
43+
registry-url: 'https://registry.npmjs.org'
44+
45+
# npm 11+ is required for npm Trusted Publishing (OIDC).
46+
- name: Install npm 11
47+
run: npm install -g npm@11
48+
49+
- name: Install dependencies
50+
run: yarn --prefer-offline --ignore-scripts --frozen-lockfile
51+
52+
- name: Compare local and npm versions
53+
id: version_check
54+
shell: bash
55+
run: |
56+
local_version=$(node -p "require('./package.json').version")
57+
npm_version=$(npm view gscan version 2>/dev/null || true)
58+
59+
echo "local_version=$local_version" >> "$GITHUB_OUTPUT"
60+
echo "npm_version=$npm_version" >> "$GITHUB_OUTPUT"
61+
62+
if [[ -z "$npm_version" || "$local_version" != "$npm_version" ]]; then
63+
echo "should_publish=true" >> "$GITHUB_OUTPUT"
64+
echo "reason=version-diff" >> "$GITHUB_OUTPUT"
65+
else
66+
echo "should_publish=false" >> "$GITHUB_OUTPUT"
67+
echo "reason=same-version" >> "$GITHUB_OUTPUT"
68+
fi
69+
70+
- name: Publish to npm (dry run)
71+
if: github.event_name == 'workflow_dispatch' && github.event.inputs['dry-run'] == 'true'
72+
run: yarn ship:ci
73+
env:
74+
NPM_CONFIG_DRY_RUN: true
75+
76+
- name: Publish to npm
77+
if: steps.version_check.outputs.should_publish == 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs['dry-run'] != 'true')
78+
run: yarn ship:ci
79+
80+
- name: Skip publish summary
81+
if: steps.version_check.outputs.should_publish != 'true' || (github.event_name == 'workflow_dispatch' && github.event.inputs['dry-run'] == 'true')
82+
run: |
83+
echo "Publish not executed."
84+
echo "Version check: ${{ steps.version_check.outputs.reason || 'not-run' }}"
85+
echo "Dry run: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs['dry-run'] == 'true' }}"
86+
87+
- uses: tryghost/actions/actions/slack-build@main
88+
if: failure() && secrets.SLACK_WEBHOOK_URL != ''
89+
with:
90+
status: ${{ job.status }}
91+
env:
92+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

CLAUDE.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ yarn lint
3636
yarn lint --fix
3737

3838
# Full release process (core team)
39+
# 1) bump version + commit/tag/push
3940
yarn ship
41+
42+
# 2) npm publish is handled in CI by .github/workflows/publish.yml
43+
# Manual preview is available via workflow_dispatch with dry-run=true
4044
```
4145

4246
### CLI Usage
@@ -224,4 +228,4 @@ Themes can define custom settings in package.json:
224228
2. **Test array counts**: The checker tests have exact counts of pass results - you must update these when adding new rules
225229
3. **Alphabetical ordering**: The pass results are sorted, so GSXXX codes must be inserted in the correct position in test arrays
226230
4. **Partial path normalization**: Use `normalizePath()` from `lib/utils` to handle Windows vs Unix path separators
227-
5. **Check options parameter**: Even if unused, keep the `options` parameter in the function signature and add `// eslint-disable-line no-unused-vars`
231+
5. **Check options parameter**: Even if unused, keep the `options` parameter in the function signature and add `// eslint-disable-line no-unused-vars`

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,12 @@ gscan.checkZip({
9696

9797
### Publish
9898

99-
(Core team only)
99+
Ghost core team only
100100

101-
- `yarn ship`
101+
1. run `yarn ship` - this bumps the version, commits, tags and pushes to `main`
102+
2. npm publishing is handled by GitHub Actions in `.github/workflows/publish.yml`
103+
104+
Manual preview is available via workflow dispatch with `dry-run: true`
102105

103106
### Tools
104107
When developing new rules or testing gscan following tools are great to have in the toolbelt:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"posttest": "yarn lint",
3838
"preship": "yarn test",
3939
"ship": "pro-ship",
40-
"postship": "npm publish"
40+
"ship:ci": "npm publish"
4141
},
4242
"bin": {
4343
"gscan": "./bin/cli.js"

0 commit comments

Comments
 (0)