Skip to content

Commit

Permalink
improve(build): improve/cleanup the build process
Browse files Browse the repository at this point in the history
chore: updated all dev dependencies
fix: fixed an issue with releases not being created properly on GitHub
  • Loading branch information
aaronware committed Feb 10, 2022
1 parent e7c549f commit 1307e09
Show file tree
Hide file tree
Showing 11 changed files with 613 additions and 1,270 deletions.
26 changes: 26 additions & 0 deletions .deployment/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -eo

TMP_DIR="$GITHUB_WORKSPACE/courier-notices"
mkdir "$TMP_DIR"

# If there's no .gitattributes file, write a default one into place
if [ ! -e "$GITHUB_WORKSPACE/.distignore" ]; then
echo "ℹ︎ Creating .distignore file"

cat > ".distignore" <<-EOL
/.gitattributes
/.gitignore
/.github
/README.md
/.editorconfig
/composer.json
/index.php
EOL
fi;

echo "➤ Copying files to $TMP_DIR"

# This will exclude everything in the .gitattributes file with the export-ignore flag
rsync -rc --exclude-from="$GITHUB_WORKSPACE/.distignore" "$GITHUB_WORKSPACE/" "$TMP_DIR/" --delete
22 changes: 22 additions & 0 deletions .github/workflows/master.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ jobs:
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}

- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: Get Changelog Entry
id: changelog_reader
uses: mindsers/changelog-reader-action@v2
Expand All @@ -31,6 +37,22 @@ jobs:
dev: no
php_version: "7.4"

- name: Install Yarn Dependencies
run: |
yarn install
yarn build
rm -rf node_modules
- name: Clean Build Files/Folders
run : |
chmod +x ./.deployment/cleanup.sh
sh ./.deployment/cleanup.sh;
- name: Create Sync Zip
run: |
zip -r ${{ github.event.repository.name }}.zip ./${{ github.event.repository.name }}
zip -r ${{ github.event.repository.name }}-${{ steps.get_version.outputs.VERSION }}.zip ./${{ github.event.repository.name }}
- name: Create Release
id: create_release
uses: actions/create-release@latest
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.4.4] - 2022-02-10

### Updated
- improve the build process
- updated all dev dependencies

### Fixes
- fixed an issue with releases not being created properly on GitHub

