Repository navigation
160 lines (142 loc) · 5.23 KB
/
Copy pathrelease-package.yml
File metadata and controls
160 lines (142 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Release Packages
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: Git tag to publish (e.g. v5.0.0-beta.0). Empty = current ref.
required: false
default: ''
dry_run:
description: Pack and upload release assets only (skip GitHub Packages publish)
type: boolean
required: false
default: false
permissions:
contents: write
packages: write
concurrency:
group: release-packages-${{ github.event.release.tag_name || inputs.tag || github.ref_name }}
cancel-in-progress: false
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Resolve checkout ref
id: ref
run: |
TAG="${{ github.event.release.tag_name || inputs.tag }}"
if [ -n "$TAG" ]; then
echo "ref=$TAG" >> "$GITHUB_OUTPUT"
else
echo "ref=${{ github.sha }}" >> "$GITHUB_OUTPUT"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
ref: ${{ steps.ref.outputs.ref }}
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
registry-url: https://npm.pkg.github.com
scope: '@reactpressjs'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Production build
run: pnpm run build
- name: Build publishable packages
run: pnpm run publish:build
- name: Resolve npm dist-tag
id: dist
run: |
VERSION=$(node -p "require('./cli/package.json').version")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
if echo "$VERSION" | grep -q '-'; then
echo "tag=beta" >> "$GITHUB_OUTPUT"
else
echo "tag=latest" >> "$GITHUB_OUTPUT"
fi
- name: Pack scoped packages
run: |
mkdir -p /tmp/rp-packs
for dir in toolkit web server cli; do
(cd "$dir" && npm pack --pack-destination /tmp/rp-packs)
done
ls -lh /tmp/rp-packs
- name: Upload package tarballs to GitHub Release
if: steps.ref.outputs.tag != ''
env:
GH_TOKEN: ${{ github.token }}
run: |
TAG="${{ steps.ref.outputs.tag }}"
gh release upload "$TAG" /tmp/rp-packs/*.tgz --clobber
- name: Publish @reactpressjs/* to GitHub Packages
if: ${{ inputs.dry_run != true && inputs.dry_run != 'true' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
REGISTRY=https://npm.pkg.github.com
TAG="${{ steps.dist.outputs.tag }}"
VERSION="${{ steps.dist.outputs.version }}"
publish_scoped() {
local dir="$1"
local name
name=$(node -p "require('./${dir}/package.json').name")
case "$name" in
@reactpressjs/*) ;;
*)
echo "Skip non-scoped package: $name"
return 0
;;
esac
echo "Publishing ${name}@${VERSION} → GitHub Packages (tag=${TAG})"
# Use npm (not pnpm) so publishConfig.registry + NODE_AUTH_TOKEN from setup-node apply.
(
cd "$dir"
npm publish --access public --tag "$TAG" --registry "$REGISTRY"
)
}
# Dependency order: toolkit → web/server → cli
# Resolve workspace:* and point publishConfig at GitHub Packages.
node <<'NODE'
const fs = require('fs');
const path = require('path');
const pkgs = [
{ name: '@reactpressjs/reactpress-toolkit', dir: 'toolkit' },
{ name: '@reactpressjs/reactpress-web', dir: 'web' },
{ name: '@reactpressjs/reactpress-server', dir: 'server' },
{ name: '@reactpressjs/reactpress', dir: 'cli' },
];
const versions = Object.fromEntries(
pkgs.map((p) => [p.name, JSON.parse(fs.readFileSync(path.join(p.dir, 'package.json'), 'utf8')).version]),
);
for (const p of pkgs) {
const file = path.join(p.dir, 'package.json');
const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
for (const depType of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
if (!pkg[depType]) continue;
for (const [dep, val] of Object.entries(pkg[depType])) {
if (String(val).startsWith('workspace:') && versions[dep]) {
pkg[depType][dep] = versions[dep];
}
}
}
pkg.publishConfig = {
...(pkg.publishConfig || {}),
access: 'public',
registry: 'https://npm.pkg.github.com',
};
fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + '\n');
}
NODE
publish_scoped toolkit
publish_scoped web
publish_scoped server
publish_scoped cli
echo "GitHub Packages publish complete."
echo "Install example:"
echo " npm i -g @reactpressjs/reactpress@${VERSION} --registry=https://npm.pkg.github.com"