Skip to content

Commit

Permalink
Build: Combine build+prep, and allow for alpha versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed Jul 12, 2024
1 parent 121f7e2 commit 666890b
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 157 deletions.
2 changes: 0 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@
*.tap.txt eol=lf
*.json eol=lf
*.html eol=lf

/package-lock.json binary
14 changes: 5 additions & 9 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,18 @@ Ensure that all changes for this release have been merged into the main branch.
npm ci
```

1. Prepare for the release commit:
1. Prepare for the release commit, and build release artefacts:
```
node build/prep-release.js @VERSION
```

This script does not need any credentials or permissions, and is compatible with running in an isolated container that only has read-write permissions to the current directory. The script will edit `package.json`, then execute `npm run build` to generate the release artifacts, then create a local clone of [jquery/codeorigin.jquery.com](https://github.com/jquery/codeorigin.jquery.com), and prepare a local commit for you to later push.

* Use `git add -p` to review the changes.
* In `AUTHORS.txt`, if you see duplicate entries, then use the `.mailmap` file to normalize them to a canonical name and e-mail address, and then re-run the above command.
* In `AUTHORS.txt`, if you see duplicate entries, then use the `.mailmap` file to normalize them to a canonical name and e-mail address. Then run `git add .mailmap && git checkout .` to save the mailmap changes and undo other. Then re-run the above command.
* Edit `History.md` to remove changes not relevant to end-users (e.g. changes relating to tests, build, internal refactoring, doc fixes, etc.).

1. Build the release:
```
node build/build-release.js @VERSION
```
This script does not need any credentials or permissions, and may be run in a container that can only read-write the current directory. This will edit `package.json`, then execute `npm run build` to generate the release artifacts, then create a local clone of [jquery/codeorigin.jquery.com](https://github.com/jquery/codeorigin.jquery.com), and prepare a local commit for you to later push.

Review the release artifacts, compared to the previous release.
1. Review the release artifacts, compared to the previous release.
```
node build/review-package.js @LAST_VERSION
Expand Down
130 changes: 0 additions & 130 deletions build/build-release.js

This file was deleted.

124 changes: 108 additions & 16 deletions build/prep-release.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Helper for the QUnit release preparation commit.
// Helper to create the QUnit release commit,
// and prepare a local commit in a codeorigin.git clone.
//
// To test the codeorigin step with an alternate remote,
// pass "test" as the second argument.
//
// See also RELEASE.md.
//
Expand All @@ -8,7 +12,17 @@ const fs = require('fs');
const path = require('path');
const cp = require('child_process');

const { CommandError } = require('./utils.js');
const { CommandError, isValidVersion } = require('./utils.js');

const cdnRemotes = {
anonymous: 'https://github.com/jquery/codeorigin.jquery.com.git',
auth: 'git@github.com:jquery/codeorigin.jquery.com.git'
};
const cdnFiles = {
'qunit/qunit.js': 'cdn/qunit/qunit-@VERSION.js',
'qunit/qunit.css': 'cdn/qunit/qunit-@VERSION.css'
};
const cdnCommitMessage = 'qunit: Added version @VERSION';