## [1.4.3] - 2022-02-10
- Updated - Removed an extra trigger click on courier-close that could fire a redirect if multiple were used

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "linchpin/courier",
"description": "Courier Notices, a highly extendable advanced front end notification plugin for WordPress",
"homepage": "https://github.com/linchpin/courier-notices",
"version": "1.4.3",
"version": "1.4.4",
"authors": [
{
"name": "Linchpin",
Expand Down
5 changes: 5 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ COMPATIBILITY:

# Gulp will reference these paths when it copies files
PATHS:
readme: "readme.txt"
sass: "assets/scss/*.scss"
js: "assets/js/**/*.js"
package: "package.json"
composer: "composer.json"
# Path to dist folder
dist: ""
# Paths to static assets that aren't images, CSS, or JavaScript
Expand Down
4 changes: 2 additions & 2 deletions courier-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Courier Notices
* Plugin URI: https://wordpress.org/plugins/courier-notices
* Description: A way to display, manage, and control front end notifications for your WordPress install.
* Version: 1.4.3
* Version: 1.4.4
* Author: Linchpin
* Author URI: https://linchpin.com
* Text Domain: courier-notices
Expand All @@ -22,7 +22,7 @@
*/

if ( ! defined( 'COURIER_NOTICES_VERSION' ) ) {
define( 'COURIER_NOTICES_VERSION', '1.4.3' );
define( 'COURIER_NOTICES_VERSION', '1.4.4' );
}

if ( ! defined( 'COURIER_NOTICES_RELEASE_DATE' ) ) {
Expand Down
140 changes: 72 additions & 68 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ const $ = plugins();
let PRODUCTION = !!(yargs.argv.production); // Check for --production flag
let VERSION_BUMP = yargs.argv.release; // Check for --release (x.x.x semver version number)

/**
* Load in additional config files
*/
const loadConfig = () => {
let ymlFile = fs.readFileSync('config.yml', 'utf8');
return yaml.load(ymlFile);

}

// Load settings from settings.yml
const {COMPATIBILITY, PORT, UNCSS_OPTIONS, PATHS, LOCAL_PATH} = loadConfig();

Expand Down Expand Up @@ -52,86 +61,42 @@ let webpackConfig = {
}
};

/**
* Load in additional config files
*/
function loadConfig() {
let ymlFile = fs.readFileSync('config.yml', 'utf8');
return yaml.load(ymlFile);
}

/**
* Set production mode during the build process
*
* @param done
*/
function setProductionMode(done) {
const setProductionMode = ( done ) => {
PRODUCTION = false;
webpackConfig.mode = 'production';
webpackConfig.devtool = false;
sassConfig.production = true;
done();
}

// Build the "dist" folder by running all of the below tasks
// Sass must be run later so UnCSS can search for used classes in the others assets.
gulp.task(
'build:release',
gulp.series(
setProductionMode,
clean,
javascript,
buildSass,
bumpPluginFile,
bumpPackageJson,
bumpReadmeStableTag,
bumpComposerJson,
readme,
copy
)
);

// Generate the changelog.md from the readme.txt
gulp.task(
'readme',
gulp.series(
readme,
copy
)
);

// Build the site, run the server, and watch for file changes
gulp.task(
'default',
gulp.series(
clean,
javascript,
buildSass,
copy,
gulp.parallel(watch)
)
);
}

/**
* This happens every time a build starts
* @since 1.0
*
* @param done
*/
function clean(done) {
const clean = ( done ) => {
rimraf('css', done);
rimraf('js', done);

done();
}


/**
* Create a README.MD file for github from the WordPress.org readme
*
* @since 1.0
*/
function readme(done) {
return gulp.src(['readme.txt'])
const readme = ( done ) => {
return gulp.src([PATHS.readme])
.pipe($.readmeToMarkdown({
details: false,
screenshot_ext: ['jpg', 'jpg', 'png'],
Expand All @@ -155,7 +120,7 @@ function readme(done) {
*
* @return {*}
*/
function bumpPluginFile(done) {
const bumpPluginFile = ( done ) => {

let constant = 'COURIER_NOTICES_VERSION';
let define_bump_obj = {
Expand All @@ -167,7 +132,7 @@ function bumpPluginFile(done) {
key: 'Version',
};

if (VERSION_BUMP) {
if ( VERSION_BUMP ) {
bump_obj.version = VERSION_BUMP;
define_bump_obj.version = VERSION_BUMP;
}
Expand All @@ -194,7 +159,7 @@ function bumpPluginFile(done) {
*
* @return {*}
*/
function getReleaseDate() {
const getReleaseDate = () => {
let today = new Date();
let dd = String(today.getDate()).padStart(2, '0');
let mm = String(today.getMonth() + 1).padStart(2, '0');
Expand All @@ -210,7 +175,7 @@ function getReleaseDate() {
*
* @return {*}
*/
function bumpComposerJson() {
const bumpComposerJson = () => {

let bump_obj = {
key: 'version'
Expand All @@ -220,7 +185,7 @@ function bumpComposerJson() {
bump_obj.version = VERSION_BUMP;
}

return gulp.src('./composer.json')
return gulp.src('./' + PATHS.composer)
.pipe($.bump(bump_obj))
.pipe(through2.obj(function (file, enc, cb) {
let date = new Date();
Expand All @@ -238,15 +203,15 @@ function bumpComposerJson() {
*
* @return {*}
*/
function bumpReadmeStableTag() {
const bumpReadmeStableTag = () => {

let bump_obj = {key: "Stable tag"};

if (VERSION_BUMP) {
bump_obj.version = VERSION_BUMP;
}

return gulp.src('./readme.txt')
return gulp.src('./' + PATHS.readme )
.pipe($.bump(bump_obj))
.pipe(through2.obj(function (file, enc, cb) {
let date = new Date();
Expand All @@ -264,7 +229,7 @@ function bumpReadmeStableTag() {
*
* @return {*}
*/
function bumpPackageJson() {
const bumpPackageJson = () => {

let bump_obj = {
key: 'version'
Expand All @@ -274,7 +239,7 @@ function bumpPackageJson() {
bump_obj.version = VERSION_BUMP;
}

return gulp.src('./package.json')
return gulp.src( './' + PATHS.package)
.pipe($.bump(bump_obj))
.pipe(through2.obj(function (file, enc, cb) {
let date = new Date();
Expand All @@ -293,7 +258,7 @@ function bumpPackageJson() {
*
* @return {*}
*/
function copy() {
const copy = () => {
return gulp.src(PATHS.assets)
.pipe(gulp.dest('css/fonts'));
}
Expand All @@ -305,8 +270,8 @@ function copy() {
*
* @return {*}
*/
function buildSass() {
return gulp.src('assets/scss/*.scss')
const buildSass = () => {
return gulp.src(PATHS.sass)
.pipe($.sourcemaps.init())
.pipe(sass({
includePaths: PATHS.sass
Expand All @@ -321,7 +286,7 @@ function buildSass() {
*
* @return {*}
*/
function javascript() {
const javascript = () => {
return gulp.src(PATHS.entries)
.pipe(named())
.pipe($.sourcemaps.init())
Expand All @@ -343,9 +308,48 @@ function javascript() {
*
* @since 1.1
*/
function watch() {
gulp.watch('readme.txt', readme);
gulp.watch('assets/scss/**/*.scss').on('all', buildSass);
gulp.watch('assets/js/**/*.js').on('all', gulp.series(javascript));
gulp.watch(PATHS.assets, copy);
const watch = () => {
gulp.watch( PATHS.readme , readme );
gulp.watch( PATHS.sass ).on('all', buildSass );
gulp.watch( PATHS.js ).on('all', gulp.series( javascript ) );
gulp.watch( PATHS.assets, copy );
}

// Generate the changelog.md from the readme.txt
gulp.task(
'readme',
gulp.series(
readme,
copy
)
);

// Build the site, run the server, and watch for file changes
gulp.task(
'default',
gulp.series(
clean,
javascript,
buildSass,
copy,
gulp.parallel(watch)
)
);

// Build the "dist" folder by running all of the below tasks
// Sass must be run later so UnCSS can search for used classes in the others assets.
gulp.task(
'build:release',
gulp.series(
setProductionMode,
clean,
javascript,
buildSass,
bumpPluginFile,
bumpPackageJson,
bumpReadmeStableTag,
bumpComposerJson,
readme,
copy
)
);
2 changes: 1 addition & 1 deletion js/courier-notices-admin.js

Large diffs are not rendered by default.

Loading

0 comments on commit 1307e09

Please # to comment.