-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utilities to publish unstable versions every commit
- Loading branch information
1 parent
565e9e5
commit 7846411
Showing
8 changed files
with
1,749 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@embroider/unstable-release", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"dependencies": { | ||
"ember-apply": "^2.6.5", | ||
"execa": "^7.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { execaCommand } from 'execa'; | ||
import { project } from 'ember-apply'; | ||
|
||
async function publish() { | ||
for await (let workspace of await project.eachWorkspace()) { | ||
if (await isPrivate()) continue; | ||
|
||
console.info(`Publishing ${workspace}`); | ||
await execaCommand('npm publish --tag=unstable --verbose'); | ||
} | ||
} | ||
|
||
publish(); | ||
|
||
async function isPrivate() { | ||
let pkg = await packageJson.read(); | ||
|
||
return pkg.private ?? false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import path from 'node:path'; | ||
|
||
import { execaCommand } from 'execa'; | ||
import { packageJson, project } from 'ember-apply'; | ||
|
||
/** | ||
* 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 root = await project.gitRoot(); | ||
|
||
// Pick new versions for each package | ||
for await (let workspace of await project.eachWorkspace()) { | ||
if (await isPrivate()) continue; | ||
|
||
console.info(`Setting version of ${path.relative(root, workspace)}`); | ||
await setVersion(sha); | ||
} | ||
|
||
// Update each dependency to use the new versions | ||
for await (let workspace of await project.eachWorkspace()) { | ||
if (await isPrivate()) continue; | ||
|
||
console.info(`Updating dependencies of ${path.relative(root, workspace)}`); | ||
await updateDependencies(); | ||
} | ||
} | ||
|
||
updateVersions(); | ||
|
||
//////////////////////////////////////////// | ||
|
||
async function isPrivate() { | ||
let pkg = await packageJson.read(); | ||
|
||
return pkg.private ?? false; | ||
} | ||
|
||
const NEW_VERSIONS = {}; | ||
|
||
async function setVersion(sha) { | ||
await packageJson.modify(json => { | ||
json.version = `${json.version}-unstable.${sha}`; | ||
|
||
NEW_VERSIONS[json.name] = json.version; | ||
}); | ||
} | ||
|
||
async function updateDependencies() { | ||
await packageJson.modify(json => { | ||
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; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
async function currentSHA() { | ||
let { stdout } = await execaCommand(`git rev-parse --short HEAD`); | ||
|
||
return stdout.trim(); | ||
} |
Oops, something went wrong.