function parseLineResults (output = '') {
output = output.trim();
Expand All @@ -33,10 +47,10 @@ function formatChangelogColumn (version) {

const Repo = {
async prep (version) {
if (typeof version !== 'string' || !/^\d+\.\d+\.\d+$/.test(version)) {
if (typeof version !== 'string' || !isValidVersion(version)) {
throw new CommandError('Invalid or missing version argument');
}
{
if (!version.includes('-alpha')) {
const UNRELEASED_ADDED = versionAddedString('unreleased');
const UNRELEASED_DEP = versionDeprecatedString('unreleased');
const UNRELEASED_RM = versionRemovedString('unreleased');
Expand Down Expand Up @@ -64,7 +78,7 @@ const Repo = {

const filePath = path.join(__dirname, '..', file);
const oldContent = fs.readFileSync(filePath, 'utf8');
const oldVersion = require('../package.json').version.replace(/-.*$/, '');
const oldVersion = require('../package.json').version;

const changeFilter = [
/^\* Release \d+\./,
Expand Down Expand Up @@ -112,51 +126,129 @@ const Repo = {
fs.writeFileSync(filePath, newSection + changes + oldContent);
}
{
const file = 'package.json';
const file = 'package-lock.json';
console.log(`Updating ${file}...`);
const filePath = path.join(__dirname, '..', file);
const json = fs.readFileSync(filePath, 'utf8');
const packageIndentation = json.match(/\n([\t\s]+)/)[1];
const data = JSON.parse(json);

data.version = version;
data.version = data.packages[''].version = version;

fs.writeFileSync(
filePath,
JSON.stringify(data, null, packageIndentation) + '\n'
);
}
{
const file = 'package-lock.json';
const file = 'AUTHORS.txt';
console.log(`Updating ${file}...`);
cp.execSync(
require('../package.json').scripts.authors,
{ encoding: 'utf8' }
);
}
},
buildFiles (version) {
if (typeof version !== 'string' || !isValidVersion(version)) {
throw new CommandError('Invalid or missing version argument');
}
{
const file = 'package.json';
console.log(`Updating ${file}...`);
const filePath = path.join(__dirname, '..', file);
const json = fs.readFileSync(filePath, 'utf8');
const packageIndentation = json.match(/\n([\t\s]+)/)[1];
const data = JSON.parse(json);

data.version = data.packages[''].version = version;
data.version = version;

fs.writeFileSync(
filePath,
JSON.stringify(data, null, packageIndentation) + '\n'
);
}
{
const file = 'AUTHORS.txt';
console.log(`Updating ${file}...`);
cp.execSync(
require('../package.json').scripts.authors,
{ encoding: 'utf8' }
);
console.log('Running `npm run build`...');
process.env.QUNIT_BUILD_RELEASE = '1';
cp.execFileSync('npm', [
'run',
'build'
], { encoding: 'utf8' });
}
},
cdnClone (repoPath) {
const remote = cdnRemotes.anonymous;
console.log('... cloning ' + remote);
fs.rmSync(repoPath, { recursive: true, force: true });
cp.execFileSync('git', [
'clone',
'--depth=5',
'-q',
remote,
repoPath
]);
},
cdnCommit (version) {
if (!version) {
throw new CommandError('Missing parameters');
}
const repoPath = path.join(__dirname, '..', '__codeorigin');
Repo.cdnClone(repoPath);

const toCommit = [];
for (const src in cdnFiles) {
const srcPath = path.join(__dirname, '..', src);
const dest = cdnFiles[src].replace('@VERSION', version);
const destPath = path.join(repoPath, dest);
console.log('... copying ' + src + ' to ' + dest);
fs.copyFileSync(srcPath, destPath, fs.constants.COPYFILE_EXCL);
toCommit.push(dest);
}

console.log('... creating commit');

const author = cp.execSync('git log -1 --format=%aN%n%aE',
{ encoding: 'utf8', cwd: path.join(__dirname, '..') }
)
.trim()
.split('\n');

cp.execFileSync('git', ['add', ...toCommit],
{ cwd: repoPath }
);

cp.execFileSync('git',
['commit', '-m', cdnCommitMessage.replace('@VERSION', version)],
{
cwd: repoPath,
env: {
GIT_AUTHOR_NAME: author[0],
GIT_AUTHOR_EMAIL: author[1],
GIT_COMMITTER_NAME: author[0],
GIT_COMMITTER_EMAIL: author[1]
}
}
);

// prepre for user to push from the host shell after review
cp.execFileSync('git', ['remote', 'set-url', 'origin', cdnRemotes.auth],
{ cwd: repoPath }
);
}
};

const version = process.argv[2];
const [version, remote] = process.argv.slice(2);

(async function main () {
await Repo.prep(version);
Repo.buildFiles(version);
Repo.cdnCommit(version, remote || 'real');
}()).catch(e => {
if (e.stderr) {
e.stdout = e.stdout.toString();
e.stderr = e.stderr.toString();
}
console.error(e);
process.exit(1);
});
5 changes: 5 additions & 0 deletions build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function cleanDir (dirPath) {
fs.mkdirSync(dirPath, { recursive: true });
}

function isValidVersion (version) {
return /^\d+\.\d+\.\d+(-alpha\.\d+)?$/.test(version);
}

// Turn invisible chars and non-ASCII chars into escape sequences.
//
// This is like `cat --show-nonprinting` and makes diffs easier to understand
Expand All @@ -101,6 +105,7 @@ module.exports = {
download,
downloadFile,
cleanDir,
isValidVersion,
verboseNonPrintable,
normalizeEOL
};

0 comments on commit 666890b

Please sign in to comment.