Skip to content

Commit

Permalink
Add utilities to publish unstable versions every commit
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Feb 21, 2023
1 parent 565e9e5 commit 6dae7d1
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 3 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/publish-unstable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# For every push to the master branch, this publishes an NPM package to the
# "unstable" NPM tag.

name: Publish Unstable

on:
push:
branches:
- main

concurrency:
group: ci-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
publish:
name: "NPM Publish"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- name: Install Node
uses: actions/setup-node@v3
with:
node: 18
# This creates an .npmrc that reads the NODE_AUTH_TOKEN environment variable
registry-url: 'https://registry.npmjs.org'

- name: set versions
run: node ./test-packages/unstable-release/version.js

- name: npm publish
run: node ./test-packages/unstable-release/publish.js
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"registry": "https://registry.npmjs.org"
},
"volta": {
"node": "14.19.3",
"node": "18.14.1",
"yarn": "1.22.19"
},
"version": "1.8.3"
Expand Down
5 changes: 4 additions & 1 deletion test-packages/support/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
"qunit": "^2.16.0",
"webpack": "^5"
},
"engines": {
"node": ">= 18.0.0"
},
"volta": {
"extends": "../../package.json"
"node": ">= 18.0.0"
}
}
9 changes: 9 additions & 0 deletions test-packages/unstable-release/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @embroider/unstable-release

Tools for supporting unstable releases off `main`.

_The changes this package makes to the monorepo should not be committed_.

```bash
node ./test-packages/unstable-release/version.js
```
11 changes: 11 additions & 0 deletions test-packages/unstable-release/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@embroider/unstable-release",
"version": "0.0.0",
"private": true,
"type": "module",
"dependencies": {
"fs-extra": "^9.1.0",
"globby": "^11.0.3",
"execa": "^7.0.0"
}
}
12 changes: 12 additions & 0 deletions test-packages/unstable-release/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { execaCommand } from 'execa';

async function publish() {
let publicWorkspaces = await listPublicWorkspaces();

for (let workspace of publicWorkspaces) {
console.info(`Publishing ${workspace}`);
await execaCommand('npm publish --tag=unstable --verbose');
}
}

publish();
61 changes: 61 additions & 0 deletions test-packages/unstable-release/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import fse from 'fs-extra';
import { listPublicWorkspaces, currentSHA } from './workspaces.js';

/**
* This is an I/O heavy way to do this, but hopefully it reads easy
*
* these functions change the CWD as they go, returnning to he previous
* CWD via finally blocks upon finish.
*/
async function updateVersions() {
let sha = await currentSHA();

let publicWorkspaces = await listPublicWorkspaces();

// Pick new versions for each package
for (let workspace of publicWorkspaces) {
console.info(`Setting version of ${workspace}`);
await setVersion(sha, workspace);
}

// Update each dependency to use the new versions
for (let workspace of publicWorkspaces) {
console.info(`Updating dependencies of ${workspace}`);
await updateDependencies(workspace);
}
}

updateVersions();

////////////////////////////////////////////

const NEW_VERSIONS = {};

async function setVersion(sha, filePath) {
let json = await fse.readJSON(filePath);
json.version = `${json.version}-unstable.${sha}`;

NEW_VERSIONS[json.name] = json.version;

await fse.writeJSON(filePath, json, { spaces: 2 });
}

async function updateDependencies(filePath) {
let json = await fse.readJSON(filePath);

for (let [dep, version] of Object.entries(NEW_VERSIONS)) {
if ((json.dependencies || {})[dep]) {
json.dependencies[dep] = version;
}

if ((json.devDependencies || {})[dep]) {
json.devDependencies[dep] = version;
}

if ((json.peerDependencies || {})[dep]) {
json.peerDependencies[dep] = version;
}
}

await fse.writeJSON(filePath, json, { spaces: 2 });
}
30 changes: 30 additions & 0 deletions test-packages/unstable-release/workspaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import globby from 'globby';
import { execaCommand } from 'execa';
import fse from 'fs-extra';

/**
* All publishable packages are in packages/*
*
* We could read package.json#workspaces, but then we'd have more to filter out.
*/
export async function listPublicWorkspaces() {
let filePaths = await globby(['packages/*/package.json']);

let result = [];

for (let filePath of filePaths) {
let packageJson = await fse.readJSON(filePath);

if (packageJson.private) continue;

result.push(filePath);
}

return result;
}

