Refactored release workflow

- up until now, we've been running `grunt release` before publishing to
  NPM or pushing the canary zip
- this command runs the production asset build and generates a zip
- this zip isn't used by the NPM publishing task because that does an
  `npm pack`
- we only use it for the canary build, but this should be brought more
  inline with the NPM process to make the gaps smaller
- this commit refactors the `grunt release` task to become a lot smaller
  by removing the generated zip steps
- the expected workflow is now to just to an `npm pack`, which will run
  the `prepack` task to generate a `.tgz` archive
- this should still respect `.npmignore`, so it'll just include the
  files we expect
- the test of the canary workflow is being updated to handle this
- also cleans up a dev dependency that is no longer used, along with 2
  imports
This commit is contained in:
Daniel Lockyer 2022-07-19 08:22:49 +02:00
parent 94072c4a32
commit 48194ff444
No known key found for this signature in database
GPG Key ID: D21186F0B47295AD
4 changed files with 17 additions and 110 deletions

View File

@ -24,7 +24,6 @@ jobs:
cache: yarn
- run: yarn
- run: grunt release --skip-tests
- run: npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
- run: npm publish
- uses: tryghost/action-ghost-release@main

View File

@ -1,6 +1,4 @@
const config = require('./core/shared/config');
const fs = require('fs-extra');
const path = require('path');
// Utility for outputting messages indicating that the admin is building, as it can take a while.
let hasBuiltAdmin = false;
@ -38,6 +36,9 @@ module.exports = function (grunt) {
grunt.log.error('@deprecated: Run `yarn test` instead');
});
// Runs the asset generation tasks for production and duplicates default-prod.html to default.html
grunt.registerTask('release', 'Release task - creates a final built zip', ['clean:built', 'prod', 'copy:admin_html']);
// --- Sub Commands
// Used to make other commands work
@ -271,6 +272,16 @@ module.exports = function (grunt) {
src: ['*'],
dest: '.git/hooks'
}
},
copy: {
admin_html: {
files: [{
cwd: '.',
src: 'core/server/web/admin/views/default-prod.html',
dest: 'core/server/web/admin/views/default.html'
}]
}
}
};
@ -280,7 +291,6 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('@lodder/grunt-postcss');
grunt.loadNpmTasks('grunt-bg-shell');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-symlink');
grunt.loadNpmTasks('grunt-contrib-watch');
@ -301,84 +311,4 @@ module.exports = function (grunt) {
// Load the configuration
grunt.initConfig(cfg);
// --- Release Tooling
// grunt release
// - create a Ghost release zip file.
// Uses the files specified by `.npmignore` to know what should and should not be included.
// Runs the asset generation tasks for production and duplicates default-prod.html to default.html
grunt.registerTask('release',
'Release task - creates a final built zip\n' +
' - Do our standard build steps \n' +
' - Copy files to release-folder/#/#{version} directory\n' +
' - Clean out unnecessary files (.git*, etc)\n' +
' - Zip files in release-folder to dist-folder/#{version} directory',
function () {
const escapeChar = process.platform.match(/^win/) ? '^' : '\\';
const cwd = process.cwd().replace(/( |\(|\))/g, escapeChar + '$1');
const buildDirectory = path.resolve(cwd, '.build');
const distDirectory = path.resolve(cwd, '.dist');
// Common paths used by release
grunt.config.set('paths', {
build: buildDirectory,
releaseBuild: path.join(buildDirectory, 'release'),
dist: distDirectory,
releaseDist: path.join(distDirectory, 'release')
});
// Load package.json so that we can create correctly versioned releases.
grunt.config.set('pkg', grunt.file.readJSON('package.json'));
// grunt-contrib-copy
grunt.config.set('copy.release', {
expand: true,
// A list of files and patterns to include when creating a release zip.
// This is read from the `.npmignore` file and all patterns are inverted as we want to define what to include
src: fs.readFileSync('.npmignore', 'utf8').split('\n').filter(Boolean).map(function (pattern) {
return pattern[0] === '!' ? pattern.slice(1) : '!' + pattern;
}),
dest: '<%= paths.releaseBuild %>/'
});
grunt.config.set('copy.admin_html', {
files: [{
cwd: '.',
src: 'core/server/web/admin/views/default-prod.html',
dest: 'core/server/web/admin/views/default.html'
}]
});
// grunt-contrib-compress
grunt.config.set('compress.release', {
options: {
archive: '<%= paths.releaseDist %>/Ghost-<%= pkg.version %>.zip'
},
expand: true,
cwd: '<%= paths.releaseBuild %>/',
src: ['**']
});
// grunt-contrib-clean
grunt.config.set('clean.release', {
src: ['<%= paths.releaseBuild %>/**']
});
if (!grunt.option('skip-update')) {
grunt.task
.run('update_submodules:pinned')
.run('subgrunt:init');
}
grunt.task
.run('clean:built')
.run('clean:tmp')
.run('prod')
.run('clean:release')
.run('copy:admin_html')
.run('copy:release')
.run('compress:release');
}
);
};

