Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unstable release sync with main #1364

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/publish-unstable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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:
# 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 }}
32 changes: 32 additions & 0 deletions test-packages/unstable-release/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
},
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
env: {
browser: true,
},
overrides: [
// node files
{
files: ['./.eslintrc.cjs'],
parserOptions: {
sourceType: 'script',
},
env: {
browser: false,
node: true,
},
plugins: ['node'],
extends: ['plugin:node/recommended'],
},
],
};
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
```
23 changes: 23 additions & 0 deletions test-packages/unstable-release/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@embroider/unstable-release",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"lint:js": "eslint . --cache --config ./.eslintrc.cjs"
},
"dependencies": {
"execa": "^7.0.0",
"fs-extra": "^9.1.0",
"globby": "^11.0.3"
},
"volta": {
"extends": "../../package.json"
},
"devDependencies": {
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-node": "^11.1.0",
"prettier": "^2.5.1"
}
}
14 changes: 14 additions & 0 deletions test-packages/unstable-release/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { execaCommand } from 'execa';
import { listPublicWorkspaces } from './workspaces.js';
import { dirname } from 'path';

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

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

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();
}
Loading