Skip to content

Commit

Permalink
chore: add release utilities (ReactiveX#7395)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry authored Dec 1, 2023
1 parent e19c7ef commit 480c6a2
Show file tree
Hide file tree
Showing 13 changed files with 1,203 additions and 1,911 deletions.
40 changes: 40 additions & 0 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Install Dependencies
description: 'Prepares the repo by installing dependencies'
inputs:
node-version:
description: 'The node version to setup'
required: true
registry-url:
description: 'Define registry-url'
required: false
default: 'https://registry.npmjs.org'

# outputs: - no outputs

runs:
using: 'composite'
steps:
- name: Use Node.js ${{ inputs.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
registry-url: ${{ inputs.registry-url }}

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
shell: bash

- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install --frozen-lockfile
shell: bash
env:
YARN_CACHE_FOLDER: ${{ steps.yarn-cache-dir-path.outputs.dir }}
12 changes: 5 additions & 7 deletions .github/workflows/ci_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ jobs:
name: Node ${{ matrix.node }} build

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
- uses: actions/checkout@v4

- name: Install Dependencies
uses: ./.github/actions/install-dependencies
with:
node-version: ${{ matrix.node }}
cache: npm
- name: install
run: |
npm install -g yarn@latest
yarn install

- name: rxjs lint
run: yarn workspace rxjs lint
- name: rxjs build
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci_ts_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
name: ts@latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
- uses: actions/checkout@v4

- name: Install Dependencies
uses: ./.github/actions/install-dependencies
with:
node-version: ${{ matrix.node }}
cache: npm

- name: build
run: |
npm install -g yarn@latest
yarn install
yarn workspace rxjs add typescript@latest @types/node@latest --peer --no-save
yarn workspace rxjs compile
53 changes: 53 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: publish

on:
# Run manually using the GitHub UI
workflow_dispatch:
inputs:
version:
description: 'Version to publish'
required: false
default: ''
# ...or whenever a GitHub release gets created
release:
types: [published]

jobs:
publish:
name: Publish to npm
runs-on: ubuntu-latest
permissions:
id-token: write # needed for provenance data generation
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # include tags

- name: Install Dependencies
uses: ./.github/actions/install-dependencies
with:
node-version: 20

- name: Prepare packages for publishing
run: yarn prepare-packages

- name: Apply updated version to packages
run: |
# Use the version from the workflow input if it's set, otherwise use the tag name from the release
VERSION=${{ github.event.inputs.version || github.ref_name }}
yarn nx release version $VERSION
- name: Publish packages to npm
run: |
if [[ $GITHUB_REF == 'refs/heads/7.x' ]]; then
yarn nx release publish --registry https://registry.npmjs.org --tag latest
elif [[ $GITHUB_REF == 'refs/heads/master' ]]; then
yarn nx release publish --registry https://registry.npmjs.org --tag next
else
echo "Branch not recognized for publishing, should be either '7.x' or 'master'"
exit 1
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true
2 changes: 1 addition & 1 deletion .github/workflows/rebase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Automatic Rebase
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ package-lock.json

integration/import/**/rx.json
integration/import/**/operators.json


.nx/cache
6 changes: 0 additions & 6 deletions lerna.json

This file was deleted.

40 changes: 40 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"affected": {
"defaultBase": "master"
},
"nxCloudAccessToken": "OWE4MTMzMTEtNDZlZi00MWMwLWJkYmEtN2EwYTQ1ZWNjMzRkfHJlYWQ=",
"targetDefaults": {
"build": {
"dependsOn": ["^build"],
"cache": true
},
"test:circular": {
"dependsOn": ["build"]
}
},
"release": {
"releaseTagPattern": "{version}",
"changelog": {
"git": {
"commit": true,
"tag": true
},
"workspaceChangelog": {
"createRelease": "github",
"file": false
},
"projectChangelogs": true
},
"groups": {
"npm": {
"projects": ["rxjs"],
"version": {
"generatorOptions": {
"currentVersionResolver": "git-tag",
"specifierSource": "conventional-commits"
}
}
}
}
}
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
"node": "^18.13.0 || ^20.9.0"
},
"packageManager": "yarn@1.22.21",
"scripts": {
"prepare-packages": "yarn nx run-many -t build,lint,test:circular,dtslint,copy_common_package_files --exclude rxjs.dev",
"release": "node scripts/release.js"
},
"dependencies": {},
"devDependencies": {
"lerna": "^7.3.0"
"@nx/js": "17.2.0-beta.11",
"nx": "17.2.0-beta.11"
}
}
4 changes: 2 additions & 2 deletions packages/rxjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"changelog": "npx conventional-changelog-cli -p angular -i CHANGELOG.md -s",
"lint": "eslint --ext=ts,js src spec spec-dtslint",
"dtslint": "npm run lint && tsc -b ./src/tsconfig.types.json",
"prepublishOnly": "yarn build && yarn lint && yarn test && yarn test:circular && yarn dtslint && yarn copy_common_package_files",
"test": "yarn build && cross-env TS_NODE_PROJECT=tsconfig.mocha.json mocha --config spec/support/.mocharc.js \"spec/**/*-spec.ts\"",
"test:esm": "node spec/module-test-spec.mjs",
"test:circular": "dependency-cruiser --validate .dependency-cruiser.json -x \"^node_modules\" dist/esm",
Expand All @@ -89,7 +88,8 @@
},
"repository": {
"type": "git",
"url": "https://github.com/reactivex/rxjs.git"
"url": "https://github.com/reactivex/rxjs.git",
"directory": "packages/rxjs"
},
"keywords": [
"Rx",
Expand Down
33 changes: 21 additions & 12 deletions scripts/copy-common-package-files.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
const fs = require('fs');

// Load the packages from the package.json workspaces
const packageJson = JSON.parse(fs.readFileSync('package.json'));
const packages = packageJson.workspaces;

packages
.filter((path) => path.startsWith('packages'))
.forEach((packagePath) => {
fs.copyFileSync('LICENSE.txt', `${packagePath}/LICENSE.txt`);
fs.copyFileSync('CODE_OF_CONDUCT.md', `${packagePath}/CODE_OF_CONDUCT.md`);
});
// @ts-check

const { copyFileSync } = require('fs');
const { createProjectGraphAsync, joinPathFragments, workspaceRoot } = require('@nx/devkit');

const getWorkspacePath = (...pathFragments) => joinPathFragments(workspaceRoot, ...pathFragments);

(async () => {
const projectGraph = await createProjectGraphAsync();

for (const projectConfig of Object.values(projectGraph.nodes)) {
const projectRoot = projectConfig.data.root;
if (!projectRoot.startsWith('packages')) {
continue;
}
copyFileSync(getWorkspacePath('LICENSE.txt'), getWorkspacePath(projectRoot, `LICENSE.txt`));
copyFileSync(getWorkspacePath('CODE_OF_CONDUCT.md'), getWorkspacePath(projectRoot, `CODE_OF_CONDUCT.md`));
}

process.exit(0);
})();
58 changes: 58 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// @ts-check

const { execSync } = require('node:child_process');
const { releaseChangelog, releaseVersion } = require('nx/src/command-line/release');
// There are multiple copies of outdated yargs in the workspace, access a known modern one
const yargs = require('nx/node_modules/yargs');

(async () => {
try {
const options = await yargs
// @ts-expect-error - don't use the default meaning of version in yargs
.version(false)
.option('version', {
description: 'Explicit version specifier to use, if overriding conventional commits',
type: 'string',
})
.option('dryRun', {
alias: 'd',
description: 'Whether or not to perform a dry-run of the release process, defaults to true',
type: 'boolean',
default: true,
})
.option('verbose', {
description: 'Whether or not to enable verbose logging, defaults to false',
type: 'boolean',
default: false,
})
.parseAsync();

// Prepare the packages for publishing
execSync('yarn prepare-packages', {
stdio: 'inherit',
maxBuffer: 1024 * 1000000,
});

const { workspaceVersion, projectsVersionData } = await releaseVersion({
specifier: options.version,
// stage package.json updates to be committed later by the changelog command
stageChanges: true,
dryRun: options.dryRun,
verbose: options.verbose,
});

// This will create a release on GitHub, which will act as a trigger for the publish.yml workflow
await releaseChangelog({
versionData: projectsVersionData,
version: workspaceVersion,
interactive: 'workspace',
dryRun: options.dryRun,
verbose: options.verbose,
});

process.exit(0);
} catch (err) {
console.error(err);
process.exit(1);
}
})();
Loading

0 comments on commit 480c6a2

Please sign in to comment.