Skip to content

Commit e27c890

Browse files
committed
chore: add edge release scripts
1 parent c7e7d4a commit e27c890

5 files changed

Lines changed: 147 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,10 @@ jobs:
2323
- run: yarn dev:prepare
2424
- run: yarn build
2525
- run: yarn dev:build
26-
# - run: yarn vitest --coverage
27-
# - uses: codecov/codecov-action@v3
26+
- name: Release Edge
27+
if: |
28+
github.event_name == 'push' &&
29+
!contains(github.event.head_commit.message, '[skip-release]')
30+
run: ./scripts/release-edge.sh
31+
env:
32+
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nuxt/image",
3-
"version": "1.0.0-testing",
3+
"version": "1.0.0",
44
"description": "Nuxt Image Module",
55
"repository": "nuxt/image",
66
"license": "MIT",
@@ -39,6 +39,7 @@
3939
"@nuxt/module-builder": "latest",
4040
"@nuxtjs/eslint-config-typescript": "latest",
4141
"eslint": "latest",
42+
"jiti": "latest",
4243
"nuxt": "^3.0.0-rc.4",
4344
"standard-version": "latest",
4445
"typescript": "latest"

scripts/bump-edge.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { promises as fsp } from 'fs'
2+
import { execSync } from 'child_process'
3+
import { resolve } from 'pathe'
4+
import { globby } from 'globby'
5+
6+
// Temporary forked from nuxt/framework
7+
8+
async function loadPackage (dir: string) {
9+
const pkgPath = resolve(dir, 'package.json')
10+
const data = JSON.parse(await fsp.readFile(pkgPath, 'utf-8').catch(() => '{}'))
11+
const save = () => fsp.writeFile(pkgPath, JSON.stringify(data, null, 2) + '\n')
12+
13+
const updateDeps = (reviver: Function) => {
14+
for (const type of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {
15+
if (!data[type]) { continue }
16+
for (const e of Object.entries(data[type])) {
17+
const dep = { name: e[0], range: e[1], type }
18+
delete data[type][dep.name]
19+
const updated = reviver(dep) || dep
20+
data[updated.type] = data[updated.type] || {}
21+
data[updated.type][updated.name] = updated.range
22+
}
23+
}
24+
}
25+
26+
return {
27+
dir,
28+
data,
29+
save,
30+
updateDeps
31+
}
32+
}
33+
34+
type ThenArg<T> = T extends PromiseLike<infer U> ? U : T
35+
type Package = ThenArg<ReturnType<typeof loadPackage>>
36+
37+
async function loadWorkspace (dir: string) {
38+
const workspacePkg = await loadPackage(dir)
39+
const pkgDirs = await globby(workspacePkg.data.workspaces || [], { onlyDirectories: true })
40+
41+
const packages: Package[] = [workspacePkg]
42+
43+
for (const pkgDir of pkgDirs) {
44+
const pkg = await loadPackage(pkgDir)
45+
if (!pkg.data.name) { continue }
46+
packages.push(pkg)
47+
}
48+
49+
const find = (name: string) => {
50+
const pkg = packages.find(pkg => pkg.data.name === name)
51+
if (!pkg) {
52+
throw new Error('Workspace package not found: ' + name)
53+
}
54+
return pkg
55+
}
56+
57+
const rename = (from: string, to: string) => {
58+
find(from).data.name = to
59+
for (const pkg of packages) {
60+
pkg.updateDeps((dep) => {
61+
if (dep.name === from && !dep.range.startsWith('npm:')) {
62+
dep.range = 'npm:' + to + '@' + dep.range
63+
}
64+
})
65+
}
66+
}
67+
68+
const setVersion = (name: string, newVersion: string) => {
69+
find(name).data.version = newVersion
70+
for (const pkg of packages) {
71+
pkg.updateDeps((dep) => {
72+
if (dep.name === name) {
73+
dep.range = newVersion
74+
}
75+
})
76+
}
77+
}
78+
79+
const save = () => Promise.all(packages.map(pkg => pkg.save()))
80+
81+
return {
82+
dir,
83+
workspacePkg,
84+
packages,
85+
save,
86+
find,
87+
rename,
88+
setVersion
89+
}
90+
}
91+
92+
async function main () {
93+
const workspace = await loadWorkspace(process.cwd())
94+
95+
const commit = execSync('git rev-parse --short HEAD').toString('utf-8').trim()
96+
const date = Math.round(Date.now() / (1000 * 60))
97+
98+
for (const pkg of workspace.packages.filter(p => !p.data.private)) {
99+
workspace.setVersion(pkg.data.name, `${pkg.data.version}-${date}.${commit}`)
100+
workspace.rename(pkg.data.name, pkg.data.name + '-edge')
101+
}
102+
103+
await workspace.save()
104+
}
105+
106+
main().catch((err) => {
107+
// eslint-disable-next-line no-console
108+
console.error(err)
109+
process.exit(1)
110+
})

scripts/release-edge.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Temporary forked from nuxt/framework
4+
5+
set -xe
6+
7+
# Restore all git changes
8+
git restore -s@ -SW -- .
9+
10+
# Bump versions to edge
11+
yarn jiti ./scripts/bump-edge
12+
13+
# Resolve yarn
14+
YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install
15+
16+
# Update token
17+
if [[ ! -z ${NODE_AUTH_TOKEN} ]] ; then
18+
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> ~/.npmrc
19+
echo "registry=https://registry.npmjs.org/" >> ~/.npmrc
20+
echo "always-auth=true" >> ~/.npmrc
21+
echo "npmAuthToken: ${NODE_AUTH_TOKEN}" >> ~/.yarnrc.yml
22+
npm whoami
23+
fi
24+
25+
# Release packages
26+
echo "Publishing package..."
27+
npm publish --access public --tolerate-republish

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3584,7 +3584,7 @@ jest-worker@^26.2.1:
35843584
merge-stream "^2.0.0"
35853585
supports-color "^7.0.0"
35863586

3587-
jiti@^1.12.14, jiti@^1.12.9, jiti@^1.13.0, jiti@^1.14.0:
3587+
jiti@^1.12.14, jiti@^1.12.9, jiti@^1.13.0, jiti@^1.14.0, jiti@latest:
35883588
version "1.14.0"
35893589
resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.14.0.tgz#5350fff532a4d891ca4bcd700c47c1f40e6ee326"
35903590
integrity sha512-4IwstlaKQc9vCTC+qUXLM1hajy2ImiL9KnLvVYiaHOtS/v3wRjhLlGl121AmgDgx/O43uKmxownJghS5XMya2A==

0 commit comments

Comments
 (0)