View File

@ -48,7 +48,8 @@
"lint": "yarn lint:server && yarn lint:shared && yarn lint:frontend && yarn lint:test",
"fix:admin": "yarn cache clean && cd core/admin && rm -rf node_modules tmp dist && yarn && cd ../../",
"fix:server": "yarn cache clean && rm -rf node_modules && yarn",
"fix": "yarn fix:admin && yarn fix:server"
"fix": "yarn fix:admin && yarn fix:server",
"prepack": "grunt release"
},
"engines": {
"node": "^14.17.0 || ^16.13.0",
@ -204,7 +205,6 @@
"grunt": "1.5.3",
"grunt-bg-shell": "2.3.3",
"grunt-contrib-clean": "2.0.1",
"grunt-contrib-compress": "2.0.0",
"grunt-contrib-copy": "1.0.0",
"grunt-contrib-symlink": "1.0.0",
"grunt-contrib-watch": "1.1.0",

View File

@ -2548,11 +2548,6 @@ acorn@^8.5.0, acorn@^8.7.1:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.1.tgz#0197122c843d1bf6d0a5e83220a788f278f63c30"
integrity sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==
adm-zip@^0.5.1:
version "0.5.9"
resolved "https://registry.yarnpkg.com/adm-zip/-/adm-zip-0.5.9.tgz#b33691028333821c0cf95c31374c5462f2905a83"
integrity sha512-s+3fXLkeeLjZ2kLjCBwQufpI5fuN+kIGBxu6530nVQZGVol0d7Y/M88/xw9HGGUcJjKf8LutN3VPRUBq6N7Ajg==
agent-base@4, agent-base@^4.2.0, agent-base@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee"
@ -2737,7 +2732,7 @@ archiver-utils@^2.1.0:
normalize-path "^3.0.0"
readable-stream "^2.0.0"
archiver@^5.0.0, archiver@^5.1.0:
archiver@^5.0.0:
version "5.3.1"
resolved "https://registry.yarnpkg.com/archiver/-/archiver-5.3.1.tgz#21e92811d6f09ecfce649fbefefe8c79e57cbbb6"
integrity sha512-8KyabkmbYrH+9ibcTScQ1xCJC/CGcugdVIwB+53f5sZziXgwUh3iXlAlANMxcZyDEfTHMe6+Z5FofV8nopXP7w==
@ -6099,18 +6094,6 @@ grunt-contrib-clean@2.0.1:
async "^3.2.3"
rimraf "^2.6.2"
grunt-contrib-compress@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/grunt-contrib-compress/-/grunt-contrib-compress-2.0.0.tgz#c003a1dc5e01c42a244ddb189c01a4396208a335"
integrity sha512-r/dAGx4qG+rmBFF4lb/hTktW2huGMGxkSLf9msh3PPtq0+cdQRQerZJ30UKevX3BLQsohwLzO0p1z/LrH6aKXQ==
dependencies:
adm-zip "^0.5.1"
archiver "^5.1.0"
chalk "^4.1.0"
lodash "^4.17.20"
pretty-bytes "^5.4.1"
stream-buffers "^3.0.2"
grunt-contrib-copy@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/grunt-contrib-copy/-/grunt-contrib-copy-1.0.0.tgz#7060c6581e904b8ab0d00f076e0a8f6e3e7c3573"
@ -10011,7 +9994,7 @@ prepend-http@^2.0.0:
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
pretty-bytes@^5.3.0, pretty-bytes@^5.4.1:
pretty-bytes@^5.3.0:
version "5.6.0"
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz#356256f643804773c82f64723fe78c92c62beaeb"
integrity sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg==
@ -11303,11 +11286,6 @@ stoppable@1.1.0:
resolved "https://registry.yarnpkg.com/stoppable/-/stoppable-1.1.0.tgz#32da568e83ea488b08e4d7ea2c3bcc9d75015d5b"
integrity sha512-KXDYZ9dszj6bzvnEMRYvxgeTHU74QBFL54XKtP3nyMuJ81CFYtABZ3bAzL2EdFUaEwJOBOgENyFj3R7oTzDyyw==
stream-buffers@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-3.0.2.tgz#5249005a8d5c2d00b3a32e6e0a6ea209dc4f3521"
integrity sha512-DQi1h8VEBA/lURbSwFtEHnSTb9s2/pwLEaFuNhXwy1Dx3Sa0lOuYT2yNUr4/j2fs8oCAMANtrZ5OrPZtyVs3MQ==
stream-parser@~0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/stream-parser/-/stream-parser-0.3.1.tgz#1618548694420021a1182ff0af1911c129761773"