UNPKG

@gravityforms/gulp-tasks

Version:
53 lines (44 loc) 1.89 kB
#!/usr/bin/env node const simpleGit = require('simple-git'); const getPluginVersion = require('../utils/get-plugin-version'); const sendSlackMessage = require('../utils/send-slack-message'); const getConfig = require('../../config'); const { config } = getConfig(); const rootPath = config?.paths?.root || ''; const fileName = config?.settings?.rootPluginFile || ''; const tagVersion = async () => { // Check if not in production mode and exit early 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 { // Checking if the tag already exists on the remote const remoteTags = await git.listRemote( [ '--tags' ] ); if ( remoteTags.includes( tagName ) ) { console.log( `Tag ${ tagName } already exists on the remote. Skipping creation.` ); return; // Skip the creation and pushing of the tag since it exists on the remote } // Creating and pushing the tag if it doesn't exist on the remote await git.tag( [ tagName ] ); await git.pushTags( 'origin' ); console.log( `Tag ${ tagName } created and pushed successfully.` ); } catch ( error ) { console.error( 'Failed to create or push tag:', error ); await sendSlackMessage( `Failed to tag git version during build: ${ error.message }`, 'error' ); process.exit( 1 ); } }; tagVersion();