export async function currentSHA() {
let { stdout } = await execaCommand(`git rev-parse --short HEAD`);

return stdout.trim();
}
56 changes: 55 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8959,6 +8959,21 @@ execa@^5.0.0, execa@^5.1.1:
signal-exit "^3.0.3"
strip-final-newline "^2.0.0"

execa@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-7.0.0.tgz#2a44e20e73797f6c2df23889927972386157d7e4"
integrity sha512-tQbH0pH/8LHTnwTrsKWideqi6rFB/QNUawEwrn+WHyz7PX1Tuz2u7wfTvbaNBdP5JD5LVWxNo8/A8CHNZ3bV6g==
dependencies:
cross-spawn "^7.0.3"
get-stream "^6.0.1"
human-signals "^4.3.0"
is-stream "^3.0.0"
merge-stream "^2.0.0"
npm-run-path "^5.1.0"
onetime "^6.0.0"
signal-exit "^3.0.7"
strip-final-newline "^3.0.0"

exit@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c"
Expand Down Expand Up @@ -9820,7 +9835,7 @@ get-stream@^5.0.0, get-stream@^5.1.0:
dependencies:
pump "^3.0.0"

get-stream@^6.0.0:
get-stream@^6.0.0, get-stream@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7"
integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==
Expand Down Expand Up @@ -10385,6 +10400,11 @@ human-signals@^2.1.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==

human-signals@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-4.3.0.tgz#2095c3cd5afae40049403d4b811235b03879db50"
integrity sha512-zyzVyMjpGBX2+6cDVZeFPCdtOtdsxOeseRhB9tkQ6xXmGUNrcnBzdEKPy3VPNYz+4gy1oukVOXcrJCunSyc6QQ==

[email protected], iconv-lite@^0.4.17, iconv-lite@^0.4.24:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
Expand Down Expand Up @@ -10903,6 +10923,11 @@ is-stream@^2.0.0:
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077"
integrity sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==

is-stream@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-3.0.0.tgz#e6bfd7aa6bef69f4f472ce9bb681e3e57b4319ac"
integrity sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==

is-string@^1.0.5, is-string@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.7.tgz#0dd12bf2006f255bb58f695110eff7491eebc0fd"
Expand Down Expand Up @@ -12489,6 +12514,11 @@ mimic-fn@^2.1.0:
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==

mimic-fn@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-4.0.0.tgz#60a90550d5cb0b239cca65d893b1a53b29871ecc"
integrity sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==

mimic-response@^1.0.0, mimic-response@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b"
Expand Down Expand Up @@ -12843,6 +12873,13 @@ npm-run-path@^4.0.0, npm-run-path@^4.0.1:
dependencies:
path-key "^3.0.0"

npm-run-path@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-5.1.0.tgz#bc62f7f3f6952d9894bd08944ba011a6ee7b7e00"
integrity sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==
dependencies:
path-key "^4.0.0"

npmlog@^6.0.0:
version "6.0.2"
resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-6.0.2.tgz#c8166017a42f2dea92d6453168dd865186a70830"
Expand Down Expand Up @@ -12990,6 +13027,13 @@ onetime@^5.1.0, onetime@^5.1.2:
dependencies:
mimic-fn "^2.1.0"

onetime@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/onetime/-/onetime-6.0.0.tgz#7c24c18ed1fd2e9bca4bd26806a33613c77d34b4"
integrity sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==
dependencies:
mimic-fn "^4.0.0"

optionator@^0.8.1, optionator@^0.8.2:
version "0.8.3"
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495"
Expand Down Expand Up @@ -13312,6 +13356,11 @@ path-key@^3.0.0, path-key@^3.1.0:
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==

path-key@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/path-key/-/path-key-4.0.0.tgz#295588dc3aee64154f877adb9d780b81c554bf18"
integrity sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==

path-parse@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
Expand Down Expand Up @@ -15113,6 +15162,11 @@ strip-final-newline@^2.0.0:
resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad"
integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==

strip-final-newline@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-3.0.0.tgz#52894c313fbff318835280aed60ff71ebf12b8fd"
integrity sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==

strip-indent@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-3.0.0.tgz#c32e1cee940b6b3432c771bc2c54bcce73cd3001"
Expand Down

0 comments on commit 6dae7d1

Please sign in to comment.