@gravityforms/gulp-tasks
Version:
Configurable Gulp tasks for use in Gravity Forms projects.
65 lines (54 loc) • 2.13 kB
JavaScript
import { createRequire } from 'node:module';
import getConfig from '../../config.js';
import getPluginVersion from '../utils/get-plugin-version.js';
import sendSlackMessage from '../utils/send-slack-message.js';
import withRetry from '../utils/with-retry.js';
const cjsRequire = createRequire( import.meta.url );
const simpleGit = cjsRequire( 'simple-git' );
const { config } = getConfig();
const rootPath = config?.paths?.root || '';
const fileName = config?.settings?.rootPluginFile || '';
const tagVersion = async () => {
if ( process.env.GULP_PRODUCTION_MODE !== 'true' ) {
console.log( 'Skipping tagging version because GULP_PRODUCTION_MODE is not set to true.' );
return;
}
if ( ! rootPath || ! fileName ) {
console.error( 'Root path or file name not found, cannot tag release.' );
return;
}
const buildEnvironment = process.env.BUILD_ENVIRONMENT;
if ( ! buildEnvironment || buildEnvironment !== 'prod' ) {
console.log( 'Skipping tagging version because BUILD_ENVIRONMENT is not set or dev.' );
return;
}
const git = simpleGit( rootPath );
const version = process.env.GRAVITY_PLUGIN_VERSION || getPluginVersion( rootPath, fileName );
const tagName = `v${ version }`;
try {
const remoteTags = await withRetry(
() => git.listRemote( [ '--tags' ] ),
{ label: `list remote tags for ${ tagName }` },
);
if ( remoteTags.includes( tagName ) ) {
console.log( `Tag ${ tagName } already exists on the remote. Skipping creation.` );
return;
}
await withRetry(
() => git.tag( [ tagName ] ),
{ label: `create local tag ${ tagName }` },
);
await withRetry(
() => git.pushTags( 'origin' ),
{ label: `push tag ${ tagName } to origin` },
);
console.log( `Tag ${ tagName } created and pushed successfully.` );
} catch ( error ) {
const retryInfo = error.attempts ? ` after ${ error.attempts } attempts` : '';
console.error( `Failed to create or push tag${ retryInfo }:`, error );
await sendSlackMessage( `Git tag push failed${ retryInfo } for ${ tagName } during build: ${ error.message }`, 'error' );
process.exit( 1 );
}
};
tagVersion();